Shop OBEX P1 Docs P2 Docs Learn Events
Modifying Boe Bot robotics code — Parallax Forums

Modifying Boe Bot robotics code

ltmhallltmhall Posts: 102
edited 2007-01-12 20:22 in BASIC Stamp

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


[noparse][[/noparse] 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!"
'
[noparse][[/noparse] 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
'
[noparse][[/noparse] Variables ]

' Declare variables for storing measured RC times of the
' left & right photoresistors.
timeLeft VAR Word
timeRight VAR Word
'
[noparse][[/noparse] Initialization ]

FREQOUT 4, 2000, 3000
'
[noparse][[/noparse] Main Routine ]

DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
'
[noparse][[/noparse] 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
'
[noparse][[/noparse] 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

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-01-12 20:22
    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
Sign In or Register to comment.