Avoid with bumper program

Here is a natural use for a bumper with a left & right sensor: To avoid an obstacle after bumping into it.

/********************************************************************************

******* Back-away-readjust – by Azi Crawford 2011:07:25:13:26 -rev tlg 6/6/12

This program moves forward while sensing left & right bumpers; a hit causes

the robot to back away. It assumes left motor =2 and right motor =0.**********

It readjusts when one of the bumper/sensors (on ports 8 & 13) are triggered **/

int main()

{

int r_bumper=digital(8);

int l_bumper=digital(13);  

while(!black_button()) // bumper testing loop with appropriate motor commands

       { motor(0,75);  // keep motors moving forward if  no bumper

          motor(2,75);

          r_bumper=digital(8); //update sensor

          l_bumper=digital(13); //same as above  

          if(r_bumper==1)  

                { //back & shift to the left  

                  mrp(0,750,-1100);off(2);//stop left, reverse right motor

                  bmd(0);  

                  mrp(2,750,-1100); bmd(2); //wait for each motor to finish   

               }  

          else if(l_bumper==1)  

               { //back & shift to the right

                  mrp(2,750,-1100); off(0);//stop right, reverse left motor

                  bmd(2);

                  mrp(0,750,-1100); bmd(0); //wait for each motor

                }

          }

}

Please note that this is NOT a universal way to navigate, but robot will go forward while avoiding an obstacle.  [If your robot approaches wall, however, it doesn’t provide an efficient way around the wall.]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s