Pages: [1]   Go Down
Author Topic: Streaming Serial Data into Arduino  (Read 933 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok so i am working on a robot controller, i have a labview program that is reading the values of my controllers (the axis info, the button info etc) and it is streaming it threw a virtual com port, to a WIFly Modual (RN-XV WIFLY modual) witch is than sending the data to the arduino mega serial 1. this data is getting sent at the highest speed possable, and it is always being sent.

my question is: I have a never stopping separated values comming in to the arduino, but i want to be able to use the data at the same time to limit the delay to a minimal level.

EX of the data comming in "255,128,128,0,0,128,0,0,0,0,0,0,0,0,0,0,0;" the first six values are numbers between 0-255, they are 2 joysticks. the next 11 values are 0 or 1 for 11 buttons.

so what is the most efficient way of parsing the data and driving the motors and accessories while still trying to keep real time control?
Logged

0
Offline Offline
Tesla Member
***
Karma: 147
Posts: 9741
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so what is the most efficient way of parsing the data and driving the motors and accessories while still trying to keep real time control?

Do you have some type of delimiter to indicate the start/stop of each data packet stream?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ya to end each value there is a comma, and at the end of one stream there is a semicolon.

but right after the semicolon gets sent the next set of values gets sent
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8975
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thing I would suggest is to only send data when it changes.  That way you get better responsiveness because you don't have to wait for data that isn't needed.

Second thing is to send binary rather than text so it doesn't have to be converted back.

If each data byte contains address information then you don't need to provide framing.

You have 43 bits you want to send:  4*8 for joysticks and 11 for buttons.  You can break those into blocks of 4 bits and use the other 4 bits in the byte to specify which block of data:

0X: Joystick axis 1 High Four Bits
1X: Joystick axis 1 Low Four Bits
2X: Joystick axis 2 High Four Bits
3X: Joystick axis 2 Low Four Bits
4X: Joystick axis 3 High Four Bits
5X: Joystick axis 3 Low Four Bits
6X: Joystick axis 4 High Four Bits
7X: Joystick axis 4 Low Four Bits
8X: Buttons 0-3
9X: Buttons 4-7
AX: Buttons 8-11
BX: Spare
CX: Spare
DX: Spare
EX: Spare
FX: Spare

As each byte arrives the Arduino places the low four bits in the correct location based on the high four bits and then calls whatever function handles that data item.

One problem is that sending a joystick axis as two parts might cause glitches as the joystick moves since it might be acting on the left half of a new value combined with the right half of the old value.  Fix this by having the sending program always send the low half if the high half changes and have the Arduino only act when the low half arrives.  Small changes that only change the low half will remain efficient and large changes are likely to change both halves anyway so little efficiency is lost by sending both.

If the data might get lost along the way you can have the sending program send out the un-changed values periodically.  Say one joystick value or set of 4 buttons every tenth of a second or so.  That would help assure that both sides have the same current values.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50852
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so what is the most efficient way of parsing the data and driving the motors and accessories while still trying to keep real time control?
If all the values are byte sized, then sending as strings and parsing and converting to ints/bytes is a waste of time. Send the data as binary. Read the binary data. No parsing, no conversion, way faster.
Logged

Pages: [1]   Go Up
Jump to: