Shop OBEX P1 Docs P2 Docs Learn Events
Please Help: Stripe Following with Infared Lights — Parallax Forums

Please Help: Stripe Following with Infared Lights

Bobby12345Bobby12345 Posts: 2
edited 2008-06-06 00:27 in Learn with BlocklyProp
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!!

Comments

  • accidentprone8accidentprone8 Posts: 7
    edited 2008-06-04 23:28
    Im working on the same project, just a little more complicated. Im having problems with it to, so Ill be watching to see if you get an answer. If I get an answer, Ill be sure to tell you.
  • accidentprone8accidentprone8 Posts: 7
    edited 2008-06-04 23:29
    Also, if you are using the ir for navigation as well, dont, because it will never work. A kid in my class who worked with programing stuff all last year couldnt get that to work. My advice? Use the whiskers. Much simpler.
  • Bobby12345Bobby12345 Posts: 2
    edited 2008-06-06 00:27
    i used the following stripe one and it's working properly i just need to know how to make it to come closer if its in zone 4 n move away if its closer than zone 2...
Sign In or Register to comment.