NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
JSONMGCPGGeneralControl.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_MG_CPG_GENERAL_CONTROL_H
20 #define JSON_MG_CPG_GENERAL_CONTROL_H
21 
34 
35 #include <vector>
36 #include "boost/multi_array.hpp"
37 
38 #include "core/tgSubject.h"
39 #include "core/tgObserver.h"
40 #include "sensors/tgDataObserver.h"
41 
42 #include <json/value.h>
43 
44 // Forward Declarations
47 class CPGEquations;
48 class tgCPGLogger;
51 
52 typedef boost::multi_array<double, 2> array_2D;
53 typedef boost::multi_array<double, 3> array_3D;
54 
63 class JSONMGCPGGeneralControl : public tgObserver<BaseQuadModelLearning>, public tgSubject <JSONMGCPGGeneralControl>
64 {
65 public:
66 
67 struct Config
68  {
69  public:
73  Config( int ss,
74  int tm,
75  int om,
76  int param,
77  int segnum = 6,
78  double ct = 0.1,
79  double la = 0,
80  double ha = 30,
81  double lp = -1 * M_PI,
82  double hp = M_PI,
83  double kt = 0.0,
84  double kp = 1000.0,
85  double kv = 100.0,
86  bool def = true,
87  double cl = 10.0,
88  double lf = 0.0,
89  double hf = 30.0);
90 
91  // Learning Parameters
92  const int segmentSpan; // 3 possible muscles touching two rigid bodies
93  const int theirMuscles; // 8 muscles in a segment
94  const int ourMuscles; // same as above
95  const int params; // Number of parameters per edge
96  const int segmentNumber;
97 
98  // CPG control frequency
99  const double controlTime;
100 
101  // Limit Params
102  const double lowAmp;
103  const double highAmp;
104  const double lowFreq;
105  const double highFreq;
106  const double lowPhase;
107  const double highPhase;
108 
109  // Parameters for Impedance Controllers
110  const double tension;
111  const double kPosition;
112  const double kVelocity;
113  const bool useDefault;
114  const double controlLength;
115  };
116 
118  std::string args,
119  std::string resourcePath = "");
120 
121  virtual ~JSONMGCPGGeneralControl();
122 
123  virtual void onStep(BaseQuadModelLearning& subject, double dt);
124 
125  virtual void onSetup(BaseQuadModelLearning& subject);
126 
127  virtual void onTeardown(BaseQuadModelLearning& subject);
128 
129  const double getCPGValue(std::size_t i) const;
130 
131  double getScore() const;
132 
133 protected:
139  virtual array_3D scaleEdgeActions (Json::Value edgeParam);
140  virtual array_2D scaleNodeActions (Json::Value actions);
141 
142  virtual void setupCPGs(BaseQuadModelLearning& subject, array_2D nodeActions, array_3D edgeActions);
143 
144  CPGEquations* m_pCPGSys;
145 
146  std::vector<tgCPGMGActuatorControl*> m_allControllers;
147 
149 
150  std::vector<double> initConditions;
151 
152  std::size_t segments;
153 
154  tgDataObserver m_dataObserver;
155 
156  double m_updateTime;
157  double m_totalTime;
158 
159  std::vector<double> scores;
160  std::vector<double> metrics;
161 
162  bool bogus;
163 
164  std::string controlFilename;
165  std::string controlFilePath;
166 };
167 
168 #endif // JSON_MG_CPG_GENERAL_CONTROL_H
Definition of tgObserver class.
Implementing the Flemons quadruped model (roughly), but as a subclass of Brian's BaseSpineModelLearni...
virtual void onTeardown(BaseQuadModelLearning &subject)
Definition of tgSubject class.
virtual array_3D scaleEdgeActions(Json::Value edgeParam)
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)
Definition of tgObserver class.
virtual void onSetup(BaseQuadModelLearning &subject)
JSONMGCPGGeneralControl(JSONMGCPGGeneralControl::Config config, std::string args, std::string resourcePath="")
virtual void setupCPGs(BaseQuadModelLearning &subject, array_2D nodeActions, array_3D edgeActions)
virtual void onStep(BaseQuadModelLearning &subject, double dt)