Shop OBEX P1 Docs P2 Docs Learn Events
BoeBot and Xbee code review — Parallax Forums

BoeBot and Xbee code review

Doug3251Doug3251 Posts: 8
edited 2012-05-25 16:11 in BASIC Stamp
Thanks Mike and xanadu, low batteries were the culprits. Thanks for the advice now just fine tune some values and I will be ready to go.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-25 14:12
    Servos require continual control pulses, about every 20ms. That's why there's a PAUSE 20 after each set of PULSOUTs (except for the last one ... an omission?)

    Your program produces a single pulse pair for each character received. That won't do unless there's a continuous stream of such characters. You may also need to adjust the PAUSE time to reflect the time needed to receive each character.
  • Doug3251Doug3251 Posts: 8
    edited 2012-05-25 14:56
    Okay I located the BS2 Program that Parallax wrote and loaded on to my BOE, and I seem to be having the same problems I can get the BoeBot to spin left or spin right but no forward or backward movement. I tried messing around with the PAUSE values and nothing happens.
    Like I said above the code works intermittenly then stops working. Example I will press and hold "W" to move forward and it will jerk forward and then nothing, I can sometimes get it to turn in circles but nothing works reliably its all spontaneous. I know that its not my signal form on Xbee to the other they are only a foot apart.
    Here is the code:

    ' =========================================================================
    '
    ' File...... xbee_demo.bs2
    ' Purpose... to demonstrate serial communication through the XBee
    ' Author.... Parallax, Inc.
    ' E-mail.... support@parallax.com
    ' Started... 9-28-2010
    ' Updated...
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' =========================================================================


    '
    [ Program Description ]
    '
    ' This program is meant to drive a BOE-Bot by receiving commands from an
    ' XBee wireless radio. The commands are simple ascii characters, the
    ' the charachters 'a, s, d, and w' on the keyboard are used to control
    ' how the BOE-Bot drives.

    '
    [ Revision History ]



    '
    [ I/O Definitions ]

    XBEE_TX PIN 1 'connect to DIN pin on XBee module
    XBEE_RX PIN 0 'connect to DOUT pin on XBee module

    L_MOTOR PIN 13
    R_MOTOR PIN 12



    '
    [ Constants ]

    L_FWD CON 825
    L_REV CON 685
    L_STOP CON 750
    R_FWD CON 685
    R_REV CON 825
    R_STOP CON 750

    BAUD_MODE CON 84 '9600 Baud, 8n1 true


    '
    [ Variables ]

    i VAR Byte
    rx_data VAR Byte


    '
    [ EEPROM Data ]



    '
    [ Initialization ]

    Initialization:

    LOW L_MOTOR
    LOW R_MOTOR



    '
    [ Program Code ]

    Main:

    DO
    SERIN XBEE_RX, BAUD_MODE, [rx_data] 'get data from the XBee

    SELECT rx_data
    CASE $61 ' ascii for 'a'
    GOSUB Turn_left

    CASE $73 ' ascii for 's'
    GOSUB Backup

    CASE $64 ' ascii for 'd'
    GOSUB Turn_right

    CASE $77 ' ascii for 'w'
    GOSUB Forward

    ENDSELECT


    LOOP


    END


    '
    [ Subroutines ]


    Forward: 'drive the BOE-Bot forward
    FOR i = 0 TO 10
    PULSOUT L_MOTOR, L_FWD
    PULSOUT R_MOTOR, R_FWD
    PAUSE 20
    NEXT

    RETURN

    Backup: 'drive the BOE-Bot backwards
    FOR i = 0 TO 10
    PULSOUT L_MOTOR, L_REV
    PULSOUT R_MOTOR, R_REV
    PAUSE 20
    NEXT

    RETURN

    Turn_left: 'turn the BOE-Bot left
    FOR i = 0 TO 10
    PULSOUT L_MOTOR, L_STOP
    PULSOUT R_MOTOR, R_FWD
    PAUSE 20
    NEXT

    RETURN

    Turn_right: 'turn the BOE-Bot right
    FOR i = 0 TO 10
    PULSOUT L_MOTOR, L_FWD
    PULSOUT R_MOTOR, R_STOP
    PAUSE 20
    NEXT

    RETURN
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-25 15:33
    There are all sorts of things that might be wrong with your setup. The servos might not be calibrated. I can't even guess how you'd get turning movements and not forward and backward. That doesn't make sense. As is true with anything like this, throw it out until you've satisfied yourself that the basics work. Download the "Robotics with the BoeBot" tutorial from Parallax's Downloads webpage (under Stamp Tutorials). Work through the calibration procedure as described there. Write simple programs that move first one wheel forward, then backward, then the other. Then get the BotBot to move forward and then backward. Only then should you try this program again. The program should work as is. It certainly has worked for me and for others. It's hard to tell you why it doesn't without detailed information on how it behaves with what inputs. It's not enough to say that one thing or another doesn't work. You need to describe its behavior in detail.
  • xanaduxanadu Posts: 3,347
    edited 2012-05-25 15:39
    And don't forget servos and XBees need lots of juice, low battery voltage will cause random head scratching.
  • Doug3251Doug3251 Posts: 8
    edited 2012-05-25 16:11
    Thanks Mike and xanadu, low batteries were the culprits. Thanks for the advice now just fine tune some values and I will be ready to go.
Sign In or Register to comment.