NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
Escape_T6Controller.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 ESCAPE_T6CONTROLLER
20 #define ESCAPE_T6CONTROLLER
21 
30 #include <vector>
31 
32 #include "core/tgObserver.h"
34 
35 // Forward declarations
36 class Escape_T6Model;
37 class tgBasicActuator;
38 
39 //namespace std for vectors
40 using namespace std;
41 
43 class Escape_T6Controller : public tgObserver<Escape_T6Model>
44 {
45  public:
46  // Note that currently this is calibrated for decimeters.
47  Escape_T6Controller(const double prefLength=5.0);
48 
50  virtual ~Escape_T6Controller() { }
51 
52  virtual void onSetup(Escape_T6Model& subject);
53 
54  virtual void onStep(Escape_T6Model& subject, double dt);
55 
56  virtual void onTeardown(Escape_T6Model& subject);
57 
58  protected:
59  virtual vector< vector <double> > transformActions(vector< vector <double> > act);
60 
61  virtual void applyActions(Escape_T6Model& subject, vector< vector <double> > act);
62 
63  private:
64  vector<double> initPosition; // Initial position of model
65  const double m_initialLengths;
66  double m_totalTime;
67  double const maxStringLengthFactor; // Proportion of string's initial length by which a given actuator can increase/decrease
68 
69  // Evolution and Adapter
70  AnnealAdapter evolutionAdapter;
71  vector< vector<double> > actions; // For modifications between episodes
72 
73  // Muscle Clusters
74  int nClusters;
75  int musclesPerCluster;
77  vector<vector<tgBasicActuator*> > clusters;
78 
79  // Sine Wave Data
80  double* amplitude;
81  double* angularFrequency;
82  double* phaseChange;
83  double* dcOffset;
84 
86  void setupAdapter();
87 
89  double totalEnergySpent(Escape_T6Model& subject);
90 
92  void setPreferredMuscleLengths(Escape_T6Model& subject, double dt);
93 
96  void populateClusters(Escape_T6Model& subject);
97 
100  void initializeSineWaves();
101 
104  double displacement(Escape_T6Model& subject);
105 
107  std::vector<double> readManualParams(int lineNumber, string filename);
108 
109  void printSineParams();
110 };
111 
112 #endif // ESCAPE_T6CONTROLLER
Definition of tgObserver class.
Defines a class AnnealAdapter to pass parameters from AnnealEvolution to a controller. Adapting NeuroEvolution to do Simulated Annealing.