28 #include "AppQuadControlSegments.h"
29 #include "dev/btietz/JSONTests/tgCPGJSONLogger.h"
31 AppQuadControlSegments::AppQuadControlSegments(
int argc,
char** argv)
35 add_controller =
true;
39 timestep_physics = 1.0f/1000.0f;
40 timestep_graphics = 1.0f/60.0f;
52 lowerPath =
"default";
54 handleOptions(argc, argv);
60 world = createWorld();
64 view = createGraphicsView(world);
66 view = createView(world);
78 const int segments = 7;
87 const int segmentSpan = 3;
88 const int numMuscles = 32;
89 const int numParams = 2;
90 const int segNumber = 0;
91 const double controlTime = .01;
92 const double lowPhase = -1 * M_PI;
93 const double highPhase = M_PI;
94 const double lowAmplitude = 0.0;
95 const double highAmplitude = 300.0;
96 const double kt = 0.0;
97 const double kp = 1000.0;
98 const double kv = 200.0;
99 const bool def =
true;
102 const double cl = 10.0;
103 const double lf = 0.0;
104 const double hf = 30.0;
107 const double ffMin = -0.5;
108 const double ffMax = 10.0;
109 const double afMin = 0.0;
110 const double afMax = 200.0;
111 const double pfMin = -0.5;
112 const double pfMax = 6.28;
114 const double maxH = 30.0;
115 const double minH = 1.0;
118 const int numHipMuscles = 30;
119 const int numLegMuscles = 20;
158 myControl->
attach(myLogger);
160 myModel->
attach(myControl);
168 tgModel* blockField = getBlocks();
176 void AppQuadControlSegments::handleOptions(
int argc,
char **argv)
179 po::options_description desc(
"Allowed options");
181 (
"help,h",
"produce help message")
182 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
183 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
184 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
185 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
186 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
187 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
188 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
189 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
190 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
191 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
192 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
193 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
194 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
195 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
196 (
"goal_angle,B", po::value<double>(&goalAngle),
"Angle of starting rotation for goal box. Degrees. Default = 0")
197 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
198 (
"lower_path,P", po::value<std::string>(&lowerPath),
"Which resources folder in which you want to store controllers. Default = default")
201 po::variables_map vm;
202 po::store(po::parse_command_line(argc, argv, desc), vm);
204 if (vm.count(
"help"))
206 std::cout << desc <<
"\n";
212 if (vm.count(
"phys_time"))
214 timestep_physics = 1/vm[
"phys_time"].as<
double>();
215 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
218 if (vm.count(
"graph_time"))
220 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
221 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
227 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
228 btScalar friction = 0.5;
229 btScalar restitution = 0.0;
231 btVector3 size = btVector3(0.0, 0.1, 0.0);
232 btVector3 origin = btVector3(0.0, 0.0, 0.0);
236 double triangleSize = 4.0;
237 double waveHeight = 2.0;
240 size, origin, nx, ny, margin, triangleSize,
242 return hillGroundConfig;
247 const double yaw = 0.0;
248 const double pitch = 0.0;
249 const double roll = 0.0;
250 const double friction = 0.5;
251 const double restitution = 0.0;
252 const btVector3 size(1000.0, 1.5, 1000.0);
262 tgModel* AppQuadControlSegments::getBlocks()
269 tgWorld* AppQuadControlSegments::createWorld()
288 return new tgWorld(config, ground);
298 return new tgSimView(*world, timestep_physics, timestep_graphics);
316 simulate(simulation);
327 void AppQuadControlSegments::simulate(
tgSimulation *simulation)
329 for (
int i=0; i<nEpisodes; i++) {
330 fprintf(stderr,
"Episode %d\n", i);
333 simulation->
run(nSteps);
335 catch (std::runtime_error e)
341 if (all_terrain && i != nEpisodes - 1)
349 simulation->
reset(ground);
352 else if (i % nTypes == 1)
356 simulation->
reset(ground);
359 else if (i % nTypes == 2)
362 tgModel* obstacle = getBlocks();
367 else if (i != nEpisodes - 1)
381 int main(
int argc,
char** argv)
383 std::cout <<
"AppQuadControlSegments" << std::endl;
void addObstacle(tgModel *pObstacle)
void addModel(tgModel *pModel)
int main(int argc, char **argv)
void attach(tgObserver< T > *pObserver)