28 #include "AppQuadSimpleActuation.h"
29 #include "dev/btietz/JSONTests/tgCPGJSONLogger.h"
31 #include <json/json.h>
33 AppQuadSimpleActuation::AppQuadSimpleActuation(
int argc,
char** argv)
37 add_controller =
true;
41 timestep_physics = 1.0f/1000.0f;
42 timestep_graphics = 1.0f/60.0f;
54 lowerPath =
"default";
56 handleOptions(argc, argv);
62 world = createWorld();
66 view = createGraphicsView(world);
68 view = createView(world);
80 const int segments = 7;
93 std::string resourcePath =
"bgigous/AppQuadSimpleActuation/";
95 std::string controlFilename = controlFilePath + suffix;
97 bool parsingSuccessful = reader.parse( FileHelpers::getFileString(controlFilename.c_str()), root );
98 if ( !parsingSuccessful )
101 std::cout <<
"Failed to parse configuration\n"
102 << reader.getFormattedErrorMessages();
103 throw std::invalid_argument(
"Bad filename for JSON, check that resource path exists");
107 Json::Value impedenceVals = root.get(
"impedenceVals",
"UTF-8");
108 impedenceVals = impedenceVals.get(
"params",
"UTF-8");
111 if (impedenceVals[0].isArray())
113 impedenceVals = impedenceVals[0];
116 const double impedanceMax = 2000.0;
118 const int segmentSpan = 3;
119 const int numMuscles = 16;
120 const int numParams = 2;
121 const int segNumber = 0;
122 const double controlTime = .01;
123 const double lowPhase = -1*M_PI;
124 const double highPhase = M_PI;
125 const double lowAmplitude = 0.0;
126 const double highAmplitude = 300.0;
131 const double kt = impedanceMax * (impedenceVals.get(j, 0.0)).asDouble();
132 const double kp = impedanceMax * (impedenceVals.get(1, 0.0)).asDouble();
133 const double kv = impedanceMax * (impedenceVals.get(2, 0.0)).asDouble();
134 const bool def =
false;
137 const double cl = 10.0;
138 const double lf = 0.0;
139 const double hf = 1.5;
142 const double ffMin = 0.0;
143 const double ffMax = 1;
144 const double afMin = 0.0;
145 const double afMax = 200;
146 const double pfMin = -0.5;
147 const double pfMax = 6.28;
149 const double maxH = 300.0;
150 const double minH = 1.0;
185 myControl->
attach(myLogger);
187 myModel->
attach(myControl);
195 tgModel* blockField = getBlocks();
203 void AppQuadSimpleActuation::handleOptions(
int argc,
char **argv)
206 po::options_description desc(
"Allowed options");
208 (
"help,h",
"produce help message")
209 (
"graphics,G", po::value<bool>(&use_graphics),
"Test using graphical view")
210 (
"controller,c", po::value<bool>(&add_controller),
"Attach the controller to the model.")
211 (
"blocks,b", po::value<bool>(&add_blocks)->implicit_value(
false),
"Add a block field as obstacles.")
212 (
"hills,H", po::value<bool>(&add_hills)->implicit_value(
false),
"Use hilly terrain.")
213 (
"all_terrain,A", po::value<bool>(&all_terrain)->implicit_value(
false),
"Alternate through terrain types. Only works with graphics off")
214 (
"phys_time,p", po::value<double>(),
"Physics timestep value (Hz). Default=1000")
215 (
"graph_time,g", po::value<double>(),
"Graphics timestep value a.k.a. render rate (Hz). Default = 60")
216 (
"episodes,e", po::value<int>(&nEpisodes),
"Number of episodes to run. Default=1")
217 (
"steps,s", po::value<int>(&nSteps),
"Number of steps per episode to run. Default=60K (60 seconds)")
218 (
"segments,S", po::value<int>(&nSegments),
"Number of segments in the tensegrity spine. Default=6")
219 (
"start_x,x", po::value<double>(&startX),
"X Coordinate of starting position for robot. Default = 0")
220 (
"start_y,y", po::value<double>(&startY),
"Y Coordinate of starting position for robot. Default = 20")
221 (
"start_z,z", po::value<double>(&startZ),
"Z Coordinate of starting position for robot. Default = 0")
222 (
"angle,a", po::value<double>(&startAngle),
"Angle of starting rotation for robot. Degrees. Default = 0")
223 (
"goal_angle,B", po::value<double>(&goalAngle),
"Angle of starting rotation for goal box. Degrees. Default = 0")
224 (
"learning_controller,l", po::value<std::string>(&suffix),
"Which learned controller to write to or use. Default = default")
225 (
"lower_path,P", po::value<std::string>(&lowerPath),
"Which resources folder in which you want to store controllers. Default = default")
228 po::variables_map vm;
229 po::store(po::parse_command_line(argc, argv, desc), vm);
231 if (vm.count(
"help"))
233 std::cout << desc <<
"\n";
239 if (vm.count(
"phys_time"))
241 timestep_physics = 1/vm[
"phys_time"].as<
double>();
242 std::cout <<
"Physics timestep set to: " << timestep_physics <<
" seconds.\n";
245 if (vm.count(
"graph_time"))
247 timestep_graphics = 1/vm[
"graph_time"].as<
double>();
248 std::cout <<
"Graphics timestep set to: " << timestep_graphics <<
" seconds.\n";
254 btVector3 eulerAngles = btVector3(0.0, 0.0, 0.0);
255 btScalar friction = 0.5;
256 btScalar restitution = 0.0;
258 btVector3 size = btVector3(0.0, 0.1, 0.0);
259 btVector3 origin = btVector3(0.0, 0.0, 0.0);
263 double triangleSize = 4.0;
264 double waveHeight = 2.0;
267 size, origin, nx, ny, margin, triangleSize,
269 return hillGroundConfig;
274 const double yaw = 0.0;
275 const double pitch = 0.0;
276 const double roll = 0.0;
277 const double friction = 0.5;
278 const double restitution = 0.0;
279 const btVector3 size(1000.0, 1.5, 1000.0);
289 tgModel* AppQuadSimpleActuation::getBlocks()
296 tgWorld* AppQuadSimpleActuation::createWorld()
315 return new tgWorld(config, ground);
325 return new tgSimView(*world, timestep_physics, timestep_graphics);
343 simulate(simulation);
355 void AppQuadSimpleActuation::simulate(
tgSimulation *simulation)
357 for (
int i=0; i<nEpisodes; i++) {
358 fprintf(stderr,
"Episode %d\n", i);
361 simulation->
run(nSteps);
363 catch (std::runtime_error e)
369 if (all_terrain && i != nEpisodes - 1)
377 simulation->
reset(ground);
380 else if (i % nTypes == 1)
384 simulation->
reset(ground);
387 else if (i % nTypes == 2)
390 tgModel* obstacle = getBlocks();
395 else if (i != nEpisodes - 1)
409 int main(
int argc,
char** argv)
411 std::cout <<
"AppQuadSimpleActuation" << 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)
void attach(tgObserver< T > *pObserver)