NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
BaseSpineCPGControl.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 BASE_SPINE_CPG_CONTROL_H
20 #define BASE_SPINE_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 
38 
39 //This should probably be a forward declaration
40 #include "BaseSpineModelLearning.h"
41 
42 // Forward Declarations
44 class AnnealEvolution;
45 class configuration;
47 class CPGEquations;
48 class tgCPGLogger;
49 
50 typedef boost::multi_array<double, 2> array_2D;
51 typedef boost::multi_array<double, 4> array_4D;
52 
61 class BaseSpineCPGControl : public tgObserver<BaseSpineModelLearning>, public tgSubject <BaseSpineCPGControl>
62 {
63 public:
64 
65 struct Config
66  {
67  public:
71  Config( int ss,
72  int tm,
73  int om,
74  int param,
75  int segnum = 6,
76  double ct = 0.1,
77  double la = 0,
78  double ha = 30,
79  double lp = -1 * M_PI,
80  double hp = M_PI,
81  double kt = 0.0,
82  double kp = 1000.0,
83  double kv = 100.0,
84  bool def = true,
85  double cl = 10.0,
86  double lf = 0.0,
87  double hf = 30.0);
88 
89  // Learning Parameters
90  const int segmentSpan; // 3 possible muscles touching two rigid bodies
91  const int theirMuscles; // 8 muscles in a segment
92  const int ourMuscles; // same as above
93  const int params; // Number of parameters per edge
94  const int segmentNumber;
95 
96  // CPG control frequency
97  const double controlTime;
98 
99  // Limit Params
100  const double lowAmp;
101  const double highAmp;
102  const double lowFreq;
103  const double highFreq;
104  const double lowPhase;
105  const double highPhase;
106 
107  // Parameters for Impedance Controllers
108  const double tension;
109  const double kPosition;
110  const double kVelocity;
111  const bool useDefault;
112  const double controlLength;
113  };
114 
116  std::string args,
117  std::string resourcePath = "",
118  std::string ec = "edgeConfig.ini",
119  std::string nc = "nodeConfig.ini");
120 
121  virtual ~BaseSpineCPGControl();
122 
123  virtual void onStep(BaseSpineModelLearning& subject, double dt);
124 
125  virtual void onSetup(BaseSpineModelLearning& subject);
126 
127  virtual void onTeardown(BaseSpineModelLearning& subject);
128 
129  const double getCPGValue(std::size_t i) const;
130 
131  double getScore() const;
132 
133 protected:
139  virtual array_4D scaleEdgeActions (std::vector< std::vector <double> > actions);
140  virtual array_2D scaleNodeActions (std::vector< std::vector <double> > actions);
141 
142  virtual void setupCPGs(BaseSpineModelLearning& subject, array_2D nodeActions, array_4D edgeActions);
143 
144  CPGEquations* m_pCPGSys;
145 
146  std::vector<tgCPGActuatorControl*> m_allControllers;
147 
149 
154  std::string edgeConfigFilename;
155  std::string nodeConfigFilename;
156 
162  configuration edgeConfigData;
163 
169  AnnealEvolution nodeEvolution;
170 
176  AnnealAdapter nodeAdapter;
177 
182  bool edgeLearning;
183 
184  std::vector<double> initConditions;
185 
186  std::size_t segments;
187 
188  tgDataObserver m_dataObserver;
189 
190  double m_updateTime;
191 
192  std::vector<double> scores;
193 
194  bool bogus;
195 };
196 
197 #endif // BASE_SPINE_CPG_CONTROL_H
virtual void onSetup(BaseSpineModelLearning &subject)
virtual void onStep(BaseSpineModelLearning &subject, double dt)
Definition of tgObserver class.
AnnealEvolution edgeEvolution
virtual void onTeardown(BaseSpineModelLearning &subject)
virtual void setupCPGs(BaseSpineModelLearning &subject, array_2D nodeActions, array_4D edgeActions)
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)
configuration nodeConfigData
BaseSpineCPGControl(BaseSpineCPGControl::Config config, std::string args, std::string resourcePath="", std::string ec="edgeConfig.ini", std::string nc="nodeConfig.ini")
A template base class for a tensegrity spine.
Definition of tgObserver class.
virtual array_4D scaleEdgeActions(std::vector< std::vector< double > > actions)
Defines a class AnnealAdapter to pass parameters from AnnealEvolution to a controller. Adapting NeuroEvolution to do Simulated Annealing.