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