Explore.cpp

From IPRE Wiki
Revision as of 20:45, 8 March 2011 by Jhoare (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <Myro.h>
#include <iostream>

/**
 * This program causes the robot to "explore" the room.  The robot starts moving
 * forward, and when it hits a wall (i.e., it stalls) it stops, backs up a bit,
 * turns a bit, then continues moving forward. The program stops when 1 minute 
 * is up.
 */

int main(){
    connect();

    robot.forward(0.7);

    // Run for 1 minute
    while(timeRemaining(60)){
        if ( robot.getStall() ){
            // We must have hit something to stop, backup a bit, turn, 
            // and continue
            robot.stop();
            robot.backward(0.4,1.0);
            robot.turnLeft(0.5, 0.75);
            robot.forward(0.7);
        }
    }
    robot.stop();

    disconnect();
}