Datasheet

Page 166· Applied Robotics with the SumoBot
Example Program: FrontAndSideIrNavigation.bs2
The beauty in terminating the rotate loop as soon as one of the front IR detectors sees the
object is that one of the other code blocks will then take over to get the SumoBot to face
its opponent. Let's see how it performs:
Save FrontIrNavigiation.bs2 as FrontAndSideIrNavigation.bs2
Insert the peripheral vision
ELSEIF...THEN... code blocks shown above just
before the
ELSE keyword in the Main Routine.
Use the printed example program to check your work.
Run the program.
Press and hold the Reset button as you take the SumoBot to the practice ring.
Make sure there all objects are well away from the SumoBot's front and side. If
there are objects near the ring, consider using an
IrFreq CON directive that
makes the SumoBot nearsighted.
Set the SumoBot on the practice ring so that you are behind it. Otherwise, it will
see you and react immediately. Make sure that there are no other objects within
a couple meters of the ring.
Let go of the Reset button. The SumoBot should stay still because it doesn't see
anything.
Place your hand in view of its right IR object detector. The SumoBot should
immediately turn to face your hand and then lunge forward.
Press and hold the Reset button, and again place the SumoBot so that it can't see
you.
Place your hand in view of its left IR object detector and verify that it rounds on
an object to its left as well.
' -----[ Title ]--------------------------------------------------------------
' Applied Robotics with the SumoBot - FrontAndSideIrNavigation.bs2
' This is FrontIrNavigation.bs2 with peripheral IR object detection added.
' {$STAMP BS2} ' Target = BASIC Stamp 2
' {$PBASIC 2.5} ' Language = PBASIC 2.5
' -----[ I/O Definitions ]---------------------------------------------------
ServoLeft PIN 13 ' Left servo connected to P13
ServoRight PIN 12 ' Right servo connected to P12
IrLedLS PIN 2 ' Left IR LED connected to P2
IrSenseLS PIN 1 ' Left IR detector to P1