27 #include "AppMultiTerrain_OC.h"
38 AppMultiTerrain_OC::AppMultiTerrain_OC(
int argc,
char** argv)
42 add_controller =
true;
46 timestep_physics = 1.0f/1000.0f;
47 timestep_graphics = 1.0f/60.0f;
60 handleOptions(argc, argv);
66 world = createWorld();
70 view = createGraphicsView(world);
72 view = createView(world);
81 double goalAngle = -M_PI / 2.0;
91 const int segmentSpan = 3;
92 const int numMuscles = 4;
93 const int numParams = 2;
94 const int segNumber = 0;
95 const double controlTime = .01;
96 const double lowPhase = -1 * M_PI;
97 const double highPhase = M_PI;
98 const double lowAmplitude = 0.0;
99 const double highAmplitude = 300.0;
100 const double kt = 0.0;
101 const double kp = 1000.0;
102 const double kv = 210.0;
103 const bool def =
true;
106 const double cl = 10.0;
107 const double lf = 0.0;
108 const double hf = 30.0;
111 const double ffMin = -0.5;
112 const double ffMax = 10.0;
113 const double afMin = 0.0;
114 const double afMax = 200.0;
115 const double pfMin = -0.5;
116 const double pfMax = 6.28;
117 const double tensionFeedback = 1000.0;
178 myModel->
attach(myControl);
186 tgModel* blockField = getBlocks();
194 void AppMultiTerrain_OC::handleOptions(
int argc,
char **argv)
197 po::options_description desc(
"Allowed options");
199 (
"help,h",
"produce help message")
200 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
201 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
202 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
203 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
204 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
205 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
206 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
207 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
208 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
209 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
210 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
211 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
212 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
213 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
214 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
217 po::variables_map vm;
218 po::store(po::parse_command_line(argc, argv, desc), vm);
220 if (vm.count(
"help"))
222 std::cout << desc <<
"\n";
228 if (vm.count(
"phys_time"))
230 timestep_physics = 1/vm[
"phys_time"].as<
double>();
231 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
234 if (vm.count(
"graph_time"))
236 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
237 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
243 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
244 btScalar friction = 0.5;
245 btScalar restitution = 0.0;
247 btVector3 size = btVector3(0.0, 0.1, 0.0);
248 btVector3 origin = btVector3(0.0, 0.0, 0.0);
252 double triangleSize = 4.0;
253 double waveHeight = 2.0;
256 size, origin, nx, ny, margin, triangleSize,
258 return hillGroundConfig;
263 const double yaw = 0.0;
264 const double pitch = 0.0;
265 const double roll = 0.0;
266 const double friction = 0.5;
267 const double restitution = 0.0;
268 const btVector3 size(1000.0, 1.5, 1000.0);
278 tgModel* AppMultiTerrain_OC::getBlocks()
285 tgWorld* AppMultiTerrain_OC::createWorld()
304 return new tgWorld(config, ground);
314 return new tgSimView(*world, timestep_physics, timestep_graphics);
332 simulate(simulation);
343 void AppMultiTerrain_OC::simulate(
tgSimulation *simulation)
345 for (
int i=0; i<nEpisodes; i++) {
346 fprintf(stderr,
"Episode %d\n", i);
349 simulation->
run(nSteps);
351 catch (std::runtime_error e)
357 if (i != nEpisodes - 1)
368 simulation->
reset(ground);
371 else if (i % nTypes == 1)
375 simulation->
reset(ground);
378 else if (i % nTypes == 2)
381 tgModel* obstacle = getBlocks();
388 tgModel* obstacle = getBlocks();
406 int main(
int argc,
char** argv)
408 std::cout <<
"AppMultiTerrain_OC" << std::endl;
A controller for the template class BaseSpineModelLearning.
void addObstacle(tgModel *pObstacle)
Implementing the cross-linked octahedral complex spine inspired by Tom Flemons.
void addModel(tgModel *pModel)
A controller for the template class BaseSpineModelLearning.
int main(int argc, char **argv)
A controller for the template class BaseSpineModelLearning.
void attach(tgObserver< T > *pObserver)