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

Sumobot IR

GLPGLP Posts: 9
edited 2011-03-10 12:22 in Robotics
Hi, i'm new to robototics and im building a sumobot for a class project. I seem to be having problems with getting the IR sensors to scan. When i run the test program 4.2 IR scan it will continuously switch back and forth from "follow right" to "scan right" at a rapid rate in the debug terminal. I have adjusted the frequency several different times and have had the same results. I have also changed the entire right IR pair and have had the same results. Any help would be greatly appreciated.

Thanks

Comments

  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2011-02-25 10:38
    Hi GLP,

    Could you post the code you're running as an attachment? There are a couple of things that could be happening, but checking the code is a good first step.

    Thanks,
    Jessica
  • GLPGLP Posts: 9
    edited 2011-02-25 11:31
    This is the IR-scan code i am using from the parallax website


    ' SumoBot-4.2-IR-Scan.BS2
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [ I/O Definitions ]
    LMotor PIN 13 ' left servo motor
    RMotor PIN 12 ' right servo motor
    LfIrOut PIN 4 ' left IR LED output
    LfIrIn PIN 11 ' left IR sensor input
    RtIrOut PIN 15 ' right IR LED output
    RtIrIn PIN 14 ' right IR sensor input
    '
    [ Constants ]
    LFwdFast CON 1000 ' left motor fwd; fast
    LFwdSlow CON 800 ' left motor fwd; slow
    LStop CON 750 ' left motor stop
    LRevSlow CON 700 ' left motor rev; slow
    LRevFast CON 500 ' left motor rev; fast
    RFwdFast CON 500 ' right motor fwd; fast
    RFwdSlow CON 700 ' right motor fwd; slow
    RStop CON 750 ' right motor stop
    RRevSlow CON 800 ' right motor rev; slow
    RRevFast CON 1000 ' right motor rev; fast
    '
    [ Variables ]
    irBits VAR Nib ' storage for IR target data
    irLeft VAR irBits.BIT1
    irRight VAR irBits.BIT0
    lastIr VAR Nib ' info from last reading
    pulses VAR Byte ' counter for motor control
    '
    [ Initialization ]
    Reset:
    LOW LMotor ' initialize motor outputs
    LOW RMotor
    '
    [ Program Code ]
    Main:
    GOSUB Read_IR_Sensors
    BRANCH irBits, [Scan, Follow_Right, Follow_Left, Hold]
    Scan:
    BRANCH lastIR, [Move_Fwd, Scan_Right, Scan_Left, Move_Fwd]
    Move_Fwd:
    DEBUG HOME, "Forward", CLREOL
    GOTO Main
    Scan_Right: ' spin right, slow
    DEBUG HOME, "Scan Right", CLREOL
    PULSOUT LMotor, LFwdSlow
    PULSOUT RMotor, RRevSlow
    PAUSE 20
    GOTO Main
    Scan_Left: ' spin left, slow
    DEBUG HOME, "Scan Left", CLREOL
    PULSOUT LMotor, LRevSlow
    PULSOUT RMotor, RFwdSlow
    PAUSE 20
    GOTO Main
    Follow_Right: ' spin right, fast
    DEBUG HOME, "Follow Right", CLREOL
    PULSOUT LMotor, LFwdFast
    PULSOUT RMotor, RRevFast
    PAUSE 20
    lastIr = irBits ' save last direction found
    GOTO Main
    Follow_Left: ' spin left, fast
    DEBUG HOME, "Follow Left", CLREOL
    PULSOUT LMotor, LRevFast
    PULSOUT RMotor, RFwdFast
    PAUSE 20
    lastIr = irBits
    GOTO Main
    Hold: ' on target
    DEBUG HOME, "On Target", CLREOL
    FOR pulses = 1 TO 3
    PULSOUT LMotor, LStop
    PULSOUT RMotor, RStop
    PAUSE 20
    NEXT
    lastIr = %00
    GOTO Main
    END
    '
    [ Subroutines ]
    Read_IR_Sensors:
    FREQOUT LfIrOut, 1, 38500 ' modulate left IR LED
    irLeft = ~LfIrIn ' read input (1 = target)
    FREQOUT RtIrOut, 1, 38500 ' modulate right IR LED
    irRight = ~RtIrIn ' read input (1 = target)
    RETURN
  • GLPGLP Posts: 9
    edited 2011-02-25 12:23
    Sorry, i just saw that you wanted the program as an attachment

    Thanks,
    GLP
  • bee_manbee_man Posts: 109
    edited 2011-02-25 14:24
    Did you download this code or type it in yourself?
  • GLPGLP Posts: 9
    edited 2011-02-25 19:33
    I downloaded the code directly from the parallax website.
  • bee_manbee_man Posts: 109
    edited 2011-02-26 12:14
    The code should not be the problem then, it works on my Sumobot. I would try to light a LED thru a resistor with the port pins to make sure a pin is not dead. Those pin sockets are also big, are you sure the components are making good contact.
  • GLPGLP Posts: 9
    edited 2011-02-26 20:39
    bee_man,

    I am not certain to which pins you are referring to, but if you are talking about the IR pins i am sure they are working because i have adjusted the frequency for both the left and right side using the test program 4.1 and both sides respond to adjustments. I currently have a LED ran through a 220 ohm resistor to P0 . I also have a piezo speaker ran parallel to the LED into P1, and they both function properly (if that is the pins you are referring to). Thanks again for all the replys
  • bee_manbee_man Posts: 109
    edited 2011-02-27 06:26
    I am refering to the IR pins P11, P4, P14, and P15. plug the resistor into each pin run the LED test program after changing the output pin number to the pin you want to test. If it is not a software problem, it must be a hardware problem, if it is not a component problem (you did change components correct), then it must be a CPU problem.

    Did you try to download the program again and run it?
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2011-02-28 10:19
    Hi GLP,

    To be clear, you've run program 4.1, and both sensors respond normally, correct?

    The first thing I would check is the polarity of the IR LED, it sounds simple, but it's a very common mistake, particularly if you've trimmed the LED leads. If you have trimmed the leads, take a look at the LED, and you'll see a flat spot. This denotes the cathode and should be connected to Vss.

    Also, there are some things that can interfere with the IR signaling, such as fluorescent lights. Attached is a program, IrInterferenceSniffer.bs2, from Robotics with the Boe-Bot which checks for IR interference. It's modified to work with the SumoBot, and if you run this program and get a response, you'll know if outside conditions are affecting your readings.

    Let us know how it goes.

    Cheers,
    Jessica
  • GLPGLP Posts: 9
    edited 2011-03-10 12:22
    Sorry for the prolonged reply everyone. I did find my error however, it was a simple novice mistake. I had calibrated the sensors frequency using 4.1, but when i ran program 4.2 i did not pay close attention to the subroutine and it was running the standard frequency value of 38500 i believe it is. Once i adjusted the frequencies in the subroutine of 4.2 to the values that i had in program 4.1, I began to get a better scan and follow response. Thank you for everyone that replied and all the input


    GLP
Sign In or Register to comment.