Datasheet

Page 152· Applied Robotics with the SumoBot
Example Program: ServoControlWithLookup.bs2
Enter and save ServoControlWithLookup.bs2
Move the 3-position switch on the SumoBot circuit board to position 1.
Download the program to the SumoBot.
Hold down the Reset button on the SumoBot circuit board, then move the 3-
position switch from 1 to 2.
Place the SumoBot on the practice ring, let go of the Reset button, and watch it
navigate. It should move forward around 10 inches (25 cm), then rotate left
almost 90°, then rotate right almost 180°, then rotate left almost 90° to return to
the direction it was first facing. It should then continue forward and repeat the
“look left, look right” jog after another 10 inches.
The usefulness of the Reset subroutine. It sure was easier to just tap that Reset button to
make the SumoBot stop and wait wasn’t it? All you have to do is copy and paste a few
sections from TestResetButton.bs2 from Chapter 2, Activity #3 into this example program,
and you'll have that functionality again.
Calibration: Your servos may perform differently, so you many need to adjust the
FOR...NEXT loops' EndValue arguments to get your SumoBot to perform the search
pattern the way it was just described.
' -----[ Title ]--------------------------------------------------------------
' Applied Robotics with the SumoBot - ServoControlWithLookup.bs2
' {$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
' -----[ Constants ]----------------------------------------------------------
' SumoBot maneuver constants
Forward CON 0 ' Forward
Backward CON 1 ' Backward
RotateLeft CON 2 ' Rotate in place turning left
RotateRight CON 3 ' Rotate in place turning right
' Servo pulse width rotation constants
FS_CCW CON 850 ' Full speed counterclockwise
FS_CW CON 650 ' Full speed clockwise