BoeBot and Xbee code review
Doug3251
Posts: 8
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
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.
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