NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
JSONQuadFeedbackControl.h
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
19 #ifndef JSON_QUAD_FEEDBACK_CONTROL_H
20 #define JSON_QUAD_FEEDBACK_CONTROL_H
21 
31 
32 #include <json/value.h>
33 
34 // Forward Declarations
35 class neuralNetwork;
37 
47 {
48 public:
49 
51  {
52  public:
56  Config( int ss,
57  int tm,
58  int om,
59  int param,
60  int segnum = 6,
61  double ct = 0.1,
62  double la = 0,
63  double ha = 30,
64  double lp = -1 * M_PI,
65  double hp = M_PI,
66  double kt = 0.0,
67  double kp = 1000.0,
68  double kv = 100.0,
69  bool def = true,
70  double cl = 10.0,
71  double lf = 0.0,
72  double hf = 30.0,
73  double ffMin = 0.0,
74  double ffMax = 0.0,
75  double afMin = 0.0,
76  double afMax = 0.0,
77  double pfMin = 0.0,
78  double pfMax = 0.0,
79  double maxH = 60.0, //May need to tune this value more
80  double minH = 1.0, //Perhaps same
81  double hffMin = 0.0,
82  double hffMax = 0.0
83  );
84 
85  const double freqFeedbackMin;
86  const double freqFeedbackMax;
87  const double ampFeedbackMin;
88  const double ampFeedbackMax;
89  const double phaseFeedbackMin;
90  const double phaseFeedbackMax;
91 
92  const double maxHeight;
93  const double minHeight;
94 
95  const double highFreqFeedbackMin;
96  const double highFreqFeedbackMax;
97 
98  // Values to be filled in by JSON file during onSetup
99  int numStates;
100  int numActions;
101 
102  };
103 
105  std::string args,
106  std::string resourcePath = "");
107 
108  virtual ~JSONQuadFeedbackControl();
109 
110  virtual void onSetup(BaseSpineModelLearning& subject);
111 
112  virtual void onStep(BaseSpineModelLearning& subject, double dt);
113 
114  virtual void onTeardown(BaseSpineModelLearning& subject);
115 
116 protected:
117 
118  virtual void setupCPGs(BaseSpineModelLearning& subject, array_2D nodeActions, array_4D edgeActions);
119  virtual void setupHighCPGs(array_2D nodeActions, array_4D highEdgeActions, Json::Value highLowEdgeActions);
120  //virtual void setupHighCouplings(array_4D highEdgeActions);
121  // I'm cheating and just using the Json thing directly. ~B
122  //virtual void setupHighLowCouplings(Json::Value highLowEdgeActions);
123 
124  virtual array_4D scaleEdgeActions (Json::Value edgeParam);
125  virtual array_2D scaleNodeActions (Json::Value actions);
126  virtual array_4D scaleHighEdgeActions (Json::Value highEdgeParam);
127 
128  std::vector<double> getFeedback(BaseSpineModelLearning& subject);
129 
130  std::vector<double> getCableState(const tgSpringCableActuator& cable);
131 
132  std::vector<double> transformFeedbackActions(std::vector< std::vector<double> >& actions);
133 
135 
136  // Hacky and probably temporary. Or maybe not. ¯\_(ツ)_/¯
137  // Make array of 9 basic body parts. Each body part has vector of CPG controllers.
138  std::vector<tgCPGActuatorControl*> m_controllers[9];
139 
140  // Higher level CPGs
141  std::vector<tgCPGActuatorControl*> m_highControllers;
142 
144  neuralNetwork* nn;
145 
146  // How many different body parts we're using in the goat/puppy dealy thing
147  int n_bodyParts;
148  // Helps us keep track of the number of muscles in each body part
149  int n_muscSpine; // how many controllable muscles in the spine
150  int n_muscHip; // how many controllable muscles in each hip/shoulder
151  int n_muscLeg; // how many controllable muscles in each leg
152 
153 };
154 
155 #endif // JSON_QUAD_FEEDBACK_CONTROL_H
virtual array_4D scaleEdgeActions(Json::Value edgeParam)
virtual void onTeardown(BaseSpineModelLearning &subject)
An adaptation of JSONCPGControl that utilizes JSON for parameters.
virtual void onStep(BaseSpineModelLearning &subject, double dt)
JSONQuadFeedbackControl(JSONQuadFeedbackControl::Config config, std::string args, std::string resourcePath="")
virtual void onSetup(BaseSpineModelLearning &subject)
virtual array_4D scaleHighEdgeActions(Json::Value highEdgeParam)
Config(int ss, int tm, int om, int param, int segnum=6, double ct=0.1, double la=0, double ha=30, double lp=-1 *M_PI, double hp=M_PI, double kt=0.0, double kp=1000.0, double kv=100.0, bool def=true, double cl=10.0, double lf=0.0, double hf=30.0, double ffMin=0.0, double ffMax=0.0, double afMin=0.0, double afMax=0.0, double pfMin=0.0, double pfMax=0.0, double maxH=60.0, double minH=1.0, double hffMin=0.0, double hffMax=0.0)