World::World(float dt, QObject *parent) : QObject(parent), world(NULL), timer(NULL), time(0), dt(dt) { timer = new QTimer(this); timer->setInterval(1000.*dt); timer->setSingleShot(false); connect(timer,SIGNAL(timeout()),this,SLOT(stepWorld())); }
stateStruct Mechanism::simulate(std::vector<double>& action){ // set the necessary parameters from the startState setGoalWithAction(action); // Same for each mechanism: defined in this file // run iterations of the simulation to generate a new state // make sure dynamic world exists - allows fixed case - kind of a hack if (dynamicsWorld_){ for(size_t i = 0; i<1000;i++){ stepWorld(); } } // return the state of the world after the iterations std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; return returnStateOfWorld(); // Virtual function: not defined in this file }
std::vector<double> BasicDemo::runSimulation(std::vector<double> prevState, std::vector<double> action){ startPose_.setValue(prevState[0],1.0,prevState[1]); initPhysics(); desiredPose_.setValue(action[0],1.0,action[1]); for(size_t i = 0; i<1000;i++){ stepWorld(); } std::vector<double> nextState; nextState.push_back(bravoBodyTrans_.getOrigin().getX()); nextState.push_back(bravoBodyTrans_.getOrigin().getZ()); return nextState; }
/* Advance the simulation by one time step. Render and/or dump statistics * if neccesary. Return false if the user wants to quit. */ static bool stepSimulation(Timer *renderTimer) { static int stepsSinceVerbose = 0; stepWorld(); if (config.verbose > 0) { stepsSinceVerbose++; if (stepsSinceVerbose > config.verbose) { stepsSinceVerbose = 0; dumpStats(); } } if (config.render && tickTimer(renderTimer)) return stepGraphics(); return true; }