28 #include "AppQuadControlSpiral.h"
29 #include "dev/btietz/JSONTests/tgCPGJSONLogger.h"
31 AppQuadControlSpiral::AppQuadControlSpiral(
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;
88 const int segmentSpan = 3;
89 const int numMuscles = 16;
90 const int numParams = 2;
91 const int segNumber = 0;
92 const double controlTime = .01;
93 const double lowPhase = -1 * M_PI;
94 const double highPhase = M_PI;
95 const double lowAmplitude = 0.0;
96 const double highAmplitude = 300.0;
97 const double kt = 0.0;
98 const double kp = 1000.0;
99 const double kv = 200.0;
100 const bool def =
true;
103 const double cl = 10.0;
104 const double lf = 0.0;
105 const double hf = 30.0;
108 const double ffMin = -0.5;
109 const double ffMax = 10.0;
110 const double afMin = 0.0;
111 const double afMax = 200.0;
112 const double pfMin = -0.5;
113 const double pfMax = 6.28;
115 const double maxH = 70.0;
116 const double minH = 1.0;
151 myControl->
attach(myLogger);
153 myModel->
attach(myControl);
161 tgModel* blockField = getBlocks();
169 void AppQuadControlSpiral::handleOptions(
int argc,
char **argv)
172 po::options_description desc(
"Allowed options");
174 (
"help,h",
"produce help message")
175 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
176 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
177 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
178 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
179 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
180 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
181 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
182 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
183 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
184 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
185 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
186 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
187 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
188 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
189 (
"goal_angle,B", po::value<double>(&goalAngle),
"Angle of starting rotation for goal box. Degrees. Default = 0")
190 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
191 (
"lower_path,P", po::value<std::string>(&lowerPath),
"Which resources folder in which you want to store controllers. Default = default")
194 po::variables_map vm;
195 po::store(po::parse_command_line(argc, argv, desc), vm);
197 if (vm.count(
"help"))
199 std::cout << desc <<
"\n";
205 if (vm.count(
"phys_time"))
207 timestep_physics = 1/vm[
"phys_time"].as<
double>();
208 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
211 if (vm.count(
"graph_time"))
213 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
214 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
220 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
221 btScalar friction = 0.5;
222 btScalar restitution = 0.0;
224 btVector3 size = btVector3(0.0, 0.1, 0.0);
225 btVector3 origin = btVector3(0.0, 0.0, 0.0);
229 double triangleSize = 4.0;
230 double waveHeight = 2.0;
233 size, origin, nx, ny, margin, triangleSize,
235 return hillGroundConfig;
240 const double yaw = 0.0;
241 const double pitch = 0.0;
242 const double roll = 0.0;
243 const double friction = 0.5;
244 const double restitution = 0.0;
245 const btVector3 size(1000.0, 1.5, 1000.0);
255 tgModel* AppQuadControlSpiral::getBlocks()
262 tgWorld* AppQuadControlSpiral::createWorld()
281 return new tgWorld(config, ground);
291 return new tgSimView(*world, timestep_physics, timestep_graphics);
309 simulate(simulation);
320 void AppQuadControlSpiral::simulate(
tgSimulation *simulation)
322 for (
int i=0; i<nEpisodes; i++) {
323 fprintf(stderr,
"Episode %d\n", i);
326 simulation->
run(nSteps);
328 catch (std::runtime_error e)
334 if (all_terrain && i != nEpisodes - 1)
342 simulation->
reset(ground);
345 else if (i % nTypes == 1)
349 simulation->
reset(ground);
352 else if (i % nTypes == 2)
355 tgModel* obstacle = getBlocks();
360 else if (i != nEpisodes - 1)
374 int main(
int argc,
char** argv)
376 std::cout <<
"AppQuadControlSpiral" << std::endl;
int main(int argc, char **argv)
void addObstacle(tgModel *pObstacle)
void addModel(tgModel *pModel)
void attach(tgObserver< T > *pObserver)