IR Sensors
ltmhall
Posts: 102
I'm having a problem getting my IR emitter/led pair to run the fastIRroaming program on
a robot i'm building using the basic stamp II and wanted to know what other IR sensors
are out there I can use for· collision avoidance.
a robot i'm building using the basic stamp II and wanted to know what other IR sensors
are out there I can use for· collision avoidance.
Comments
-Phil
Would you like to post your code as an attachment?
No double postings please!
Robotics with the Boe-Bot - FastIrRoaming.bs2
' Higher performance IR object detection assisted navigation
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable Declarations
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine
FREQOUT 3, 1, 38500 ' Check IR Detectors
irDetectLeft = IN2
FREQOUT 1, 1, 38500
irDetectRight = IN0
' Decide how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
HIGH 4
HIGH 5
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
HIGH 5
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
HIGH 4
pulseLeft = 650
pulseRight = 650
ELSE
LOW 4
LOW 5
pulseLeft = 850
pulseRight = 650
ENDIF
PULSOUT 15,pulseLeft ' Apply the pulse.
PULSOUT 14,pulseRight
PAUSE 15
LOOP
Thus, when detecting things at the edge of sensor detection, it backs a little, doesn't see it, moves forward a little, sees it, backs up a little, doesn't see it, etc. All at a 20 mSec delay, which is about 50 times a second. I'm not surprised it 'vibrates'.
Solution: Put your "PULSOUT" statements in a short loop -- do it 25 times. That will be 1/2 second of movement for each sense, which should allow some movement before the next sense statement.
* Program with PULSOUT loop
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable Declarations
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
DO
GOSUB IR_TEST
GOSUB PULSOUT_MOVE
LOOP
IR_TEST:
FREQOUT 3, 1, 38500 ' Check IR Detectors
irDetectLeft = IN2
FREQOUT 1, 1, 38500
irDetectRight = IN0
' Decide how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
HIGH 4
HIGH 5
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
HIGH 5
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
HIGH 4
pulseLeft = 650
pulseRight = 650
ELSE
LOW 4
LOW 5
pulseLeft = 850
pulseRight = 650
ENDIF
RETURN
PULSOUT_MOVE:
PULSOUT 15,pulseLeft ' Apply the pulse.
PULSOUT 14,pulseRight
PAUSE 15
RETURN
To loop it, you'd do:
FOR I = 1 to 25
GOSUB Pulsout_Move
NEXT
This way, you'd move for 500 mSec, before you tried sensing again. It's that Sense-move-sense-move repetition 50 times a second that's getting you.
DEBUG "Program Running!"
irDetectLeft VAR Bit ' Variable Declarations
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
DO
GOSUB IR_TEST
FOR I = 1 to 25
GOSUB Pulsout_Move
NEXT
LOOP
IR_TEST:
FREQOUT 3, 1, 38500 ' Check IR Detectors
irDetectLeft = IN2
FREQOUT 1, 1, 38500
irDetectRight = IN0
' Decide how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
HIGH 4
HIGH 5
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
HIGH 5
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
HIGH 4
pulseLeft = 650
pulseRight = 650
ELSE
LOW 4
LOW 5
pulseLeft = 850
pulseRight = 650
ENDIF
RETURN
PULSOUT_MOVE:
PULSOUT 15,pulseLeft ' Apply the pulse.
PULSOUT 14,pulseRight
PAUSE 15
RETURN
THANKS
Post Edited (ltmhall) : 1/23/2007 2:19:21 PM GMT
I VAR BYTE
declaration in there somewhere.