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