Need help on the old Boe-Bot IR Roaming Code
Lifedrive
Posts: 8
Hi,
I'm using Bs2p24, my boe-bot able to roam but the response/reaction is very slow with the left & right IR pairs. Once it detects an object, it takes about 2 seconds to react.
I did a test on the DEBUG, it seems to work properly as it changes state almost immediate.
Can anyone help me? Thank you.
Here's the code I'm using:
'
[ Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR object detectors.
' {$STAMP BS2p} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[ Variables ]
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
'
[ Initialization ]
FREQOUT 9, 5000, 300 ' display start delay
'
[ Main Routine ]
DO
FREQOUT 7, 1, 38500 ' Store IR detection values in
irDetectLeft = IN6 ' bit variables.
FREQOUT 5, 1, 38500
irDetectRight = IN4
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' None detect
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[ Subroutines ]
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 14,2125
PULSOUT 13,1625
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 1625
PULSOUT 14, 1625
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 2125
PULSOUT 14, 2125
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 1625
PULSOUT 14, 2125
PAUSE 20
NEXT
RETURN
I'm using Bs2p24, my boe-bot able to roam but the response/reaction is very slow with the left & right IR pairs. Once it detects an object, it takes about 2 seconds to react.
I did a test on the DEBUG, it seems to work properly as it changes state almost immediate.
Can anyone help me? Thank you.
Here's the code I'm using:
'
[ Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR object detectors.
' {$STAMP BS2p} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[ Variables ]
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
'
[ Initialization ]
FREQOUT 9, 5000, 300 ' display start delay
'
[ Main Routine ]
DO
FREQOUT 7, 1, 38500 ' Store IR detection values in
irDetectLeft = IN6 ' bit variables.
FREQOUT 5, 1, 38500
irDetectRight = IN4
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' None detect
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[ Subroutines ]
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 14,2125
PULSOUT 13,1625
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 1625
PULSOUT 14, 1625
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 2125
PULSOUT 14, 2125
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 1625
PULSOUT 14, 2125
PAUSE 20
NEXT
RETURN
Comments
The FREQOUT Duration and Freq1 arguments would also need to be adjusted for the IR emitters. We are going to try FREQOUT pin, 4, 7171 on a BS2p Boe-Bot and will let you know what happens.
Hi, Thank for replying. I did try out as suggested with FREQOUT pin, 4, 7171 , it doesn't work. However now the boe-bot response in time with the IR detection. What I did is, I removed the "Back_Up" subroutine. Now I need another help on figuring out why this subroutine either caused the problem and also it doesn't work. I'm not sure what is wrong with it. Please help me with this as this "Back_Up" subroutine is much needed.
Thank you.
This is what I did:
'
[ Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR object detectors.
' {$STAMP BS2p} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
'
[ Variables ]
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte
'
[ Initialization ]
FREQOUT 9, 5000, 300 ' display start delay
'
[ Main Routine ]
DO
FREQOUT 7, 1, 38500 ' Store IR detection values in
irDetectLeft = IN6 ' bit variables.
FREQOUT 5, 1, 38500
irDetectRight = IN4
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both detect obstacle <--- I REMOVED THIS
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left detects
GOSUB Back_Up ' Back up & turn right <--- I REMOVED THIS
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right detects
GOSUB Back_Up ' Back up & turn left <--- I REMOVED THIS
GOSUB Turn_Left
ELSE ' None detect
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
'
[ Subroutines ]
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 14,2125
PULSOUT 13,1625
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 1625
PULSOUT 14, 1625
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 2125
PULSOUT 14, 2125
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up. <--- I REMOVED THIS
FOR pulseCount = 0 TO 40 <--- I REMOVED THIS
PULSOUT 13, 1625 <--- I REMOVED THIS
PULSOUT 14, 2125 <--- I REMOVED THIS
PAUSE 20 <--- I REMOVED THIS
NEXT <--- I REMOVED THIS
RETURN <--- I REMOVED THIS
I tried your code using Freq1 at 38500 and it did work (I am not sure why!)
I tried your code, keeping 38500 as the Freq1 argument. The only thing I changed was the pin assignments to match the original circuit in Robotics with the Boe-Bot, since that is how I have my Boe-Bot built: IR LEDs on 8 and 2, IR receivers on 9 and 0, and servos on 13 and 12.
Everything worked as expected. So I'm not sure what the issue is? Here is my code:
Look at the order of your PULSOUT commands to the servos.
For Forward you have Pin 14 first but for all the other directions you have Pin 13 first.
If you put the Forward and Back_Up PULSOUTs with the same pin first then you would notice that you are sending the same values to each pin.
Swap the servo pulse values in Back_Up and then it will go in the same direction.
Notice that in Steph's program she always uses Pin 13 first.
Hi Genetix, thanks for pointing that out to me. I had rearranged that 14 & 13 to the Pulsout, but it doesn't help with the problem.
Do you have a piezo on Pin 9?
When you hear a beep, that usually means the board reset due to low battery voltage.
Try a fresh set of batteries and try it.
Thanks everyone, problem solved . : )
In a related story, just last Friday I submitted an article to SERVO magazine on (drumroll please)... SERVOS! Here is one poignant except:
Perhaps the most common "noob" problems discussed in Parallax's very helpful Robotics forum stem from weak alkaline batteries. Things appear to function properly until the servos move, drawing an amp or more, causing old batteries' voltage to drop and reset the microcontroller. New alkaline batteries almost always solve the problem. Oh, how people hate to admit that weak batteries were the only problem.
We've all been there, Pal. Now you're a real roboticist!
Not to create a spam, just a thought of sharing some of my Boe-bot short videos/pics even though not that much, to those interested can see it at my Instagram account: @grafiks_
Again thanks to everyone for the help.