NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
JSONHierarchyFeedbackControl.h
Go to the documentation of this file.
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_HIERARCHY_FEEDBACK_CONTROL_H
20 #define JSON_HIERARCHY_FEEDBACK_CONTROL_H
21 
31 #include "dev/dhustigschultz/BP_SC_NoLegs_Stats/JSONQuadCPGControl.h"
32 
33 #include <json/value.h>
34 
35 // Forward Declarations
36 class neuralNetwork;
38 
39 
49 {
50 public:
51 
53  {
54  public:
58  Config( int ss,
59  int tm,
60  int om,
61  int param,
62  int segnum = 6,
63  double ct = 0.1,
64  double la = 0,
65  double ha = 30,
66  double lp = -1 * M_PI,
67  double hp = M_PI,
68  double kt = 0.0,
69  double kp = 1000.0,
70  double kv = 100.0,
71  bool def = true,
72  double cl = 10.0,
73  double lf = 0.0,
74  double hf = 30.0,
75  double ffMin = 0.0,
76  double ffMax = 0.0,
77  double afMin = 0.0,
78  double afMax = 0.0,
79  double pfMin = 0.0,
80  double pfMax = 0.0,
81  double maxH = 60.0, //May need to tune this value more
82  double minH = 1.0, //Perhaps same
83  int ohm = 10,
84  int thm = 10,
85  int olm = 10,
86  int tlm = 10,
87  int ohighm = 5,
88  int thighm = 5,
89  double hf2 = 20.0,
90  double ffMax2 = 0.0
91  );
92 
93  const double freqFeedbackMin;
94  const double freqFeedbackMax;
95  const double ampFeedbackMin;
96  const double ampFeedbackMax;
97  const double phaseFeedbackMin;
98  const double phaseFeedbackMax;
99 
100  //So that these limits don't have to be hardcoded:
101  const double maxHeight;
102  const double minHeight;
103 
104  // Values to be filled in by JSON file during onSetup
105  int numStates;
106  int numActions;
107 
108  // New values of numMuscles, for non-spine segments:
109  int ourHipMuscles;
110  int theirHipMuscles;
111  int ourLegMuscles;
112  int theirLegMuscles;
113  int ourHighMuscles;
114  int theirHighMuscles;
115 
116  // These are for the higher level CPGs
117  const double highFreq2;
118  const double freqFeedbackMax2;
119  };
120 
122  std::string args,
123  std::string resourcePath = "");
124 
125  virtual ~JSONHierarchyFeedbackControl();
126 
127  virtual void onSetup(BaseQuadModelLearning& subject);
128 
129  virtual void onStep(BaseQuadModelLearning& subject, double dt);
130 
131  virtual void onTeardown(BaseQuadModelLearning& subject);
132 
133 protected:
134 
135  virtual void setupCPGs(BaseQuadModelLearning& subject, array_2D spineNodeActions, array_2D legNodeActions, array_4D spineEdgeActions, array_4D hipEdgeActions, array_4D legEdgeActions);
136 
137  virtual void setupHighCPGs(BaseQuadModelLearning& subject, array_2D highNodeActions, array_4D highEdgeActions);
138 
139  //If need to couple the other way, then may need to pass more arrays as parameters
140  virtual void setupHighLowCouplings(BaseQuadModelLearning& subject, Json::Value highLowEdgeActions);
141 
142  virtual array_2D scaleNodeActions (Json::Value actions, double highFreq, double freqFeedbackMax);
143 
144  virtual array_4D scaleEdgeActions (Json::Value actions, int segmentSpan, int theirMuscles, int ourMuscles);
145 
146  std::vector<double> getFeedback(BaseQuadModelLearning& subject);
147 
148  std::vector<double> getCableState(const tgSpringCableActuator& cable);
149 
150  std::vector<double> transformFeedbackActions(std::vector< std::vector<double> >& actions);
151 
153 
154  // @todo: doing separate vectors of controllers, until I can find a way to make them into a vector of vectors, without segfaulting.
155  std::vector<tgCPGActuatorControl*> m_spineControllers;
156 
157  std::vector<tgCPGActuatorControl*> m_leftShoulderControllers;
158  std::vector<tgCPGActuatorControl*> m_rightShoulderControllers;
159 
160  std::vector<tgCPGActuatorControl*> m_leftHipControllers;
161  std::vector<tgCPGActuatorControl*> m_rightHipControllers;
162 
163  std::vector<tgCPGActuatorControl*> m_leftForelegControllers;
164  std::vector<tgCPGActuatorControl*> m_rightForelegControllers;
165 
166  std::vector<tgCPGActuatorControl*> m_leftHindlegControllers;
167  std::vector<tgCPGActuatorControl*> m_rightHindlegControllers;
168 
169  //std::vector<tgCPGActuatorControl*> m_hipControllers;
170  //std::vector<tgCPGActuatorControl*> m_legControllers;
171 
172  std::vector<tgCPGActuatorControl*> m_highControllers;
173 
174  // @todo generalize this if we need more than one
175  neuralNetwork* nn;
176 
177  std::vector< std::vector<double> > m_quadCOM;
178 
179 };
180 
181 #endif // JSON_HIERARCHY_FEEDBACK_CONTROL_H
JSONHierarchyFeedbackControl(JSONHierarchyFeedbackControl::Config config, std::string args, std::string resourcePath="")
virtual void onTeardown(BaseQuadModelLearning &subject)
virtual void onStep(BaseQuadModelLearning &subject, double dt)
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, int ohm=10, int thm=10, int olm=10, int tlm=10, int ohighm=5, int thighm=5, double hf2=20.0, double ffMax2=0.0)
virtual void onSetup(BaseQuadModelLearning &subject)
virtual array_4D scaleEdgeActions(Json::Value actions, int segmentSpan, int theirMuscles, int ourMuscles)