NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
JSONSegmentsFeedbackControl.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_SEGMENTS_FEEDBACK_CONTROL_H
20 #define JSON_SEGMENTS_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 
48 {
49 public:
50 
52  {
53  public:
57  Config( int ss,
58  int tm, //These now apply to spine segments only.
59  int om, //Same.
60  int param,
61  int segnum = 6,
62  double ct = 0.1,
63  double la = 0,
64  double ha = 30,
65  double lp = -1 * M_PI,
66  double hp = M_PI,
67  double kt = 0.0,
68  double kp = 1000.0,
69  double kv = 100.0,
70  bool def = true,
71  double cl = 10.0,
72  double lf = 0.0,
73  double hf = 30.0,
74  double ffMin = 0.0,
75  double ffMax = 0.0,
76  double afMin = 0.0,
77  double afMax = 0.0,
78  double pfMin = 0.0,
79  double pfMax = 0.0,
80  double maxH = 60.0, //May need to tune this value more
81  double minH = 1.0, //Perhaps same
82  int ohm = 10,
83  int thm = 10,
84  int olm = 10,
85  int tlm = 10
86  );
87 
88  const double freqFeedbackMin;
89  const double freqFeedbackMax;
90  const double ampFeedbackMin;
91  const double ampFeedbackMax;
92  const double phaseFeedbackMin;
93  const double phaseFeedbackMax;
94 
95  const double maxHeight;
96  const double minHeight;
97 
98  // Values to be filled in by JSON file during onSetup:
99  int numStates;
100  int numActions;
101 
102  // New values of numMuscles, for non-spine segments:
103  int ourHipMuscles;
104  int theirHipMuscles;
105  int ourLegMuscles;
106  int theirLegMuscles;
107 
108  };
109 
111  std::string args,
112  std::string resourcePath = "");
113 
114  virtual ~JSONSegmentsFeedbackControl();
115 
116  virtual void onSetup(BaseQuadModelLearning& subject);
117 
118  virtual void onStep(BaseQuadModelLearning& subject, double dt);
119 
120  virtual void onTeardown(BaseQuadModelLearning& subject);
121 
122 protected:
123 
124  virtual void setupCPGs(BaseQuadModelLearning& subject, array_2D nodeActions, array_4D edgeActions, array_4D hipEdgeActions, array_4D legEdgeActions);
125 
126 
127  virtual array_4D scaleEdgeActions (Json::Value actions, int theirMuscles, int ourMuscles);
128  virtual array_2D scaleNodeActions (Json::Value actions);
129 
130  std::vector<double> getFeedback(BaseQuadModelLearning& subject);
131 
132  std::vector<double> getCableState(const tgSpringCableActuator& cable);
133 
134  std::vector<double> transformFeedbackActions(std::vector< std::vector<double> >& actions);
135 
137 
138  std::vector<tgCPGActuatorControl*> m_spineControllers;
139  std::vector<tgCPGActuatorControl*> m_hipControllers;
140  std::vector<tgCPGActuatorControl*> m_legControllers;
141 
143  neuralNetwork* nn;
144 
145 };
146 
147 #endif // JSON_SEGMENTS_FEEDBACK_CONTROL_H
virtual void onSetup(BaseQuadModelLearning &subject)
JSONSegmentsFeedbackControl(JSONSegmentsFeedbackControl::Config config, std::string args, std::string resourcePath="")
virtual array_4D scaleEdgeActions(Json::Value actions, int theirMuscles, int ourMuscles)
virtual void onStep(BaseQuadModelLearning &subject, double dt)
virtual void onTeardown(BaseQuadModelLearning &subject)
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)