xbee not recieving proper values
graffix
Posts: 389
Ive been struggling with some code for awhile.Ive taken the code Ive been working with and ommited alot of it to try and simplify the process and Im still struggling with it.Currently I'd like to get two parallax 2 axis joysticks to control a boe's drive wheels. Via xbee modules. I dont think there is any wiring issues, just code. Basically one joystick controls up-down values and the other left right values. Sent to the boe via xbee modules. Both codes have debug commands. The controller gives good values in its debug window. The recieving boe does not display the same values in its debug window. They also dont refresh at the same rate. Im attaching some code for each and a video. If someone can look it over and suggest a fix that would be great. Thanks ahead of time. If you have any questions please ask. Ps I already have all the demo code and different variations.
http://www.youtube.com/watch?v=ab_NkBmQvtg&feature=plcp
http://www.youtube.com/watch?v=ab_NkBmQvtg&feature=plcp
'recieving boe '{$STAMP BS2} '{$PBASIC 2.5} ' -----[ Constants ]------------------------------------------------------- L_FWD CON 1000 L_REV CON 500 L_STOP CON 750 R_FWD CON 500 R_REV CON 1000 R_STOP CON 750 BAUD_MODE CON 84 '9600 Baud, 8n1 true '---Variables------------------------------------------- UD VAR Byte LR VAR Byte a VAR Word b VAR Word c VAR Word d VAR Word e VAR Word f VAR Word i VAR Byte rx_data VAR Byte '---Pin Descriptions------------------------------------ xbee_rts PIN 9 xbee_Rx PIN 10 ' Dout xbee_Tx PIN 11 ' Din Rwheel PIN 13 Lwheel PIN 12 '---initializations------------------------------------ LOW Lwheel LOW Rwheel '---main program------------------------------------------ DO SERIN XBee_Tx, 84, [UD,LR] DEBUG HOME, "UD =", DEC UD, CLREOL, CR, "LR = ", DEC LR, CLREOL SELECT UD CASE < 270 UD = a GOSUB forwards CASE > 400 UD = b GOSUB backwards CASE 270 TO 400 UD = c ENDSELECT SELECT LR CASE < 220 LR = d GOSUB left CASE > 380 LR = e GOSUB right CASE 220 TO 380 LR = f ENDSELECT IF (UD = c)AND(LR = f) THEN GOSUB stall ENDIF LOOP '---Subroutines------------------------------------------ forwards: PULSOUT Rwheel, L_FWD PULSOUT Lwheel, R_FWD PAUSE 20 RETURN backwards: PULSOUT Rwheel, R_REV PULSOUT Lwheel, L_REV PAUSE 20 RETURN left: PULSOUT Lwheel, L_FWD PULSOUT Rwheel, R_STOP PAUSE 20 RETURN right: PULSOUT Lwheel, L_STOP PULSOUT Rwheel, R_FWD PAUSE 20 RETURN stall: PULSOUT Rwheel, R_STOP PULSOUT Lwheel, L_STOP PAUSE 20 RETURN
'xbee controller ' {$STAMP BS2} ' {$PBASIC 2.5} '----------------[Initialize]--------------------------- PAUSE 5 SEROUT 0, 84, [22,12] SEROUT 0, 84,50, [22,17, "Hello", 13, "John"] PAUSE 1000 '---------------[Variables]----------------------------- LR VAR Word UD VAR Word btn1wrk VAR Byte btn2wrk VAR Byte green VAR Bit red VAR Bit distance VAR Word '---------------[Constants]----------------------------- #SELECT $STAMP #CASE BS2, BS2E, BS2PE T9600 CON 84 #ENDSELECT Lcd PIN 0 Btn1 PIN 7 Btn2 PIN 5 Tx PIN 9 ' XBee DIN Rx PIN 10 ' XBee DOUT LRjoy PIN 6 UDjoy PIN 4 Led_A PIN 15 Led_B PIN 14 stickUD CON 25 stickLD CON 25 Baud CON T9600 '-------------------------[Main]--------------------------- Main: DO HIGH 6 PAUSE 2 RCTIME 6, 1, LR HIGH 4 PAUSE 2 RCTIME 4, 1, UD DEBUG HOME, "UD =", DEC UD, CLREOL, CR, "LR = ", DEC LR, CLREOL SEROUT Rx, 84, [UD] SEROUT Rx, 84, [LR] LOOP
Comments
Probably the easiest solution is on the controller, to scale the RCTIME value down to fit in a byte.
It worked, Thanks again
After I get the Boe to display the correct values for Btn1 and Btn2. I hope to use one of them to change into a different mode of operation. Say when I press Btn1 the LR joystick then controls the Ping servo(standard servo) while sending the ping value back to be displayed on the controllers LCD until I press Btn1 again. If I can get some some help with this portion that would be great. Thanks ahead of time.
P.S. I would move this to two Prop Boe's if I had the funds to do so.
controller
Boe Bot
LCD - pin 0
UDjoystick - pin 4
LRjoystick - pin 6
Btn1 - pin 7
Btn2 - pin 5
XBee Rx - pin 10
XBee Tx - pin 9
XBee RTS- pin 8
LED_A - pin 15
LED_B - pin 14
BoeBot:
XBee RTS - pin 9
XBee Rx - pin 10
XBee Tx - pin 11
servo pal - nInp pin 12
servo pal - alarm pin 13
HM55B Clk pin 0
HM55B En pin 1
HM55B Din/Dout pin 2
Bi_clrLEDred pin 6 ' when high + low 7
Bi_clrLEDgreen pin 7 ' when high + low 6
This is all of hardware I'd like to incorporate and pins used for both controller and Boe Bot.
Im not sure how I'd like to use and code functionality of all of it. Im not sure of how much varible space would be required for each.
Im also not sure how I should establish a two way communication between the xbees so my loops dont freeze up.
I've yet to get the HM55B properly calibrated even in a code by its self. I have three different compasses and I get different readings
from each. I'm sure it's interference, but thats where I'm at regardless.
Here is latest attempt
controller
Boe Bot
though I've added some things to the code I still have same issues as before
Also, the transmitter and receiver can get out of sync and there is no way for the receiver to distinguish UD,LR data from Btn data. So you end up with UC data where you were expecting Btn data. For that reason, it can help to insert a sync character, one that will never be a data value. On the receiving end the command will look something like this:
SERIN XBee_Tx\XBee_rts, 84, [wait(sync),UD,LR,Btn1,Btn2]
where XBee_rts matches the hardware RTS pin, and the sync character may be something like a byte value of 255. With the RTS flow control implemented, it will also be possible to add a timeout to the SERIN, so the BOE can go off and do other things while it is waiting for a command. Or two way communication with flow control on both ends.
I posted that code just before I left for work. I thought it was good to go. Turns out I lost the right turn functionality of it. I tried all kinds of things. Finally I started removing some of the older variables I hadnt used in awhile and assigning the proper space for what was left. It fixed that problem. I also omitted the debug statements (tip I got from Erco) and the code seemed quite fast and responsive. I also added Btn1 centers the ping servo.
controller
Boe Bot The problems I mentioned in the other thread are still there. Im going to work on combining these three codes into two. I still havent managed to get the ping reading from the boe back to the controller without locking up the program. Any help I can get, would be great. Thanks
Im gonna guess that it has to do with the +++ atch atid stuff that isnt present in the above code. Ive tried implementing it and I havent got it to work.
controller code
boe code test bar graph program. I eventually would like to have some variant of this working while in mode 1
Boe code
wireless Remote
Boe-Bot