Sumobot IR
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
Thanks
Comments
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
' 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
Thanks,
GLP
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
Did you try to download the program again and run it?
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
GLP