Shop OBEX P1 Docs P2 Docs Learn Events
Can someone help me! Boebot (photoresistor+IR Sensor) — Parallax Forums

Can someone help me! Boebot (photoresistor+IR Sensor)

DuhitptDuhitpt Posts: 1
edited 2012-05-04 08:33 in BASIC Stamp
Im currently stuck on this project, So far i got the Photoresistor to avoid black line using deadband. But I cant seem to work the IR sensor to avoiding object. can someone help me please. My project is similar to this video, so far i got through the first two maze, but last one doesnt work http://www.youtube.com/watch?v=i8gghvQbs-g&feature=relmfu



' {$Stamp bs2} ' Stamp Directive.
'
Declarations
irDetectLeft VAR Bit
irDetectRight VAR Bit
left_photo VAR Bit
right_photo VAR Bit
pulseCount VAR Byte
counter VAR Nib

'
Initialization
OUTPUT 2 ' Set P2 to output.
FREQOUT 2,4 2000, 3000 ' Program start/restart signal.
LOW 12 ' Set P12 and 13 to output-low.
LOW 13


'
Main Routine
Do

FREQOUT 7, 1, 45500
irDetectLeft = IN8

FREQOUT 1, 1, 45500
irDetectRight = IN0


' Measure RC time for right photoresistor.
HIGH 3 ' Set P3 to output-high.
PAUSE 3 ' Pause for 3 ms.
RCTIME 3,1,right_photo ' Measure RC time on P3.


' Measure RC time for left photoresistor.
HIGH 5 ' Set P5 to output-high.
PAUSE 3 ' Pause for 3 ms.
RCTIME 5,1,left_photo ' Measure RC time on P5.
' Check if difference between RC times is within the deadband, 2 in this case.
' If yes, then forward. If no then skip to check_dir subroutine.


IF ABS(left_photo-right_photo) > 2 THEN check_dir
forward_pulse:
PULSOUT 12, 1000
PULSOUT 13, 500
PAUSE 20
NEXT

IF (irDetectLeft = 0) AND (irDetectRight = 0)THEN
GOSUB Back_Up ' Both IR pairs detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left

ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detect
GOSUB BACK_UP ' Back up & turn right
GOSUB Turn_Right

ELSEIF (irDetectRight = 0) THEN ' Right IR pair detect
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both IR pairs 1, no detects
GOSUB Forward_Pulse ' Apply a forwards pulse
ENDIF ' and check again
LOOP



check_dir:
IF left_photo > right_photo THEN right_pulse
IF left_photo < right_photo THEN left_pulse






'
Subroutines


left_pulse: ' Photoresistor
PULSOUT 12, 500
PULSOUT 13, 500
PAUSE 20
NEXT
RETURN


right_pulse: 'Photoresistor
PULSOUT 12, 1000
PULSOUT 13, 1000
PAUSE 20
NEXT
RETURN




Forward_Pulse: ' IR Forward
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN

Turn_Left:
FOR pulseCount = 0 TO 20 ' IR Left turn
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN

Turn_Right:
FOR pulseCount = 0 TO 20 'IR Right turn
PULSOUT 13, 850
PULSOUT 12, 850

PAUSE 20
NEXT
RETURN

Back_Up:
FOR pulseCount = 0 TO 40 ' IR Back up.
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-05-04 08:33
    Please wrap your code in [code] tags to make it more readable.
Sign In or Register to comment.