NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
SuperBallLearningController.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 SUPERBALL_LEARNINGCONTROLLER_H
20 #define SUPERBALL_LEARNINGCONTROLLER_H
21 
30 // This library
31 #include "core/tgObserver.h"
33 #include <vector>
34 #include "BulletDynamics/Dynamics/btRigidBody.h"
35 
36 // Forward declarations
37 class SuperBallModel;
38 
39 //namespace std for vectors
40 using namespace std;
41 
48 class SuperBallPrefLengthController : public tgObserver<SuperBallModel>
49 {
50 public:
51 
57  // Note that currently this is calibrated for decimeters.
58  SuperBallPrefLengthController(const double prefLength=5);
59 
64 
65  virtual void onSetup(SuperBallModel& subject);
66 
67  virtual void onStep(SuperBallModel& subject, double dt);
68 
69  virtual void onTeardown(SuperBallModel& subject);
70 
71 protected:
72 
73  vector< vector <double> > receiveActionsFromEvolution();
74 
75  virtual vector< vector <double> > transformActions(vector< vector <double> > act);
76 
77  virtual void applyActions (SuperBallModel& subject, vector< vector <double> > act, vector<double> state);
78 
79  double calculateDistanceMoved();
80 
81 private:
82  double m_initialLengths;
83  double m_totalTime;
84  btRigidBody *goalPoint;
85 
86  AnnealEvolution *evolution;
87 
88  vector<double> initialPosition;
89  SuperBallModel *m_subject;
90 };
91 
92 #endif // SUPERBALL_LEARNINGCONTROLLER_H
Definition of tgObserver class.
Defines a class AnnealAdapter to pass parameters from AnnealEvolution to a controller. Adapting NeuroEvolution to do Simulated Annealing.