'
=========================================================================
'
' File...... Easy Bluetooth.bs2
' Purpose... Control a Boe-Bot with a GUI interface
' Author.... Technical Support & RoboTech SRL
' E-mail.... support@parallax.com
' Started... April 1st 2009
' Updated... N/A
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
'
=========================================================================
' -----[ Program Description ]---------------------------------------------
' This program is what is loaded into the BASIC Stamp prior to using the
GUI interface
' from RoboTech SLR. It allows a Boe-Bot to be controlled via a GUI
interface.
'
' Commands are as followed:
'
' Up Arrow = Forward
' Down Arrow = Backwards
' Left Arrow = Left Turn
' Right Arrow = Right Turn
' Space Bar = Stop
'
' You can press and hold and release an arrow key for 2 seconds to
access a double speed
' of each action. For example, Press Up Arrow, release to make the
Boe-Bot move faster
' forward.
' -----[ I/O Definitions ]-------------------------------------------------
BT_RX PIN 2 ' RX of the Easy Bluetooth
BT_TX PIN 0 ' TX of the Easy Bluetooth
LED PIN 7 ' Indicator LED for Bluetooth Connection
' -----[ Constants ]-------------------------------------------------------
BT_SPEED CON 84 ' baud 9600 true UART
' -----[ Variables ]-------------------------------------------------------
tLeft VAR Word ' Left Servo control pulse durations
tRight VAR Word ' Right Servo control pulse durations
temp VAR Word ' Temp variable
' Buffer array not declared as buffer VAR Word(5) for SERIN
functionality.
' It can still be accessed as buffer(0), buffer(1), etc. However,
' buffer0, buffer1, etc. should be used in SERIN commands with
variations
' of WAIT.
buffer0 VAR Byte ' Buffer - Start char = $ff
buffer1 VAR Byte ' Message Index value
buffer2 VAR Byte ' Command
buffer3 VAR Byte ' Argument 1 (return data 1)
buffer4 VAR Byte ' Argument 2 (return data 2)
buffer VAR buffer0 ' For standard array indexing
msgIndex VAR Byte ' message index
rxc VAR Byte ' Receive Clear
' -----[ Initialization ]--------------------------------------------------
Program_Start:
LOW LED
DEBUG CLS
PAUSE 1000 ' Wait for the RBT-001 radio to be ready.
msgIndex = 0
buffer0 = $FF ' Connection packet
buffer1 = msgIndex
buffer2 = $CC
buffer3 = 100
buffer4 = 100
GOSUB Set_Servo_Speed
DEBUG CR,"Waiting connection..." ' wait for connection request
SERIN BT_RX, BT_SPEED, [WAITSTR buffer \ 3, buffer3, buffer4] '
' -----[ Program Code ]----------------------------------------------------
DO
SELECT buffer2
CASE $CC ' Connect
HIGH LED
msgIndex = 0
DEBUG CR,"Connected"
GOSUB Reply
CASE $DD ' Disconnect
LOW LED
DEBUG CR,"Disconnected"
GOSUB Reply
GOTO Program_Start
CASE $11 ' Servo
DEBUG CR,"Servo"
GOSUB Set_Servo_Speed
GOSUB Reply
CASE ELSE ' Error
buffer2 = $EE
GOSUB Reply
ENDSELECT
Resume: ' If Message not rcvd, try again
PULSOUT 13, tLeft ' Servo control pulses
PULSOUT 12, tRight
SERIN BT_RX, BT_SPEED, 10, Resume, ' Get next command
[WAITSTR buffer \ 2, buffer2,
buffer3, buffer4]
PULSOUT 13, tLeft ' Servo control pulses again
PULSOUT 12, tRight
LOOP
Reply:
msgIndex = msgIndex + 1 ' Increment message index for reply. Next
message from PC has to use
buffer1 = msgIndex ' reply's buf[1].
SEROUT BT_TX, BT_SPEED, [STR buffer \5]
' -----[ Subroutines ]-----------------------------------------------------
Set_Servo_Speed: ' Range of 0 to 200 with 100 = stopped maps to 650 to
850 with 750 stopped.
tLeft = buffer3 + 650 ' Decode servo speed.
tRight = buffer4 + 650
RETURN
' -----[ Data ]------------------------------------------------------------
ResetOnOff DATA 0 ' On/off toggle w/ Reset button
RequestConnect DATA $FF, 0, 1, 0, 0
ConnectionGranted DATA $FF, 0, 2, 0, 0
RequestCommand DATA $FF, 0, 3, 0, 0
ServoSpeeds DATA $FF, 0, 4, 0, 0 |