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.
Now 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!