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