NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
EscapeController.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 ESCAPECONTROLLER
20 #define ESCAPECONTROLLER
21 
30 #include <vector>
31 
32 #include "core/tgObserver.h"
36 
37 // Forward declarations
38 class EscapeModel;
39 class tgBasicActuator;
40 
41 //namespace std for vectors
42 using namespace std;
43 
45 class EscapeController : public tgObserver<EscapeModel>
46 {
47  public:
48  // Note that currently this is calibrated for decimeters.
49  EscapeController(const double prefLength=5.0,
50  std::string args = "_Escape",
51  std::string resourcePath = "",
52  std::string config = "Config.ini");
53 
55  virtual ~EscapeController() { }
56 
57  virtual void onSetup(EscapeModel& subject);
58 
59  virtual void onStep(EscapeModel& subject, double dt);
60 
61  virtual void onTeardown(EscapeModel& subject);
62 
63  protected:
64  virtual vector< vector <double> > transformActions(vector< vector <double> > act);
65 
66  virtual void applyActions(EscapeModel& subject, vector< vector <double> > act);
67 
68  private:
69  vector<double> initPosition; // Initial position of model
70  const double m_initialLengths;
71  double m_totalTime;
72  double const maxStringLengthFactor; // Proportion of string's initial length by which a given actuator can increase/decrease
73 
74  // Evolution and Adapter
75  AnnealAdapter evolutionAdapter;
76  vector< vector<double> > actions; // For modifications between episodes
77 
78  // Muscle Clusters
79  int nClusters;
80  int musclesPerCluster;
82  vector<vector<tgBasicActuator*> > clusters;
83 
84  // Sine Wave Data
85  double* amplitude;
86  double* angularFrequency;
87  double* phaseChange;
88  double* dcOffset;
89 
90  // Configuration strings
91  std::string suffix;
92  std::string configPath;
93  std::string configName;
94 
96  void setupAdapter();
97 
99  double totalEnergySpent(EscapeModel& subject);
100 
102  void setPreferredMuscleLengths(EscapeModel& subject, double dt);
103 
106  void populateClusters(EscapeModel& subject);
107 
110  void initializeSineWaves();
111 
114  double displacement(EscapeModel& subject);
115 
117  std::vector<double> readManualParams(int lineNumber, string filename);
118 
119  void printSineParams();
120 };
121 
122 #endif // ESCAPECONTROLLER
Definition of tgObserver class.
A class to read a learning configuration from a .ini file.
Contains the definition of class AnnealEvolution. Adapting NeuroEvolution to do Simulated Annealing...
virtual ~EscapeController()
Defines a class AnnealAdapter to pass parameters from AnnealEvolution to a controller. Adapting NeuroEvolution to do Simulated Annealing.