Free shipping on orders over \$75

DIY Remote Control XBee controller for Robotics...

 Print view Share : #at3win #at3winheader h3 { text-align:left !important; } Previous topicNext topic

Page 3 of 35 [ 511 posts ]

1, 2, 3, 4, 5, 6 ... 35
Guru ( offline )
Posts: 4942
Posted: 2009-09-23 13:42
Yep, Currently I have the a little handshaking at the start that the Transmitter says I am ready...

Then the Robot sends out a 4 byte packet:
<Packet type><checksum><Seq number><CB Extra>

The controller responds back with a packet of data:
Again something like:
<Packet Type><Checksum><SeqNumber><CBexra=8><the PS2 type of data...>

I don't resend as the data is not critical, if the robot does not like it, it simply asks again... If I get too many timeouts on either end I then reset and wait for the transmiter to say it is ready again.

Kurt

Guru ( offline )
Posts: 9256
Posted: 2009-09-23 13:56
Excellent!!!

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...

Expert ( offline )
Posts: 309
Posted: 2009-09-25 13:51
 Post subject: Scaling Joystick values....
I am late to dinner, but I had some thoughts about the discussion of scaling the joysitck values. Kurte originally said, "...I believe we found that these joysticks maybe had a range of 392-692 (~300 values)...". This could be expressed in 9 bits, not 10. Scaling from 9 bits instead of from 10 bits would lose much less precision, wouldn't it?

* The raw range would require 10 bits admittedly.
* Simply subtracting the minimum value results in a range of 0-300 (expressible in 9 bits) with 300 possible values.
* Then performing an integer divide by 300 (the upper limit) results in a range of 0-255 (8 bits) and 256 possible positions.
* Scaling the entire range from 10 bits to 8 bits results in a range of 144-255 with only 111 possible positions.

So in this example, expressed in MS Excel formulas,
ScaleDown = int(255*((position - 300)/300))
ScaleUp = int(300*(value/255))+392

Am I missing something?

Expert ( offline )
Posts: 628
Posted: 2009-09-26 15:36
When scaling you always want to trim the unused portions(indicated by your minimum value) and then scale using the max range(max value-min value). So given 392 to 692 first subtract 392 and then do your scaling.

value = ((value - 392)*256)/(692-392)

will give you the best posible scaling for this particular range of values. With this you will get the full 256 position resolution of your byte.

To do the reverse:

value = ((value*(692-392))/256)+392

So you had the ScaleUp part nearly right. Remember you are dealing with a byte which has 256 possible values, not 255.

Also the order in which you multiply/divide integers for scaling should ALWAYS be multiply first and then divide. With integer numbers you will lose precision if you divide before multiplying.

Guru ( offline )
Posts: 4942
Posted: 2009-09-27 17:51
Thanks Nathan,

Yep, my calculations are similar to what you mentioned. They look like:
Code:
bPacket(2) = (((((sums(0) + SumOffsets(0)) min (AToDMins(0)*8)) / 8) - AToDMins(0)) * 256) / AToDRanges(0)

They are a little more complicated as I now have stored away both the minimum for the joystick or slider, and also the Range, which is equal to the Max - Min + 1 as both value are inclusive.

Also we have the sums where are equal to the last 8 samples for the item and we are also trying to take the center point into account. That is while we wish the center point to 0x80, we may be off by a little...

I have been playing around with the code over the weekend. Now when you press the D key on the keypad it has two different display modes (Not quite implemented yet), plus a page that allows you to hit 1-9 to choose the destination robot (DL in Xbee 1 talk). Soon I will change this to probably allow you to enter in hex a full 16 bit address for DL. Also have a second config page, that allows you to Move both joysticks the full ranges as well as the sliders and then when you hit a key it will save the mins/maxs for the joysticks in the EEPROM of the BAP, such that each receiver can be configured properly.

I need to work on improving the communication reliability next, which maybe I am timing out too quickly... May also try bumping up to 57.6K or Could try the 114...

Things on my todo list:
1) Finish being able to set My and DL on Remote. Change the connect message from Remote to have it's My sent to robot to use. Also make them both be able to set full 16 bit address. I have not done yet as I am using "D" key to cycle pages... May break down and do hardware upgrade to add 1 or more switches to DIY receiver Could be simple 1 switch 1 IO, or could try muliple switches (Gun buttons...), could try to hang them off of 1 IO with Rows or Cols in reading keypad, or maybe different resistors and using different voltages with AtoD to know which switch(s) have been pressed...

2) Finish implementation of Send data only when it changes. things like:
a) Robot sends packet saying: I want only data when it changes. Also use a deadband of X for each of the joystick values...
b) Transmitter keeps track if data changes and sends out a simple packet telling user it changed.
c) When Robot wants the data it can ask at any time regardless of data change or not. (ie it may want to ask every second for data just to make sure that the receiver did not go away...)

3) Finish implementing Second page of output on the Remote: Maybe first line shows what if anything has changed (sliders/joystick), 2nd line shows Info returned from Robot.

4) Maybe add a page that allows me to addjust the servo offsets that I save in the Brats BAP EEPROM. I had a PS2 program that allowed me to adjust the servos, but maybe merge into my MechBratXbee so I can configure that brat to be in Offsets mode and use joysticks to adjust...

5) I am currently setting some values on the XBEE like its MY, Descriptive Name, Baud rate, command timeout, ... using a USB adapter I plug into my PC, using the DIGI utility X-CTU. I will probably write a Quick and Dirty simple application that runs on the BAP to set these, as maybe you don't have this ability.

6) Probably seperate out some of the XBEE Robot code into a self contained file that makes it easier to integrate into other robots. WIll probably add to my Hex or Rover...
...
When this will all get done? Good question. Depends on whatever else I decide to do as I am doing it just for fun!

Kurt

P.S - If anyone is interested, maybe I should try out the new file upload capabilities of the forum and upload my incomple sources...

Guru ( offline )
Posts: 4942
Posted: 2009-09-28 16:25
A short update, from the previous post. I think I have the communication handshaking working better now. I now have the two different versions of the display working (at least the first part). I will now implement some of the protocol for the robot to send information back. I also updated my MechBrat code some, need to work on the directions it walks when I move the joystick...

For the fun of it I uploaded the current snapshot of these two files. They are not complete yet, but this way if I totally screw up, I can at least come back to these

Guru ( offline )
Posts: 4942
Posted: 2009-10-06 12:05
I am thinking about adding a few switches to my DIY Xbee receiver to allow me to be used to wonder through configuration screens. Things like next page, cancel, OK... I am thinking about using one of the analog inputs to handle this and as such try a resistor ladder. I am thinking about hooking it up something like what was mentioned in a thread on Trossen roboticshttp://forums.trossenrobotics.com/showthread.php?t=1284&page=2&highlight=button+resistor.
If you go with the diagram by clavis that is about 2/3 the way in this page, where each switch is connected to +5V and then goes through a different resistor (r1-rn) and then there is a resistor that goes to ground (r0). So each switch sets up a differnt voltage divider.

If I remember my resistor stuff, if one button is pressed then the voltage out should be: Vout = Vin * (R0/(r0+r1))

So assuming three switches and using some resistors I have on hand: Lets say R0=1K, r1-r3=(1K, 5.5K, 10K) and Vin = 5v, I would have for the three switches

V1 = 5 * (1k/(1k+1K)) = 2.5V -> AtoD = 512
v2 = 5 * (1/(6.5)) = .769v -> Atod = 157
v3 = 5 * (1/11) = .45v -> AtoD = 93

I think from looking at this I can choose some better values. Also If I remember my resistor stuff well, if two switches are pressed, we end up with two resistors in parallel. The equivlent resistance for two in parallel = 1/rt = 1/r1 + 1/r2 -> Rt = R1*R2(R1+R2)

So if I use my resistor values from before and lets say we press S1+S2, we would have: R12 = (1K*5.5K)/(1K+5.5K) = 846
R13 = (1k*10k)/11k = 909
R23 = (5.5K*10k)/15.5K = 3550.

I could do the math again here to convert to AtoD values. The question is, does this look correct? Has anyone done this and if so what resistor values worked well for you?

Thanks
Kurt

Guru ( offline )
Posts: 9256
Posted: 2009-10-06 12:43
skimmed over the thread. I'm going to try to select some values that work better. Will try...

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...

Guru ( offline )
Posts: 4282
Posted: 2009-10-06 14:00
Kurt,

That's certainly a way to do it. Do you have an extra pin? Why not use a panel shaft encoder? It would allow you to spin through selections. Can even be done with a single pin, if you are willing to accept scrolling only in one direction (not bad). And I seem to recall that you have code already for the encoder!

I didn't work them out, but your resistors would probably be OK. R-2R ladders are commonly used. Might even be able to buy an R-2R package? Seems I saw/used one somewhere.

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/

Guru ( offline )
Posts: 9256
Posted: 2009-10-06 14:02
I drew up this little schematic. I forgot to label R0.
Attachment:

schem01.jpg [ 22.11 KiB | Viewed 1121 times ]

The problem with your resistor choices is the actual output from the voltage divider.

I changed your 5.5k resistor to a 4.7k standard value.

R0 = 1k
R1 = 1k
R2 = 4.7k
R3 = 10k

Sw1 closed 2.5vdc
Sw2 closed .88vdc
Sw3 closed .45vdc

There's not much difference between Sw2 and Sw3.

I'm still working on the actual values.

Edit: added resistor values.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...

Guru ( offline )
Posts: 9256
Posted: 2009-10-06 14:05
KM6VV wrote:
Kurt,

That's certainly a way to do it. Do you have an extra pin? Why not use a panel shaft encoder? It would allow you to spin through selections. Can even be done with a single pin, if you are willing to accept scrolling only in one direction (not bad). And I seem to recall that you have code already for the encoder!

I didn't work them out, but your resistors would probably be OK. R-2R ladders are commonly used. Might even be able to buy an R-2R package? Seems I saw/used one somewhere.

Alan KM6VV

R2R setups require the "inputs" to switch from 5vdc and ground. There is no way to do this with single throw switches. We're only needing three switches to do a simple LCD menu navigation system.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...

Guru ( offline )
Posts: 4282
Posted: 2009-10-06 14:22
I see. Seems most of the little toggle switches I get are SPDT. But maybe you're using push buttons?

The push buttons would probably be less expensive then a small panel shaft encoder.

You could also just do "up" and "down" push buttons. Use the third PB for "enter".

I've seen both, individual PBs next to menu items on an LCD, and a pair of up/down PBs as well.

Here's an example commercial product that actually uses BOTH:

http://www.cirris.com/cable/tester/1100r.html

You probably don't need both!

Just some ideas for you.

Alan KM6VV

Robot Dude wrote:
R2R setups require the "inputs" to switch from 5vdc and ground. There is no way to do this with single throw switches. We're only needing three switches to do a simple LCD menu navigation system.

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/

Guru ( offline )
Posts: 9256
Posted: 2009-10-06 16:02
I asked Beth to make me a quick excel sheet so I could quickly substitute resistor values.

If we go with 4 switches. Would allow up down enter exit.

R0 = 5k
R1 = 1.8k
R2 = 3.3k
R3 = 5.6k
R4 = 10k

When each switch is pressed you get.
S1 = 3.68vdc
S2 = 3.01vdc
S3 = 2.36vdc
S4 = 1.67vdc

These values are about 0.67 volts apart. If you only allow a narrow band for each switch and ignore all the rest you should be able to only respond to the 4 switches.

A to D in for 5vdc is 1023. So the values for these resistors would be.
S1 = 753
S2 = 616
S3 = 483
S4 = 342

So if you write the decision like this it should be good.

if S1 >748 and S1 < 758 then...

Of course the true values may be off a bit in the real world.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...

Guru ( offline )
Posts: 4942
Posted: 2009-10-06 16:14
Sounds great. I was about to suggest from the previous version that we try changing R0 to something like 4.7 with the earlier ones of 1, 4.7 and 10 would get us voltages like: 4.1, 2.5, 1.5. But I do like your four switch one. So now I just need to dig into my pile of resistors and get ones that are close!

Kurt

P.S - We could also play around to see what all of the voltages are when multiple switches are pressed, but may not need it in this case...

Guru ( offline )
Posts: 9256
Posted: 2009-10-06 16:54
kurte wrote:
Sounds great. I was about to suggest from the previous version that we try changing R0 to something like 4.7 with the earlier ones of 1, 4.7 and 10 would get us voltages like: 4.1, 2.5, 1.5. But I do like your four switch one. So now I just need to dig into my pile of resistors and get ones that are close!

Kurt

P.S - We could also play around to see what all of the voltages are when multiple switches are pressed, but may not need it in this case...

Just need to make sure that no combination of switches would mimic a different switch press. But it shouldn't be possible. I don;t think it's possible anyway. lol

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...

1, 2, 3, 4, 5, 6 ... 35

All times are UTC - 5 hours [ DST ]. It is currently 2018-06-19 06:08