PDA

View Full Version : Modifying Boe Bot robotics code



ltmhall
01-12-2007, 09:04 PM
If I wanted to add object avoidance or object detection using bumper switches or infrared how would I do it.
Where would I put that code. I want my robot to move towards a light, at the same time be able to
detect or avoid objetcs in it's path.

Note: This comes from the Robotics with Boe Bot manual

-----[ Title ]--------------------------------------------------------------
' Robotics with the Boe-Bot - FlashlightControlledBoeBot.bs2 Boe-Bot follows flashlight beam focused in front of it.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
' -----[ Constants ]----------------------------------------------------------
LeftAmbient CON 108
RightAmbient CON 114
LeftBright CON 20
RightBright CON 22
' Average Scale factor
LeftThreshold CON LeftBright + LeftAmbient / 2 * 5 / 8
RightThreshold CON RightBright + RightAmbient / 2 * 5 / 8
' -----[ Variables ]----------------------------------------------------------
' Declare variables for storing measured RC times of the
' left & right photoresistors.
timeLeft VAR Word
timeRight VAR Word
' -----[ Initialization ]-----------------------------------------------------
FREQOUT 4, 2000, 3000
' -----[ Main Routine ]-------------------------------------------------------
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
' -----[ Subroutine - Test_Photoresistors ]-----------------------------------
Test_Photoresistors:
HIGH 6 ' Left RC time measurement.
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3 ' Right RC time measurement.
PAUSE 3
RCTIME 3,1,timeRight
RETURN
' -----[ Subroutine - Navigate ]----------------------------------------------
Navigate:
IF (timeLeft < LeftThreshold) AND (timeRight < RightThreshold) THEN
PULSOUT 13, 850 ' Both detect flashlight beam,
PULSOUT 12, 650 ' full speed forward.
ELSEIF (timeLeft < LeftThreshold) THEN ' Left detects flashlight beam,
PULSOUT 13, 700 ' pivot left.
PULSOUT 12, 700
ELSEIF (timeRight < RightThreshold) THEN ' Right detects flashlight beam,
PULSOUT 13, 800 ' pivot right.
PULSOUT 12, 800
ELSE
PULSOUT 13, 750 ' No flashlight beam, sit still.
PULSOUT 12, 750
ENDIF
PAUSE 20 ' Pause between pulses.
RETURN



Post Edited (ltmhall) : 1/12/2007 3:15:59 PM GMT

Franklin
01-13-2007, 04:22 AM
In the main routine create another entry like GOSUB Test_Bumpers and have another subroutine check for a bumper event. There is code in the manual for bumpers.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen