// motion.cc by Mikael Beckius 2000-04-17 - . // #include "motion.hh" using namespace std; int delay = 2; // shouldn't be here, but gives seg fault if declred in the Motion class. Motion::Motion(){ leda_string path = ""; //leda_vector InitialState; //leda_vector GoalState; prob = new Problem(new WorldPolygonal(path),new Model2DPoint(path), path); //rrt = new RRTExtExt(new Problem(new WorldPolygonal(path),new Model2DPoint(path), path)); rrt = new RRTExtExt(prob); cout<<"Motion"<Explore(); rrt->Plan(0.4,pathplan); cout<<"Motion done!"< &obst, vector &rob):gdist(0.5){ leda_string path = ""; float x = 0, y = 0, z = 0; robots = &rob; obstacles = &obst; PQPObject *obj = (*robots)[0]; Robot* robo = static_cast(obj); robo->getTrans(x,y,z); //leda_vector q(x,y,z,robo->getRotY()); //leda_vector q2(70.0,4,-70,robo->getRotY()); model = new Model3Dy(path); world = new WorldPQP(path,obst,rob); prob = new Problem(world,model, path); //prob->InitialState = q; //prob->GoalState = q2; //cout<<"Motion"<Explore(); cout<<"Avstand: "<GoalDist<Plan(gdist,pathplan); //reversePath = pathplan; //cout<<"Path length: "<(obj); //cout<<"ROT: "<getRotY()<getRotY(); prob->GoalState = q; //cout<(obj); robo->getTrans(x,y,z); leda_vector q(4); q[0]=x; q[1] = y; q[2] = z; q[3] = robo->getRotY(); //leda_vector q2(70.0,-70,robo->getRotY()); prob->InitialState = q; //cout<Explore(); rrt->G.clear(); rrt->GG.clear(); setInit(); pathplan.clear(); rrt->Plan(gdist,pathplan); reversePath = pathplan; cout<<"Path length: "<Explore(); rrt->Plan(gdist,pathplan); } void Motion::draw(){ drawPath(); drawRRT(); } void Motion::drawRobot(){ leda_node n; leda_vector q; //list_item L.first(); PQPObject *obj = (*robots)[0]; Robot* robo = static_cast(obj); //cout<<"Delay: "< 0){ if (delay == 0){ n = reversePath.pop(); delay = 3; q = rrt->P->StateToConfiguration(rrt->G.inf(n)); robo->setPos(q); } if(delay > 0) delay--; } } void Motion::drawPath(){ leda_node n; leda_vector q,q2; // Show goal q = rrt->P->StateToConfiguration(rrt->P->GoalState); glPushMatrix(); glColor3f(1.0,1.0,0.0); glTranslatef(q[0],q[1],q[2]); glutSolidSphere(0.35,15,15); glPopMatrix(); if (pathplan.length() > 0){ // Show init. q2 = rrt->P->StateToConfiguration(rrt->P->InitialState); glPushMatrix(); glColor3f(0.0,1.0,1.0); glTranslatef(q2[0],q2[1],q2[2]); glutSolidSphere(0.35,15,15); glPopMatrix(); // Show path. forall(n,pathplan) { q = rrt->P->StateToConfiguration(rrt->G.inf(n)); glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(q[0],q[1],q[2]); glutSolidSphere(.15,5,5); glPopMatrix(); } glPushMatrix(); glDisable(GL_LIGHTING); glBegin(GL_LINES); forall(n,pathplan) { q = rrt->P->StateToConfiguration(rrt->G.inf(n)); glVertex3f(q2[0],q2[1],q2[2]); glVertex3f(q[0],q[1],q[2]); q2 = q; } glEnd(); glEnable(GL_LIGHTING); glPopMatrix(); } } void Motion::drawRRT(){ leda_node n; leda_vector q; // Show goal q = rrt->P->StateToConfiguration(rrt->P->GoalState); glPushMatrix(); glColor3f(1.0,1.0,0.0); glTranslatef(q[0],q[1],q[2]); //glutSolidSphere(0.75,15,15); glPopMatrix(); // Show init q = rrt->P->StateToConfiguration(rrt->P->InitialState); glPushMatrix(); glColor3f(0.0,1.0,1.0); glTranslatef(0,0,0); glTranslatef(q[0],q[1],q[2]); //glutSolidSphere(1.15,15,15); glPopMatrix(); //cout<<"Start: "<G.number_of_nodes() > 0) { forall_nodes(n,rrt->G) { q = rrt->P->StateToConfiguration(rrt->G.inf(n)); //cout<<"random: "<draw_point(q[0],q[1],brown); glPopMatrix(); } } // Show second tree (if it exists) if (rrt->GG.number_of_nodes() > 0) { forall_nodes(n,rrt->GG) { q = rrt->P->StateToConfiguration(rrt->G.inf(n)); glPushMatrix(); glColor3f(0.0,1.0,0.0); glTranslatef(q[0],q[1],q[2]); glutSolidSphere(.15,15,15); glPopMatrix(); //w->draw_point(q[0],q[1],brown); } } } Motion::~Motion(){ delete rrt; }