Custom RC Joystick System - Need Help
Keith Young
Posts: 569
I am gutting a Logitech Joystick and am trying to make it control things through XBEE.
I finally got the prop to sense every button and potentiometer. The data is currently to my knowledge being saved in the following format.
The 16 buttons are saved in a variable "button", for example when the trigger is pulled button[0]=1 otherwise its 0.
I can get this value as well as the ADC values to send perfectly through Parallax Serial Terminal when I send the individual bits button[0],button[1]...button[15], however when I try to send the whole "button" through such as DBG.Bin(button,16) it only seems to read the trigger.
I will first post my Joystick code, then post the code that will go in the aircraft or other general purpose Prop controlled hardware.
I have been tinkering with syntax alot, hence alot of commented out sections. I am assuming I am doing something fundamentally wrong as far as data treatment that will probably stick out to someone that actually knows what they're doing.
Basically I just want the end object to know everything the Joystick is sending. My current method is trying to send button which may equal say 0000010000001000 and I want the controled robot to know buttons 6, and 13 are being pressed, and then act on that. Additionally it needs to receive 4 12 bit ADC signals, know which is which, and act accordingly.
I tried sending such as
which looks perfect to me when sent from the joystick XBEE to my other XBEE connected via USB to my PC and read through X-CTU. However when trying to read it in any form such as
it just doesn't seem to work.
Thanks,
Keith
I finally got the prop to sense every button and potentiometer. The data is currently to my knowledge being saved in the following format.
The 16 buttons are saved in a variable "button", for example when the trigger is pulled button[0]=1 otherwise its 0.
I can get this value as well as the ADC values to send perfectly through Parallax Serial Terminal when I send the individual bits button[0],button[1]...button[15], however when I try to send the whole "button" through such as DBG.Bin(button,16) it only seems to read the trigger.
I will first post my Joystick code, then post the code that will go in the aircraft or other general purpose Prop controlled hardware.
{{
Version C
Got rid of cycles area, now everything is in the check area and the base
phases are included in the joystick phases resulting in a much faster response
Version D
Beginning XBEE communication
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
dpin = 1
cpin = 2
spin = 0
rudderc = 0
aileronc = 1
elevatorc = 2
throttlec = 3
OBJ
XBE : "FullDuplexSerialPlus"
MCP : "MCP3208_fast_ADC"
VAR
long cog
word rudder, aileron, elevator, throttle
long stack[256]
PUB Start
'XBE.Start( 8, 9, 0, 9600)
XBE.Start(31,30, 0,57600)
MCP.Start(dpin, cpin, spin, 0)
cognew(Check, @stack[0])
dira[17]~~
outa[17]~
repeat
!outa[17]
XBE.Str(String(16))
XBE.Bin(button[ 0],1)
XBE.Bin(button[ 1],1)
XBE.Bin(button[ 2],1)
XBE.Bin(button[ 3],1)
XBE.Bin(button[ 4],1)
XBE.Bin(button[ 5],1)
XBE.Bin(button[ 6],1)
XBE.Bin(button[ 7],1)
XBE.Bin(button[ 8],1)
XBE.Bin(button[ 9],1)
XBE.Bin(button[10],1)
XBE.Bin(button[11],1)
XBE.Bin(button[12],1)
XBE.Bin(button[13],1)
XBE.Bin(button[14],1)
XBE.Bin(button[15],1)
XBE.Str(String(13))
XBE.Bin(button,16)
XBE.Str(String(13))
XBE.Dec(button)
waitcnt(clkfreq / 5 + cnt)
'XBE.Tx(button)
'XBE.Str(string(13))
'XBE.Dec(rudder)
'XBE.Str(string(13))
'XBE.Dec(aileron)
'XBE.Str(string(13))
'XBE.Dec(elevator)
'XBE.Str(string(13))
'XBE.Dec(throttle)
'if button[11] == 1 'One way to check a certain button
' outa[27]~~
'else
' outa[27]~
'if word[@button][0] == 1 'Another way to check a certain button
' outa[27]~~
'waitcnt(clkfreq / 5 + cnt)
Pub Check
dira[16]~~
dira[17]~~
outa[17]~
dira[25]~~
outa[25]~
!outa[25]
dira[24]~~
outa[24]~
!outa[24]
dira[21]~~
outa[21]~
!outa[21]
dira[10]~~
outa[10]~
!outa[10]
dira[15]~~
outa[15]~
!outa[15]
repeat
'rudder := MCP.In(rudderc)
'aileron := MCP.In(aileronc)
'elevator := MCP.In(elevatorc)
'throttle := MCP.In(throttlec)
!outa[21]
!outa[10]
if ina[23] == 0 '13 Hat Up
word[@button][12] := 1
else
word[@button][12] := 0
if ina[22] == 0 '14 Hat Right
button.WORD[13] := 1
else
button.WORD[13] := 0
if ina[19] == 0 '15 Hat Down
button.WORD[14] := 1
else
button.WORD[14] := 0
if ina[20] == 0 '16 Hat Left
button.WORD[15] := 1
else
button.WORD[15] := 0
if ina[12] == 0 '7
button.WORD[6] := 1
else
button.WORD[6] := 0
if ina[11] == 0 '8
button.WORD[7] := 1
else
button.WORD[7] := 0
!outa[21]
!outa[10]
!outa[25]
'!outa[17]
if ina[20] == 0 '1 Trigger
outa[16]~~
button.WORD[0] := 1
else
button.WORD[0] := 0
if ina[19] == 0 '2 Secondary
button.WORD[1] := 1
else
button.WORD[1] := 0
if ina[22] == 0 '3 Bottom Left
button.WORD[2] := 1
else
button.WORD[2] := 0
if ina[23] == 0 '4 Bottom Right
button.WORD[3] := 1
else
button.WORD[3] := 0
'!outa[17]
!outa[25]
!outa[24]
!outa[15]
if ina[20] == 0 '5 Top Left
button.WORD[4] := 1
else
button.WORD[4] := 0
if ina[19] == 0 '6 Top Right
button.WORD[5] := 1
else
button.WORD[5] := 0
if ina[13] == 0 '9
button.WORD[8] := 1
else
button.WORD[8] := 0
if ina[14] == 0 '10
button.WORD[9] := 1
else
button.WORD[9] := 0
if ina[12] == 0 '11
button.WORD[10] := 1
else
button.WORD[10] := 0
if ina[11] == 0 '12
button.WORD[11] := 1
else
button.WORD[11] := 0
!outa[24]
!outa[15]
DAT
MyData byte $AA
button word "0000000000000000"
{{
Version A
Figuring out how to receive data and save it to variables
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
XBE : "FullDuplexSerialPlus"
DBG : "FullDuplexSerial"
VAR
long cog
word rudder, aileron, elevator, throttle
long stack[256]
PUB Start
XBE.Start( 7, 6, 0, 9600)
DBG.Start(31,30, 0,57600)
dira[ 3]~~
outa[ 3]~
dira[ 4]~~
outa[ 4]~
cognew(Display, @stack[0])
repeat
!outa[4]
'DBG.Str(String(16))
'DBG.Str(String("Before first RX is working"))
'DBG.Str(String(13))
word[@button][ 0] := XBE.Rx
'button.WORD[ 0] := XBE.Rx
'DBG.Str(String("After first RX is working"))
'DBG.Str(String(13))
'button.WORD[ 1] := XBE.Rx
'button.WORD[ 2] := XBE.Rx
'button.WORD[ 3] := XBE.Rx
'button.WORD[ 4] := XBE.Rx
'button.WORD[ 5] := XBE.Rx
'button.WORD[ 6] := XBE.Rx
'button.WORD[ 7] := XBE.Rx
'button.WORD[ 8] := XBE.Rx
'button.WORD[ 9] := XBE.Rx
'button.WORD[10] := XBE.Rx
'button.WORD[11] := XBE.Rx
'button.WORD[12] := XBE.Rx
'button.WORD[13] := XBE.Rx
'button.WORD[14] := XBE.Rx
'button.WORD[15] := XBE.Rx
'DBG.Bin(button,16)
'DBG.Bin(button[ 1],1)
'DBG.Bin(button[ 2],1)
'DBG.Bin(button[ 3],1)
'DBG.Bin(button[ 4],1)
'DBG.Bin(button[ 5],1)
'DBG.Bin(button[ 6],1)
'DBG.Bin(button[ 7],1)
'DBG.Bin(button[ 8],1)
'DBG.Bin(button[ 9],1)
'DBG.Bin(button[10],1)
'DBG.Bin(button[11],1)
'DBG.Bin(button[12],1)
'DBG.Bin(button[13],1)
'DBG.Bin(button[14],1)
'DBG.Bin(button[15],1)
'XBE.Str(string(13))
'XBE.Dec(rudder)
'XBE.Str(string(13))
'XBE.Dec(aileron)
'XBE.Str(string(13))
'XBE.Dec(elevator)
'XBE.Str(string(13))
'XBE.Dec(throttle)
'if button[0] == 1 'One way to check a certain button
' outa[ 3]~~
'else
' outa[ 3]~
'if word[@button][0] == 1 'Another way to check a certain button
' outa[ 3]~~
{{ repeat
XBE.Str(string(16))
XBE.Bin(button[ 0],1)
XBE.Bin(button[ 1],1)
XBE.Bin(button[ 2],1)
XBE.Bin(button[ 3],1)
XBE.Bin(button[ 4],1)
XBE.Bin(button[ 5],1)
XBE.Bin(button[ 6],1)
XBE.Bin(button[ 7],1)
XBE.Bin(button[ 8],1)
XBE.Bin(button[ 9],1)
XBE.Bin(button[10],1)
XBE.Bin(button[11],1)
XBE.Bin(button[12],1)
XBE.Bin(button[13],1)
XBE.Bin(button[14],1)
XBE.Bin(button[15],1)
XBE.Str(string(13))
XBE.Dec(rudder)
XBE.Str(string(13))
XBE.Dec(aileron)
XBE.Str(string(13))
XBE.Dec(elevator)
XBE.Str(string(13))
XBE.Dec(throttle)
if button[11] == 1 'One way to check a certain button
outa[27]~~
else
outa[27]~
if word[@button][0] == 1 'Another way to check a certain button
outa[27]~~
waitcnt(clkfreq / 20 + cnt)
}}
PUB Display
repeat
DBG.Bin(button,16)
DBG.Str(String(13))
DBG.Dec(button)
DBG.Str(String(13))
DBG.Tx(button)
waitcnt(clkfreq / 5 + cnt)
DBG.Str(String(16))
DAT
MyData byte 800, $AA
button word 0000000000000001
I have been tinkering with syntax alot, hence alot of commented out sections. I am assuming I am doing something fundamentally wrong as far as data treatment that will probably stick out to someone that actually knows what they're doing.
Basically I just want the end object to know everything the Joystick is sending. My current method is trying to send button which may equal say 0000010000001000 and I want the controled robot to know buttons 6, and 13 are being pressed, and then act on that. Additionally it needs to receive 4 12 bit ADC signals, know which is which, and act accordingly.
I tried sending such as
DBG.Bin(button[0],1) DBG.Bin(button[1],1) DBG.Bin(button[2],1) ... DBG.Bin(button[15],1)
which looks perfect to me when sent from the joystick XBEE to my other XBEE connected via USB to my PC and read through X-CTU. However when trying to read it in any form such as
button := DBG.GetBin(button) 'or button[0] := DBG.Rx(button[0]) 'etc
it just doesn't seem to work.
Thanks,
Keith

Comments
Lot's of reason's Your code might not be working, could You trim it down a bit for us?. remove any code not being used.
Some folk's are grumpy and don't wanna slog thru that much code...
To help Yourself out, Try to comment each line of code with what that line's function is.
I think this might be an XBEE issue, but can't be sure cuz I sorta got lost inside all that Commented stuff.
The OBEX (human input section) should be very helpfull, as will the Wireless forum...
Anyway's, keep asking and the answers will come.
If you want to set a bit in a variable you need to use the bitwise or operator and the bitshift operator:
button |= |<1
Here is the code that's associated with that problem.
PUB Start XBE.Start( 8, 9, 0, 9600) dira[27]~~ outa[27]~ dira[16]~~ outa[16]~ pinn21 := |< 21 pinn10 := |< 10 pinn25 := |< 25 pinn24 := |< 24 pinn15 := |< 15 pinn17 := |< 17 pinn27 := |< 27 pinn20 := |< 20 pinn19 := |< 19 pinn22 := |< 22 pinn23 := |< 23 pinn12 := |< 12 pinn11 := |< 11 pinn13 := |< 13 pinn14 := |< 14 butt1 := |< 0 butt2 := |< 1 butt3 := |< 2 butt4 := |< 3 butt5 := |< 4 butt6 := |< 5 butt7 := |< 6 butt8 := |< 7 butt9 := |< 8 butt10 := |< 9 butt11 := |< 10 butt12 := |< 11 butt13 := |< 12 butt14 := |< 13 butt15 := |< 14 butt16 := |< 15 cognew(@entry, @Shared) DAT ORG 0 entry mov Mem, PAR or dira,pinn21 or outa,pinn21 or dira,pinn25 or outa,pinn25 or dira,pinn24 or outa,pinn24 or dira,pinn10 or outa,pinn10 or dira,pinn15 or outa,pinn15 or dira,pinn17 and outa,pinn17 or dira,pinn27 and outa,pinn27 xor outa,pinn21 xor outa,pinn25 xor outa,pinn24 xor outa,pinn10 xor outa,pinn15 mov time,cnt ' Current clock loaded into time add time,delay ' delay added to time :Loop xor outa, pinn21 'Pin 21 PHASE 1 waitcnt time,delay mov temp, ina test temp, pinn23 wz '13 Hat Up if_z or button, butt13 if_nz andn button, butt13 test temp, pinn22 wz '14 Hat Right if_z or button, butt14 if_nz andn button, butt14 test temp, pinn19 wz '15 Hat Down if_z or button, butt15 if_nz andn button, butt15 test temp, pinn20 wz '16 Hat Left if_z or button, butt16 if_nz andn button, butt16 xor outa, pinn21 '-------------------------------------------------------------------- xor outa, pinn25 'Pin 25 PHASE 2 waitcnt time,delay mov temp, ina test temp, pinn20 wz '1 Trigger if_z or button, butt1 if_nz andn button, butt1 test temp, pinn19 wz '2 Secondary if_z or button, butt2 if_nz andn button, butt2 test temp, pinn22 wz '3 Bottom Left if_z or button, butt3 if_nz andn button, butt3 test temp, pinn23 wz '4 Bottom Right if_z or button, butt4 if_nz andn button, butt4 xor outa, pinn25 '--------------------------------------------------------------------- xor outa, pinn24 'Pin 24 PHASE 3 waitcnt time,delay mov temp, ina test temp, pinn20 wz '5 Top Left if_z or button, butt5 if_nz andn button, butt5 test temp, pinn19 wz '6 Top Right if_z or button, butt6 if_nz andn button, butt6 xor outa, pinn24 '------------------------------------------------------------------- xor outa, pinn10 'Pin 10 PHASE 4 waitcnt time,delay mov temp, ina test temp, pinn12 wz '7 if_z or button, butt7 if_nz andn button, butt7 test temp, pinn11 wz '8 if_z or button, butt8 if_nz andn button, butt8 xor outa, pinn10 '--------------------------------------------------------------------------- xor outa, pinn15 'Pin 15 PHASE 5 waitcnt time,delay mov temp, ina test temp, pinn13 wz '9 if_z or button, butt9 if_nz andn button, butt9 test temp, pinn14 wz '10 if_z or button, butt10 if_nz andn button, butt10 test temp, pinn12 wz '11 if_z or button, butt11 if_nz andn button, butt11 test temp, pinn11 wz '12 if_z or button, butt12 if_nz andn button, butt12 xor outa, pinn15 wrlong button, Mem jmp #:Loop ' Check trigger again using :loop button word %000000000000000 delay long 5000 pinn21 long 0 pinn10 long 0 pinn25 long 0 pinn24 long 0 pinn15 long 0 pinn17 long 0 pinn27 long 0 pinn20 long 0 pinn19 long 0 pinn22 long 0 pinn23 long 0 pinn12 long 0 pinn11 long 0 pinn13 long 0 pinn14 long 0 butt1 long 0 butt2 long 0 butt3 long 0 butt4 long 0 butt5 long 0 butt6 long 0 butt7 long 0 butt8 long 0 butt9 long 0 butt10 long 0 butt11 long 0 butt12 long 0 butt13 long 0 butt14 long 0 butt15 long 0 butt16 long 0 temp long 0 time Res 1 Mem Res 1Now it's an XBEE issue which I posted in the Wireless forum.
That should be an easy fix. My main thing right now is getting the XBEE to steam steadily instead of the unorganized clumps it is sending. After that I gotta get it to also send 4 12bit ADC signals, then fix that up so it sends samples faster and faster.
I'll quick get that thing you suggested working.
Thanks!