NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
JSONGoalControl.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 JSON_GOAL_CONTROL_H
20 #define JSON_GOAL_CONTROL_H
21 
31 
32 #include <json/value.h>
33 
34 // Forward Declarations
35 class neuralNetwork;
37 class BaseSpineModelGoal;
38 class tgSCASineControl;
39 
49 {
50 public:
51 
53  {
54  public:
58  Config( int ss,
59  int tm,
60  int om,
61  int param,
62  int segnum = 6,
63  double ct = 0.1,
64  double la = 0,
65  double ha = 30,
66  double lp = -1 * M_PI,
67  double hp = M_PI,
68  double kt = 0.0,
69  double kp = 1000.0,
70  double kv = 100.0,
71  bool def = true,
72  double cl = 10.0,
73  double lf = 0.0,
74  double hf = 30.0,
75  double ffMin = 0.0,
76  double ffMax = 0.0,
77  double afMin = 0.0,
78  double afMax = 0.0,
79  double pfMin = 0.0,
80  double pfMax = 0.0,
81  double tf = 0.0
82  );
83 
84  const double freqFeedbackMin;
85  const double freqFeedbackMax;
86  const double ampFeedbackMin;
87  const double ampFeedbackMax;
88  const double phaseFeedbackMin;
89  const double phaseFeedbackMax;
90 
91  const double tensFeedback;
92 
93  // Values to be filled in by JSON file during onSetup
94  int numStates;
95  int numActions;
96  int numHidden;
97 
98  // Values to be filled in by JSON file during onSetup - goal sets
99  int goalStates;
100  int goalActions;
101  int goalHidden;
102 
103  };
104 
106  std::string args,
107  std::string resourcePath = "");
108 
109  virtual ~JSONGoalControl();
110 
111  virtual void onSetup(BaseSpineModelLearning& subject);
112 
113  virtual void onStep(BaseSpineModelLearning& subject, double dt);
114 
115  virtual void onTeardown(BaseSpineModelLearning& subject);
116 
117 protected:
118 
119  virtual void setupCPGs(BaseSpineModelLearning& subject, array_2D nodeActions, array_4D edgeActions);
120 
121  virtual array_2D scaleNodeActions (Json::Value actions);
122 
123  std::vector<double> getGoalFeedback(const BaseSpineModelGoal* subject);
124 
125  virtual std::vector<double> getFeedback(BaseSpineModelLearning& subject);
126 
127  std::vector<double> getCableState(const tgSpringCableActuator& cable);
128 
129  // Changes scale of actions from [0, 1] to [-1, 1]
130  void transformFeedbackActions(std::vector<double>& actions);
131 
132  double calculateDistanceMoved(const BaseSpineModelGoal* subject) const;
133 
134  JSONGoalControl::Config m_config;
135 
137  neuralNetwork* nn;
138  neuralNetwork* nn_goal;
139 
140 
141 };
142 
143 #endif // SPINE_FEEDBACK_CONTROL_H
virtual void onSetup(BaseSpineModelLearning &subject)
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, double ffMin=0.0, double ffMax=0.0, double afMin=0.0, double afMax=0.0, double pfMin=0.0, double pfMax=0.0, double tf=0.0)
JSONGoalControl(JSONGoalControl::Config config, std::string args, std::string resourcePath="")
An adaptation of JSONCPGControl that utilizes JSON for parameters.
neuralNetwork * nn
virtual void onTeardown(BaseSpineModelLearning &subject)
std::vector< double > getGoalFeedback(const BaseSpineModelGoal *subject)
virtual void onStep(BaseSpineModelLearning &subject, double dt)