29 #include "dev/btietz/JSONTests/tgCPGJSONLogger.h"
31 #include <json/json.h>
33 AppAOHierarchy::AppAOHierarchy(
int argc,
char** argv)
37 add_controller =
true;
41 timestep_physics = 1.0f/1000.0f;
42 timestep_graphics = 1.0f/60.0f;
54 lowerPath =
"default";
56 handleOptions(argc, argv);
62 world = createWorld();
66 view = createGraphicsView(world);
68 view = createView(world);
80 const int segments = 7;
94 std::string controlFilename = controlFilePath + suffix;
96 bool parsingSuccessful = reader.parse( FileHelpers::getFileString(controlFilename.c_str()), root );
97 if ( !parsingSuccessful )
100 std::cout <<
"Failed to parse configuration\n"
101 << reader.getFormattedErrorMessages();
102 throw std::invalid_argument(
"Bad filename for JSON, check that resource path exists");
106 Json::Value impedenceVals = root.get(
"impedenceVals",
"UTF-8");
107 impedenceVals = impedenceVals.get(
"params",
"UTF-8");
110 if (impedenceVals[0].isArray())
112 impedenceVals = impedenceVals[0];
115 const double impedanceMax = 2000.0;
116 const int segmentSpan = 3;
117 const int numMuscles = 2;
118 const int numParams = 2;
119 const int segNumber = 0;
120 const double controlTime = .01;
121 const double lowPhase = -1 * M_PI;
122 const double highPhase = M_PI;
123 const double lowAmplitude = 0.0;
124 const double highAmplitude = 300.0;
127 const double kt = impedanceMax * (impedenceVals.get(j, 0.0)).asDouble();
128 const double kp = impedanceMax * (impedenceVals.get(1, 0.0)).asDouble();
129 const double kv = impedanceMax * (impedenceVals.get(2, 0.0)).asDouble();
133 const bool def =
true;
136 const double cl = 10.0;
137 const double lf = 0.0;
138 const double hf = 30.0;
141 const double ffMin = 0.1;
142 const double ffMax = 10.0;
143 const double afMin = 0.0;
144 const double afMax = 200.0;
145 const double pfMin = -0.5;
146 const double pfMax = 6.28;
148 const double maxH = 30.0;
149 const double minH = 7.0;
151 const double numHipMuscles = 6;
152 const double numLegMuscles = 6;
154 const double numAchillesMuscles = 2;
157 const double numHighCPGs = 5;
158 const double hf2 = 30.0;
159 const double ffMax2 = 10.0;
196 myControl->
attach(myLogger);
198 myModel->
attach(myControl);
206 tgModel* blockField = getBlocks();
214 void AppAOHierarchy::handleOptions(
int argc,
char **argv)
217 po::options_description desc(
"Allowed options");
219 (
"help,h",
"produce help message")
220 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
221 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
222 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
223 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
224 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
225 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
226 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
227 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
228 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
229 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
230 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
231 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
232 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
233 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
234 (
"goal_angle,B", po::value<double>(&goalAngle),
"Angle of starting rotation for goal box. Degrees. Default = 0")
235 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
236 (
"lower_path,P", po::value<std::string>(&lowerPath),
"Which resources folder in which you want to store controllers. Default = default")
239 po::variables_map vm;
240 po::store(po::parse_command_line(argc, argv, desc), vm);
242 if (vm.count(
"help"))
244 std::cout << desc <<
"\n";
250 if (vm.count(
"phys_time"))
252 timestep_physics = 1/vm[
"phys_time"].as<
double>();
253 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
256 if (vm.count(
"graph_time"))
258 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
259 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
265 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
266 btScalar friction = 0.5;
267 btScalar restitution = 0.0;
269 btVector3 size = btVector3(0.0, 0.1, 0.0);
270 btVector3 origin = btVector3(0.0, 0.0, 0.0);
274 double triangleSize = 4.0;
275 double waveHeight = 2.0;
278 size, origin, nx, ny, margin, triangleSize,
280 return hillGroundConfig;
285 const double yaw = 0.0;
286 const double pitch = 0.0;
287 const double roll = 0.0;
288 const double friction = 0.5;
289 const double restitution = 0.0;
290 const btVector3 size(1000.0, 1.5, 1000.0);
300 tgModel* AppAOHierarchy::getBlocks()
307 tgWorld* AppAOHierarchy::createWorld()
326 return new tgWorld(config, ground);
336 return new tgSimView(*world, timestep_physics, timestep_graphics);
354 simulate(simulation);
369 for (
int i=0; i<nEpisodes; i++) {
370 fprintf(stderr,
"Episode %d\n", i);
373 simulation->
run(nSteps);
375 catch (std::runtime_error e)
381 if (all_terrain && i != nEpisodes - 1)
389 simulation->
reset(ground);
392 else if (i % nTypes == 1)
396 simulation->
reset(ground);
399 else if (i % nTypes == 2)
402 tgModel* obstacle = getBlocks();
407 else if (i != nEpisodes - 1)
421 int main(
int argc,
char** argv)
423 std::cout <<
"AppAOHierarchy" << std::endl;
void addObstacle(tgModel *pObstacle)
void addModel(tgModel *pModel)
A series of functions to assist with file input/output.
static std::string getResourcePath(std::string relPath)
int main(int argc, char **argv)
void attach(tgObserver< T > *pObserver)
Contains the definition function main() for the Multiple terrains app, used here for control of a qua...