Shop OBEX P1 Docs P2 Docs Learn Events
Stuck on EepromNavigation program from Robotics with the BoeBot — Parallax Forums

Stuck on EepromNavigation program from Robotics with the BoeBot

Walt&AndyWalt&Andy Posts: 7
edited 2013-02-11 08:56 in Robotics
Alright, I'm stumped! When running this program (code to follow), the BoeBot makes a reasonably accurate 1st left turn and right turn. The 2nd left turn, though, measures closer to 60deg rather than the expected 90. This is particularly troubling since both left turns reference the same subroutine. What am I missing? Does it matter (can't see why it would) if the BoeBot goes into the turn from reverse instead of forward?

Code:
' ROBTOICS with the BO-BOT - EepromNavigation.bs2
' Navigate using characteristics stored in EEPROM
' {$STAMP BS2}
' {$PBASIC 2.5}

DEBUG "Program Running"

'
!Variables!
pulsecount VAR Word
address VAR Byte
instruction VAR Byte
'
!EEPROM Data!
' Address: 0123456789
' ||||||||||
DATA "FLFFRBLBBQ"
'
!Initialization!

FREQOUT 4,1000,3000

'
!Main Routine!

DO UNTIL (instruction = "Q")

READ address, instruction
address=address+1
SELECT instruction
CASE "F": GOSUB Forward
CASE "B": GOSUB Backward
CASE "L": GOSUB Left_Turn
CASE "R": GOSUB Right_Turn
ENDSELECT

LOOP
FREQOUT 4,1000,2500
END
'
!Subroutine Forward!
Forward:
FOR pulsecount=1TO 64
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
NEXT
RETURN
'
!Subroutine Backward!
Backward:
FOR pulsecount=1TO 64
PULSOUT 13,650
PULSOUT 12,850
PAUSE 20
NEXT
RETURN
'
!Subroutine Left__Turn!
Left_Turn:
FOR pulsecount=1TO 17
PULSOUT 13,650
PULSOUT 12,650
PAUSE 20
NEXT
RETURN
'
!Subroutine Right_Turn!
Right_Turn:
FOR pulsecount=1TO 18
PULSOUT 13,850
PULSOUT 12,850
PAUSE 20
NEXT
RETURN

Comments

  • ercoerco Posts: 20,256
    edited 2013-02-08 19:51
    Try coming to a complete stop between maneuvers to see if turn & distance consistency improves. I'm guessing momentum may be working for you sometimes and against you other times.
  • Walt&AndyWalt&Andy Posts: 7
    edited 2013-02-08 20:31
    Thanks, Erco!

    I had that same thought, so I did, by placing

    PULSOUT 13,750
    PULSOUT 12, 750
    PAUSE 20

    at the beginning of the DO/LOOP. Couldn't tell that it had any positive effect (though I was able to see the pauses, esp between f/f commands), so I took it out.
  • ercoerco Posts: 20,256
    edited 2013-02-08 21:09
    That's the right code to send, but you need to loop it multiple times to stop. Just sending it once has no effect. Try making a stop subroutine which is a for/next loop to send twenty pulsout 750s & pause 20s in a row between other maneuvers.
  • Walt&AndyWalt&Andy Posts: 7
    edited 2013-02-09 06:40
    Ah! Excellent! Thanks, I'll try that this afternoon.
  • ercoerco Posts: 20,256
    edited 2013-02-09 11:01
    Here's a quick fix:
    '--------------!Main Routine!-------------------
    
     DO UNTIL (instruction = "Q")
    
     READ address, instruction
     address=address+1
     SELECT instruction
     CASE "F": GOSUB Forward
     CASE "B": GOSUB Backward
     CASE "L": GOSUB Left_Turn
     CASE "R": GOSUB Right_Turn
     ENDSELECT
    
     
     FOR pulsecount=1 TO 50 ' stop for 1 second between all maneuvers
     PULSOUT 13,750
     PULSOUT 12,750
     PAUSE 20
     NEXT
    
     LOOP
     FREQOUT 4,1000,2500
     END
    
  • Walt&AndyWalt&Andy Posts: 7
    edited 2013-02-11 07:51
    Thanks, Erco! That did indeed fix the problem!
  • ercoerco Posts: 20,256
    edited 2013-02-11 08:56
    XLNT. Glad it helped and thanks for reporting back. Sometimes we never hear any follow up.

    BTW, it's noteworthy that there are at least two different ways to stop a servo. Sending a long stream of 750-uS pulses actually puts the brakes on to stop quickly. Alternatively, if you simply stop sending pulses to it and wait, it will coast to a stop more gently.
Sign In or Register to comment.