Shop OBEX P1 Docs P2 Docs Learn Events
Rctime/xbee/joystick — Parallax Forums

Rctime/xbee/joystick

jbodjbod Posts: 46
edited 2008-03-16 22:12 in Robotics
I am currently using the following code to control my servos on my BOE-BOT via key commands through debug term in Stampeditor over a wireless connection via XBEE (working great) ... I would like to change it now so that I can use a USB joystick or game controller connect to my PC to send the controls to the BOT ... Would the RCTIME command be the best place to start? (any one have some source code for this I can review) ... I just want to control the two servos for forward, backward, left and right ... for now ... the PAN/TILT camera servos will be controlled by other method. Thanks in advance!!!!!

' {$STAMP BS2}
' {$PBASIC 2.5}
' ****************************************
' * Node_Control.bs2···················· *
' * Illustrates control and polling····· *
' * of nodes···························· *
' ****************************************
myAddr··········· CON $0············ ' Node Address
DestAddr········· CON $0············ ' Destination address
Baud············· CON 84············ ' Baud rate, 9600, 8-N-1, non-inverted, on BS2.
RX··············· PIN 0············· ' Receive Pin
TX··············· PIN 2············· ' Transmit Pin
RTS·············· PIN 6············· ' Flow control Pin
Buzzer··········· PIN 4
LED·············· PIN 7
RC··············· PIN 10
Left············· PIN 15
Right············ PIN 14
Pan·············· PIN 13
Tilt············· PIN 12
RFin············· VAR Byte
DataOut·········· VAR Byte
x················ VAR Byte
Counter·········· VAR Word

' XBEE SETUP
HIGH TX····································· ' Set TX pin to idle state
DEBUG CLS, "Configuring XBee..."
PAUSE 2000·································· ' Guard time for command sequence
SEROUT TX,Baud,[noparse][[/noparse]"+++"]······················ ' Enter command mode
PAUSE 2000·································· ' Guard time for command sequence
SEROUT TX,Baud,[noparse][[/noparse]"ATNI Photo Node",CR,······· ' Set description
·············· "ATMY ", HEX myAddr,CR,······ ' Set node address
·············· "ATDL ", HEX DestAddr,CR,···· ' Set destination node address
·············· "ATD6 1",CR,················· ' Use RTS for flow control
·············· "ATCN",CR]··················· ' Exit command mode
PAUSE 1000
DEBUG "Configuration Complete!",CR
'CENTER PAN/TILT
FOR counter = 1 TO 50
····· PULSOUT Tilt, 720
····· PAUSE 15
····· PULSOUT Pan, 800
NEXT

' Beep to indicate ready
· FREQOUT 4, 700, 700
· FREQOUT 4, 300, 9000
· FREQOUT 4, 50, 800
· FREQOUT 4, 50, 6000
· FREQOUT 4, 50, 6000
· FREQOUT 4, 50, 6000

DO
· GOSUB READ_Data
· GOSUB ReadnControl
LOOP
DEBUG CLS,"Ready",CR
READ_Data:····· ' Read RC Network
· HIGH RC
· PAUSE 5
· RCTIME RC,1,DataOut
RETURN
Send_Full:····· ' Tx data with text
· DEBUG "Sending full text····· ", DEC DataOut,"· ", CR
· SEROUT TX, Baud, [noparse][[/noparse]" Photo is: ", DEC DataOut,CR]
RETURN
Send_Value:···· ' TX data only
· DEBUG "Sending value only·· ", DEC DataOut,"· ", CR
· SEROUT TX, Baud, [noparse][[/noparse]DEC DataOut,CR]
RETURN
ReadnControl:·· ' Read incoming data and control
· SERIN RX\RTS,Baud,250,Timeout2,[noparse][[/noparse]RFin]
· SELECT RFin
· CASE "D"
···· GOSUB Send_Full
· CASE "d"
···· GOSUB Send_Value
'LED CONTROL
· 'CASE "N","n"
··· 'DEBUG "LED ON·························· ",CR
··· 'HIGH LED
· 'CASE "F","f"
··· 'DEBUG "LED OFF························· ",CR
··· 'LOW LED

' BOT MOVEMENT
· CASE "R","r"
··· DEBUG "Left···························· ",CR
··· FOR x = 1 TO 5
····· PULSOUT Left, 500
··· NEXT
· CASE "U","u"
··· DEBUG "Right··························· ",CR
··· FOR x = 1 TO 5
····· PULSOUT Right, 1000
··· NEXT
· CASE "T","t"
··· DEBUG "FWD····························· ",CR
··· FOR x = 1 TO 50
····· PULSOUT Right, 500
····· PULSOUT Left, 1000
····· PAUSE 15
··· NEXT
· CASE "Y","y"
··· DEBUG "BKW····························· ",CR
··· FOR x = 1 TO 50
····· PULSOUT Right, 1000
····· PULSOUT Left, 500
····· PAUSE 15
··· NEXT

' PAN CAMEREA
· CASE "Q","q"
··· DEBUG "PAN Left························ ",CR
··· FOR x = 1 TO 2
····· PULSOUT Pan, 500
··· NEXT
· CASE "W","w"
··· DEBUG "Center PAN······················ ",CR
··· FOR x = 1 TO 25
····· PULSOUT Pan, 800
····· PAUSE 10
··· NEXT
· CASE "E","e"
··· DEBUG "PAN· Right······················ ",CR
··· FOR x = 1 TO 2
····· PULSOUT Pan, 1000
··· NEXT

' TILT CAMEREA
· CASE "I","i"
··· DEBUG "Tilt Up························· ",CR
··· FOR x = 1 TO 1
····· PULSOUT Tilt, 200
··· NEXT
· CASE "O","o"
··· DEBUG "Center Tilt····················· ",CR
··· FOR x = 1 TO 25
····· PULSOUT Tilt, 700
····· PAUSE 10
··· NEXT
· CASE "P","p"
··· DEBUG "Tilt· Down······················ ",CR
··· FOR x = 1 TO 1
····· PULSOUT Tilt, 1200
··· NEXT

' QUICK CENTER CAMERA
· CASE "B","b"
··· DEBUG "Center Camerea·················· ",CR
··· FOR counter = 1 TO 50
····· PULSOUT Tilt, 720
····· PAUSE 15
····· PULSOUT Pan, 800
··· NEXT

' Quick SPIN
· CASE "H","h"
··· DEBUG "Spinning························ ",CR
··· FOR counter = 1 TO 50
····· PULSOUT Left, 1000
····· PULSOUT Right, 1000
··· NEXT

' SOUND
· CASE "1" TO "9"
··· DEBUG "Sounding tone at ", DEC RFin-48 * 600,"Hz······· ",CR
··· FREQOUT buzzer, 50, RFin-48 * 600
· ENDSELECT
TimeOut2:
· RETURN

Comments

  • jbodjbod Posts: 46
    edited 2008-03-16 14:53
    or is it possible to make a connection like this to the STAMP via BOE?

    http://www.lynxmotion.com/images/html/build036.htm
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-16 15:43
    jbod -

    The web article would kind of indicate that one can, but there are a number of caveats, if you read the article in it entirety. Here is an excerpt from the first sentences of the article:

    "Establishing a fast and reliable connection between a Sony-brand PS2 controller and the Basic Stamp 2 processor. Note, the Basic Stamp 2 processor cannot properly read the left vertical joystick."

    Is your a SONY brand PS-2 controller? Can you live with it not properly reading the left vertical joystick? I'm sure there are other caveats as well. These are questions only YOU can answer.

    If you can live with that and the other possible restrictions, go for it.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming can't be all that difficult, it's nothing but 1's and 0's
  • jbodjbod Posts: 46
    edited 2008-03-16 22:12
    Sorry guess I was not detailed enough when I posted ... I want to see if I can connect a PS2 game pad direct to my BOE (like Lynxmotion has connected it to their BOTII board) or connect a USB game pad to my PC and get stamp editor to pickup my USB gamepad input and control my BOE-BOT from the USB controller. (I don't own a Lynxmotion BOTII) ... I do have a BRAT with SSC32 on the way though [noparse];)[/noparse]



    Sorry for not being clearer.
Sign In or Register to comment.