//roverbot go back to its starting position after its bumper is hit
//you may notice that it does not exactly go to its initial position if 
//say its wheels slip or the ground is uneven

int returntime ;

void go_forward()
{
   ClearTimer(0); //start timer(0)
   OnFwd (OUT_A+OUT_C);
   
   until (SENSOR_2 ==1);
   returntime = Timer(0); //store value of Timer(0) when bumper is hit
   
}

void go_back()
{
   
   OnFwd(OUT_A); OnRev(OUT_C); Wait (220);   //to make a 180 degree turn. might have to change the wait time
   ClearTimer(0);                            //timer(0) started
   OnFwd(OUT_A+OUT_C);
   until ( Timer(0) > returntime );
   Off (OUT_A+OUT_C);                        //switch off motor after coming back
}
   
task main()
{
   SetSensor(SENSOR_2, SENSOR_TOUCH);  //touch sensor attached to sensor 2
   go_forward();
   until (SENSOR_2 ==1);
   go_back();
}   
      

    Source: geocities.com/fuhan75