Shop OBEX P1 Docs P2 Docs Learn Events
Boe-Bot: Continuous forward until any key is pressed. — Parallax Forums

Boe-Bot: Continuous forward until any key is pressed.

edited 2011-09-15 18:01 in Robotics
Continuous Forward
When using the Parallax provided TerminalBoeBotControl_Keypad.bs2 file, I am attempting to modify the forward command (for instance) to make the Boe-Bot run forward continuously until any other key is pressed to stop the continuous forward movement. In other words, I am trying to implement a LOOP function, that, when ends, returns to the Main routine. I have attempted many methods as to using DO|WHILE LOOP, but have not been able to achieve the desired results. Below is the original code.

' TerminalBoeBotControl_Keypad.bs2
' Moves the Boe-Bot based on the numbers 2, 4, 6, 8 or the
' letters A, W, D, X.

' {$STAMP BS2}
' {$PBASIC 2.5}

RX PIN 2 ' RX of the Easy Bluetooth
TX PIN 0 ' TX of the Easy Bluetooth
ltServo PIN 13 ' Left Servo Pin
rtServo PIN 12 ' Right Servo Pin

FwdLtFast CON 850 ' Left servo forward full speed
BwdLtFast CON 650 ' Left servo backward full speed
FwdRtFast CON 650 ' Right servo forward full speed
BwdRtFast CON 850 ' Right servo backward full speed

Baud CON 84 ' Baud set at 9600

myByte VAR Byte ' Byte to establish connection
index VAR Word ' READ index/character storage
character VAR Word

dirChar VAR Word ' Stores directional character
counter VAR Word ' Counter for FOR...NEXT loop

DATA CLS,
" ", CR, ' 14
" ", CR, ' 28
" | ", CR, ' 42
" --o-- ", CR, ' 56
" | ", CR, ' 70
" ", CR, ' 84
" ", CR ' 98

PAUSE 250 ' Waits 1/4 second
SERIN RX, Baud, [myByte] ' Waiting for byte
myByte = 0 ' Clear the byte value

' Display background
FOR index = 0 TO 99
READ index, character
SEROUT TX, Baud, [character]
NEXT

' Let user know the program is running
SEROUT TX, BAUD, [CR, CR, "Program Running..."]

DO
' Recieve character from the PC
SERIN RX, Baud, [dirChar]

IF (dirChar = "8") OR (dirChar = "w") THEN
GOSUB Forward
ELSEIF (dirChar = "2") OR (dirChar = "x") THEN
GOSUB Backward
ELSEIF (dirChar = "4") OR (dirChar = "a") THEN
GOSUB Left
ELSEIF (dirChar = "6") OR (dirChar = "d") THEN
GOSUB Right
ENDIF
LOOP

Forward:
SEROUT TX, BAUD, [CRSRXY, 7, 0, "*", CRSRXY, 6, 1, "*", CRSRXY, 8, 1, "*"]
PULSOUT ltServo, FwdLtFast
PULSOUT rtServo, FwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 7, 0, " ", CRSRXY, 6, 1, " ", CRSRXY, 8, 1, " "]
RETURN

Backward:
SEROUT TX, BAUD, [CRSRXY, 7, 6, "*", CRSRXY, 6, 5, "*", CRSRXY, 8, 5, "*"]
PULSOUT ltServo, BwdLtFast
PULSOUT rtServo, BwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 7, 6, " ", CRSRXY, 6, 5, " ", CRSRXY, 8, 5, " "]
RETURN

Left:
SEROUT TX, BAUD, [CRSRXY, 3, 3, "*", CRSRXY, 4, 2, "*", CRSRXY, 4, 4, "*"]
PULSOUT ltServo, FwdRtFast
PULSOUT rtServo, FwdRtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 3, 3, " ", CRSRXY, 4, 2, " ", CRSRXY, 4, 4, " "]
RETURN

Right:
SEROUT TX, BAUD, [CRSRXY, 11, 3, "*", CRSRXY, 10, 2, "*", CRSRXY, 10, 4, "*"]
PULSOUT ltServo, FwdLtFast
PULSOUT rtServo, FwdLtFast
PAUSE 20
SEROUT TX, BAUD, [CRSRXY, 11, 3, " ", CRSRXY, 10, 2, " ", CRSRXY, 10, 4, " "]
RETURN

Comments

  • Matt GillilandMatt Gilliland Posts: 1,406
    edited 2011-09-08 20:29
    Hey complex _mentality - so is this your original code? Let's see if I can scare up our resident Boe-Bot expert -

    Andy? You around?
    -Matt
  • edited 2011-09-09 08:19
    Here is some code that does what you describe while the Boe-Bot is connected to the programming port. Press a key, and it executes a maneuver until another key is pressed for another maneuver. Like the Easy Bluetooth example, I used the digits that correspond to the numeric/arrow keys on a keyboard keypad, but you can also press 5, which is in the center to make the Boe-Bot stay still. You can update it for your Easy Bluetooth by substituting your code's Pin and Baudmode arguments in the SERIN command and substituting your code's SEROUT command in place of the DEBUG command.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    pulse    VAR  Word
    maneuver VAR  Word
    
    FREQOUT 4, 2000, 3000
    DEBUG "8 = forward", CR,
          "2 = backward", CR,
          "4 = rotate left", CR,
          "6 = rotate right", CR,
          "5 = stay still"
    
    DO
      SERIN 16, 84, 20, Timeout, [maneuver]
      Timeout:
      GOSUB Go
    LOOP
    
    
    Go:
    
      LOOKDOWN maneuver, ["5", "8", "2", "4", "6"], maneuver
      LOOKUP maneuver, [750, 850, 650, 650, 850], pulse
      PULSOUT 13, pulse
      LOOKUP maneuver, [750, 650, 850, 650, 850], pulse
      PULSOUT 12, pulse
    
      RETURN
    
    


    P.S. That was fun. I added a post about it to our Stamps in Class "Mini Projects" thread in the Boe-Bot Robot section.
  • Matt GillilandMatt Gilliland Posts: 1,406
    edited 2011-09-15 18:01
    Hi complex_mentality -
    What's the word? Any progress, and did Andy's code help?
    Oh, yeah - and welcome to the Forums!
    -Matt
Sign In or Register to comment.