27 #include "AppGoalTension.h"
32 #include <json/json.h>
34 AppGoalTension::AppGoalTension(
int argc,
char** argv)
38 add_controller =
true;
42 timestep_physics = 1.0f/1000.0f;
43 timestep_graphics = 1.0f/60.0f;
57 handleOptions(argc, argv);
65 world = createWorld();
69 view = createGraphicsView(world);
71 view = createView(world);
79 startAngle = ((rand() / (double)RAND_MAX) - 0.5) * 3.1415;
90 std::string resourcePath =
"bmirletz/TC_Tension/";
92 std::string controlFilename = controlFilePath + suffix;
94 bool parsingSuccessful = reader.parse( FileHelpers::getFileString(controlFilename.c_str()), root );
95 if ( !parsingSuccessful )
98 std::cout <<
"Failed to parse configuration\n"
99 << reader.getFormattedErrorMessages();
100 throw std::invalid_argument(
"Bad filename for JSON");
104 Json::Value impedenceVals = root.get(
"impedenceVals",
"UTF-8");
105 impedenceVals = impedenceVals.get(
"params",
"UTF-8");
108 if (impedenceVals[0].isArray())
110 impedenceVals = impedenceVals[0];
113 const double impedanceMax = 2000.0;
115 const int segmentSpan = 3;
116 const int numMuscles = 8;
117 const int numParams = 2;
118 const int segNumber = 5;
119 const double controlTime = .01;
120 const double lowPhase = -1 * M_PI;
121 const double highPhase = M_PI;
122 const double lowAmplitude = 0.0;
123 const double highAmplitude = 300.0;
126 const double kt = impedanceMax * (impedenceVals.get(j, 0.0)).asDouble();
127 const double kp = impedanceMax * (impedenceVals.get(1, 0.0)).asDouble();
128 const double kv = impedanceMax * (impedenceVals.get(2, 0.0)).asDouble();
129 const bool def =
true;
132 const double cl = 10.0;
133 const double lf = 0.0;
134 const double hf = 30.0;
137 const double ffMin = -10.0;
138 const double ffMax = 10.0;
139 const double afMin = 0.0;
140 const double afMax = 200.0;
141 const double pfMin = 0.0;
142 const double pfMax = 0.0;
143 const double tensionFeedback = impedanceMax *(impedenceVals.get(3, 0.0)).asDouble();
175 myModel->
attach(myControl);
183 tgModel* blockField = getBlocks();
191 void AppGoalTension::handleOptions(
int argc,
char **argv)
194 po::options_description desc(
"Allowed options");
196 (
"help,h",
"produce help message")
197 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
198 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
199 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
200 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
201 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
202 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
203 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
204 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
205 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
206 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
207 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
208 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
209 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
210 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
211 (
"goal_angle,B", po::value<double>(&goalAngle),
"Angle of starting rotation for goal box. Degrees. Default = 0")
212 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
215 po::variables_map vm;
216 po::store(po::parse_command_line(argc, argv, desc), vm);
218 if (vm.count(
"help"))
220 std::cout << desc <<
"\n";
226 if (vm.count(
"phys_time"))
228 timestep_physics = 1/vm[
"phys_time"].as<
double>();
229 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
232 if (vm.count(
"graph_time"))
234 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
235 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
241 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
242 btScalar friction = 0.5;
243 btScalar restitution = 0.0;
245 btVector3 size = btVector3(0.0, 0.1, 0.0);
246 btVector3 origin = btVector3(0.0, 0.0, 0.0);
250 double triangleSize = 4.0;
251 double waveHeight = 2.0;
254 size, origin, nx, ny, margin, triangleSize,
256 return hillGroundConfig;
261 const double yaw = 0.0;
262 const double pitch = 0.0;
263 const double roll = 0.0;
264 const double friction = 0.5;
265 const double restitution = 0.0;
266 const btVector3 size(1000.0, 1.5, 1000.0);
276 tgModel* AppGoalTension::getBlocks()
283 tgWorld* AppGoalTension::createWorld()
302 return new tgWorld(config, ground);
312 return new tgSimView(*world, timestep_physics, timestep_graphics);
330 simulate(simulation);
343 for (
int i=0; i<nEpisodes; i++) {
344 fprintf(stderr,
"Episode %d\n", i);
347 simulation->
run(nSteps);
349 catch (std::runtime_error e)
355 if (i != nEpisodes - 1)
366 simulation->
reset(ground);
369 else if (i % nTypes == 1)
373 simulation->
reset(ground);
376 else if (i % nTypes == 2)
379 tgModel* obstacle = getBlocks();
386 tgModel* obstacle = getBlocks();
404 int main(
int argc,
char** argv)
406 std::cout <<
"AppGoalTension" << 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)
Rand seeding simular to the evolution and terrain classes.
void attach(tgObserver< T > *pObserver)