Please Help: Stripe Following with Infared Lights
Bobby12345
Posts: 2
Hello so i been working on a boe-bot project which has infared lights and the purpose of my project it was for it to follow the stripe avoid objects and finnaly park itself. Im having a lot of difficulties because my boe-bot takes the strip as an object and moves back. It would be really helpful if you are able to fix it and give finish the coding i really do not know how to park ethier please and thank you. Here is the sample code:
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[noparse][[/noparse] Constants ]
Kpl CON 35
Kpr CON -35
SetPoint CON 3
CenterPulse CON 750
'
[noparse][[/noparse] Variables ]
freqSelect VAR Nib
irFrequency VAR Word
irDetectLeft VAR Bit
irDetectRight VAR Bit
distanceLeft VAR Nib
distanceRight VAR Nib
pulseLeft VAR Word
pulseRight VAR Word
pulseCount VAR Byte
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
'
[noparse][[/noparse] Main Routine ]
DO
GOSUB Get_Ir_Distances
' Calculate proportional output.
pulseLeft = SetPoint - distanceLeft * Kpl + CenterPulse
pulseRight = SetPoint - distanceRight * Kpr + CenterPulse
GOSUB Send_Pulse
LOOP
'
[noparse][[/noparse] Subroutine - Better Roaming ]
DO
FREQOUT 8, 1, 38500 'Store IR detection values in
irDetectLeft = IN9 'bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (irDetectLeft=0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Foward_Pulse
ENDIF
LOOP
Foward_Pulse:
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount= 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
BACK_UP:
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
'
[noparse][[/noparse] Subroutine - Get IR Distances ]
Get_Ir_Distances:
distanceLeft = 0
distanceRight = 0
FOR freqSelect = 0 TO 4
LOOKUP freqSelect, [noparse][[/noparse]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
'
[noparse][[/noparse] Subroutine - Get Pulse ]
Send_Pulse:
PULSOUT 13,pulseRight
PULSOUT 12,pulseLeft
PAUSE 5
RETURN
Thank You!!
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[noparse][[/noparse] Constants ]
Kpl CON 35
Kpr CON -35
SetPoint CON 3
CenterPulse CON 750
'
[noparse][[/noparse] Variables ]
freqSelect VAR Nib
irFrequency VAR Word
irDetectLeft VAR Bit
irDetectRight VAR Bit
distanceLeft VAR Nib
distanceRight VAR Nib
pulseLeft VAR Word
pulseRight VAR Word
pulseCount VAR Byte
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
'
[noparse][[/noparse] Main Routine ]
DO
GOSUB Get_Ir_Distances
' Calculate proportional output.
pulseLeft = SetPoint - distanceLeft * Kpl + CenterPulse
pulseRight = SetPoint - distanceRight * Kpr + CenterPulse
GOSUB Send_Pulse
LOOP
'
[noparse][[/noparse] Subroutine - Better Roaming ]
DO
FREQOUT 8, 1, 38500 'Store IR detection values in
irDetectLeft = IN9 'bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (irDetectLeft=0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Foward_Pulse
ENDIF
LOOP
Foward_Pulse:
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN
Turn_Left:
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount= 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
BACK_UP:
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
'
[noparse][[/noparse] Subroutine - Get IR Distances ]
Get_Ir_Distances:
distanceLeft = 0
distanceRight = 0
FOR freqSelect = 0 TO 4
LOOKUP freqSelect, [noparse][[/noparse]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
'
[noparse][[/noparse] Subroutine - Get Pulse ]
Send_Pulse:
PULSOUT 13,pulseRight
PULSOUT 12,pulseLeft
PAUSE 5
RETURN
Thank You!!
Comments