NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
JSONMGFeedbackControl.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_MG_FEEDBACK_CONTROL_H
20 #define JSON_MG_FEEDBACK_CONTROL_H
21 
32 
33 #include <json/value.h>
34 
35 // Forward Declarations
36 class neuralNetwork;
38 
39 typedef boost::multi_array<double, 3> array_3D; //Will treat entire spine (and eventually body) as one big segment, so reducing the multi_array by one dimension.
40 
50 {
51 public:
52 
54  {
55  public:
59  Config( int ss,
60  int tm,
61  int om,
62  int param,
63  int segnum = 6,
64  double ct = 0.1,
65  double la = 0,
66  double ha = 30,
67  double lp = -1 * M_PI,
68  double hp = M_PI,
69  double kt = 0.0,
70  double kp = 1000.0,
71  double kv = 100.0,
72  bool def = true,
73  double cl = 10.0,
74  double lf = 0.0,
75  double hf = 30.0,
76  double ffMin = 0.0,
77  double ffMax = 0.0,
78  double afMin = 0.0,
79  double afMax = 0.0,
80  double pfMin = 0.0,
81  double pfMax = 0.0,
82  double maxH = 60.0, //May need to tune this value more
83  double minH = 1.0 //Perhaps same
84  );
85 
86  const double freqFeedbackMin;
87  const double freqFeedbackMax;
88  const double ampFeedbackMin;
89  const double ampFeedbackMax;
90  const double phaseFeedbackMin;
91  const double phaseFeedbackMax;
92 
93  const double maxHeight;
94  const double minHeight;
95 
96  // Values to be filled in by JSON file during onSetup
97  int numStates;
98  int numActions;
99 
100  };
101 
103  std::string args,
104  std::string resourcePath = "");
105 
106  virtual ~JSONMGFeedbackControl();
107 
108  virtual void onSetup(BaseQuadModelLearning& subject);
109 
110  virtual void onStep(BaseQuadModelLearning& subject, double dt);
111 
112  virtual void onTeardown(BaseQuadModelLearning& subject);
113 
114 protected:
115 //ToDo: Need to restructure the for loops in here, so that have separate cases for the first and last segments (long muscles)....
116  virtual void setupCPGs(BaseQuadModelLearning& subject, array_2D nodeActions, array_3D edgeActions);
117 
118  virtual array_3D scaleEdgeActions (Json::Value edgeParam);
119  virtual array_2D scaleNodeActions (Json::Value actions);
120 
121 //ToDo: May have to write a new function in this subclass, to handle the fact that we'll be skipping segments now. Not sure if scale edge actions will work in all cases.... and maybe there's something better?
122 
123  std::vector<double> getFeedback(BaseQuadModelLearning& subject);
124 
125  std::vector<double> getCableState(const tgSpringCableActuator& cable);
126 
127  std::vector<double> transformFeedbackActions(std::vector< std::vector<double> >& actions);
128 
130 
131  std::vector<tgCPGMGActuatorControl*> m_spineControllers;
132 
134  neuralNetwork* nn;
135 
136 };
137 
138 #endif // JSON_MG_FEEDBACK_CONTROL_H
virtual void onSetup(BaseQuadModelLearning &subject)
virtual void onStep(BaseQuadModelLearning &subject, double dt)
An adaptation of JSONCPGControl that utilizes JSON for parameters.
virtual array_3D scaleEdgeActions(Json::Value edgeParam)
virtual void onTeardown(BaseQuadModelLearning &subject)
JSONMGFeedbackControl(JSONMGFeedbackControl::Config config, std::string args, std::string resourcePath="")
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)