Shop OBEX P1 Docs P2 Docs Learn Events
Need help on the old Boe-Bot IR Roaming Code — Parallax Forums

Need help on the old Boe-Bot IR Roaming Code

LifedriveLifedrive Posts: 8
edited 2015-05-12 18:28 in BASIC Stamp
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

Comments

  • Steph LindsaySteph Lindsay Posts: 767
    edited 2015-05-08 11:23
    I see you have adjusted your PULSOUT arguments to take into account the timing differences between the BS2 and BS2p.

    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.
  • LifedriveLifedrive Posts: 8
    edited 2015-05-08 12:52
    I see you have adjusted your PULSOUT arguments to take into account the timing differences between the BS2 and BS2p.

    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
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2015-05-08 13:28
    Hi again,

    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:
     ' -----[ 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 4, 5000, 300 ' display start delay
    
    ' -----[ Main Routine ]-------------------------------------------------------
    DO
      FREQOUT 8, 1, 38500 ' Store IR detection values in
      irDetectLeft = IN9 ' bit variables.
      FREQOUT 2, 1, 38500
      irDetectRight = IN0
      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 13,2125
      PULSOUT 12,1625
      PAUSE 20
      RETURN
    
    Turn_Left: ' Left turn, about 90-degrees.
      FOR pulseCount = 0 TO 20
      PULSOUT 13, 1625
      PULSOUT 12, 1625
      PAUSE 20
      NEXT
      RETURN
    
    Turn_Right:
      FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
      PULSOUT 13, 2125
      PULSOUT 12, 2125
      PAUSE 20
      NEXT
      RETURN
    
    Back_Up: ' Back up.
      FOR pulseCount = 0 TO 40
      PULSOUT 13, 1625
      PULSOUT 12, 2125
      PAUSE 20
      NEXT
      RETURN
    
    
  • GenetixGenetix Posts: 1,754
    edited 2015-05-08 22:08
    Lifedrive,

    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.
  • LifedriveLifedrive Posts: 8
    edited 2015-05-09 10:59
    Hi Steph, Thanks, I tried the code that u gave and change the IR LEDs to 7 and 5, IR receivers on 6 and 4, and servos on 14 and 13 for my boe-bot built. The problem still there unless I removed the Back_Up subroutine then everything work as expected. Still try to figure out why that subroutine caused the boe-bot to stalled and beep when being triggered.

    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.
  • PublisonPublison Posts: 12,366
    edited 2015-05-09 11:25
    Lifedrive wrote: »
    Hi Steph, Thanks, I tried the code that u gave and change the IR LEDs to 7 and 5, IR receivers on 6 and 4, and servos on 14 and 13 for my boe-bot built. The problem still there unless I removed the Back_Up subroutine then everything work as expected. Still try to figure out why that subroutine caused the boe-bot to stalled and beep when being triggered.

    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.
  • LifedriveLifedrive Posts: 8
    edited 2015-05-10 19:02
    Hi Steph, Genetix & Publison... Thanks for your great help. As Publison pointed to me about the battery issue, I went to nearby store and get myself a fresh pack of batteries. Everything work as expected. Meaning my so-called new batteries that still in the unopened package that I used is having low capacity.

    Thanks everyone, problem solved . : )
  • ercoerco Posts: 20,257
    edited 2015-05-12 18:28
    Hey Lifedrive: Welcome to the forums, glad to hear that you got your problem sorted out.

    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! :)
  • MarkCrCoMarkCrCo Posts: 89
    edited 2015-07-02 04:04
    Rechargeable batteries work much better than standard alkaline batteries. Don't forget to adjust for the voltage differences. (4 X 1.5 Alkaline AA Batteries = 5 X 1.2 Rechargeable AA Batteries) If you really need constant power and your project is stationary a DC power supply is the way to go but don't reverse the leads or you fry your stamp ... The voice of experience.

  • Thanks Erco & MarkCrCo for all the explanations. I was blinded by the "newly unopened battery" that I used. I had never thought this might lead to the robot behaving weird or not working. Yes, everyone should be aware that bad batteries will cause unexpected problem. To those who doesn't believe this, now is the time that they have to reconsider about this issue. For me I will execute anyone suggestion to solve my problem. That's the reason I post to ask for help.

    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.
Sign In or Register to comment.