Shop OBEX P1 Docs P2 Docs Learn Events
IR Sensors — Parallax Forums

IR Sensors

ltmhallltmhall Posts: 102
edited 2007-01-24 02:15 in BASIC Stamp
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.

Comments

  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-01-22 17:37
    Sharp makes a variety of IR Sensors, but could you elaborate as to what type of problem you are having?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-01-22 17:48
    Make sure that the sensor receives no light directly from the IRED. This will almost certainly involve shielding the IRED with either black shrink tubing or putting it in an LED holder with a snap-on bezel. Then put the business end of the IRED forward of the sensor. This is necessary because IREDs leak light out the rear, and sensors do not completely block light coming in from the rear (unless they have a metal shield arount them, as some do).

    -Phil
  • ltmhallltmhall Posts: 102
    edited 2007-01-22 19:22
    When both pair sense an object it seems to reverse in a jerking fashion. When I place my hand right in front of both senors it backs up okay. However when I place my hand in front of both sensors from further away my robot starts jerking. The right and left sensor seem to work okay independently from each other. Initially I tried RoamingWithIr.bs2 and it worked perfect.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-22 19:47
    If RoamingWithIR.bs2 worked perfectly, then it's definitely not a hardware problem.

    Would you like to post your code as an attachment?
  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-01-22 19:53
    Looks like this is already being addressed in http://forums.parallax.com/showthread.php?p=626241...

    No double postings please!
  • ltmhallltmhall Posts: 102
    edited 2007-01-22 19:55
    This is my code


    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-22 20:21
    I think the reason your robot is jerking is you are only allowing a SINGLE move per measurement. Your robot doesn't move very much in 20 mSec.

    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.
  • ltmhallltmhall Posts: 102
    edited 2007-01-22 23:19
    I tried creating a small loop for the PULSOUT but it still reacts the same way.


    * 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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-23 14:01
    That's not a loop, that's a subroutine CALL.

    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.
  • ltmhallltmhall Posts: 102
    edited 2007-01-23 14:06
    So it would just be

    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
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-23 14:13
    Yup, that should do it.
  • ltmhallltmhall Posts: 102
    edited 2007-01-23 14:15
    Right now i'm at work and when I get home I'll give it a try and let you know if it works.



    THANKS

    Post Edited (ltmhall) : 1/23/2007 2:19:21 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-24 02:15
    Yeah, you probably need a

    I VAR BYTE

    declaration in there somewhere.
Sign In or Register to comment.