void drive() { float vel[2] = {0.1, 0.0}; // create an array to store our velocity float pos[2] = {0,0}; // create an array to store our position float lastTime=com.msecsElapsed(); // remember last time to measure change in time to calculate position while( com.isConnected() && false == bumper.value() && _run ) { pos[0]=vel[0]*(com.msecsElapsed()-lastTime)+pos[0]; // update the position pos[1]=vel[1]*(com.msecsElapsed()-lastTime)+pos[1]; std::cout << "Pos:" << pos[0] << "," << pos[1] <=_rect[0] && pos[1] <= 0){ // this if statement changes the velocity when we reach the first corner of our rectange vel[0]=0; vel[1]=.1; } if(pos[0]>=_rect[0] && pos[1] >= _rect[1]){ // second corner vel[0]=-0.1; vel[1]=0; } if(pos[0]<=0 && pos[1] >= _rect[1]){ // third corner vel[0]=0; vel[1]=-0.1; } if(pos[0]<=0 && pos[1] <= 0){ // back to start location vel[0]=0.1; vel[1]=0; } lastTime=com.msecsElapsed(); // reset the last time variable com.processEvents(); // sincronizes the com class and the onboard computer rec::robotino::api2::msleep( 100 ); // wait 100 ms } }