27 #include "AppTSGoal.h"
29 AppTSGoal::AppTSGoal(
int argc,
char** argv)
33 add_controller =
true;
37 timestep_physics = 1.0f/1000.0f;
38 timestep_graphics = 1.0f/60.0f;
51 handleOptions(argc, argv);
57 const double scale = 100;
58 world = createWorld();
62 view = createGraphicsView(world);
64 view = createView(world);
79 const int segmentSpan = 3;
80 const int numMuscles = 6;
81 const int numParams = 2;
82 const int segNumber = 5;
83 const double controlTime = .01;
84 const double lowPhase = -1 * M_PI;
85 const double highPhase = M_PI;
86 const double lowAmplitude = 0.0;
87 const double highAmplitude = 300.0;
88 const double kt = 0.0;
89 const double kp = 1000.0;
90 const double kv = 200.0;
91 const bool def =
true;
94 const double cl = 10.0;
95 const double lf = 0.0;
96 const double hf = 30.0;
99 const double ffMin = -0.5;
100 const double ffMax = 10.0;
101 const double afMin = 0.0;
102 const double afMax = 200.0;
103 const double pfMin = -0.5;
104 const double pfMax = 6.28;
105 const double tensionFeedback = 1000.0;
106 #if (0) // Switch for .nnw or JSON based methods
168 myModel->
attach(myControl);
176 tgModel* blockField = getBlocks();
184 void AppTSGoal::handleOptions(
int argc,
char **argv)
187 po::options_description desc(
"Allowed options");
189 (
"help,h",
"produce help message")
190 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
191 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
192 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
193 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
194 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
195 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
196 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
197 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
198 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
199 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
200 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
201 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
202 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
203 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
204 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
207 po::variables_map vm;
208 po::store(po::parse_command_line(argc, argv, desc), vm);
210 if (vm.count(
"help"))
212 std::cout << desc <<
"\n";
218 if (vm.count(
"phys_time"))
220 timestep_physics = 1/vm[
"phys_time"].as<
double>();
221 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
224 if (vm.count(
"graph_time"))
226 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
227 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
233 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
234 btScalar friction = 0.5;
235 btScalar restitution = 0.0;
237 btVector3 size = btVector3(0.0, 0.1, 0.0);
238 btVector3 origin = btVector3(0.0, 0.0, 0.0);
242 double triangleSize = 4.0;
243 double waveHeight = 2.0;
246 size, origin, nx, ny, margin, triangleSize,
248 return hillGroundConfig;
253 const double yaw = 0.0;
254 const double pitch = 0.0;
255 const double roll = 0.0;
256 const double friction = 0.5;
257 const double restitution = 0.0;
258 const btVector3 size(1000.0, 1.5, 1000.0);
268 tgModel* AppTSGoal::getBlocks()
275 tgWorld* AppTSGoal::createWorld()
294 return new tgWorld(config, ground);
304 return new tgSimView(*world, timestep_physics, timestep_graphics);
322 simulate(simulation);
335 for (
int i=0; i<nEpisodes; i++) {
336 fprintf(stderr,
"Episode %d\n", i);
339 simulation->
run(nSteps);
341 catch (std::runtime_error e)
347 if (i != nEpisodes - 1)
358 simulation->
reset(ground);
361 else if (i % nTypes == 1)
365 simulation->
reset(ground);
368 else if (i % nTypes == 2)
371 tgModel* obstacle = getBlocks();
378 tgModel* obstacle = getBlocks();
396 int main(
int argc,
char** argv)
398 std::cout <<
"AppTSGoal" << std::endl;
int main(int argc, char **argv)
void addObstacle(tgModel *pObstacle)
void addModel(tgModel *pModel)
void attach(tgObserver< T > *pObserver)