Chapter 8: Robot Control with Distance Detection · Page 283
Get_Ir_Distances:
distanceLeft = 0
distanceRight = 0
FOR freqSelect = 0 TO 4
LOOKUP freqSelect,[37500,38250,39500,40500,41500], irFrequency
FREQOUT 8,1,irFrequency
irDetectLeft = IN9
distanceLeft = distanceLeft + irDetectLeft
FREQOUT 2,1,irFrequency
irDetectRight = IN0
distanceRight = distanceRight + irDetectRight
NEXT
RETURN
' -----[ Subroutine – Get Pulse ]---------------------------------------------
Send_Pulse:
PULSOUT 13,pulseLeft
PULSOUT 12,pulseRight
PAUSE 5
RETURN
How the FollowingBoeBot.bs2 Works
FollowingBoeBot.bs2 declares four constants,
Kpr, Kpl, SetPoint, and CenterPulse
using the
CON directive. Everywhere you see SetPoint, it’s actually the number 2 (a
constant). Likewise, everywhere you see either
Kpl, it’s actually the number -35. Kpr is
actually 35, and
CenterPulse is 750.
Kpl CON -35
Kpr CON 35
SetPoint CON 2
CenterPulse CON 750
The first thing the main routine does is call the Get_Ir_Distances subroutine. After the
Get_Ir_Distances subroutine is finished, distanceLeft and distanceRight each
contain a number corresponding to the zone in which an object was detected for both the
left and right IR pairs.
DO
GOSUB Get_Ir_Distances