• Welcome to PiBoSo Official Forum. Please login or sign up.
 
August 24, 2019, 05:57:57 pm

News:

World Racing Series beta14 available! :)


UDP Proxy

Started by PiBoSo, July 18, 2018, 04:01:57 pm

Previous topic - Next topic

poupou59890

Quote from: h106frp on November 01, 2018, 09:13:20 pmGot this working to read the data on a remote PC on my LAN via wireless  :)

edit proxy_udp

[params]
enable = 1
port = 30000
;ip = 127.0.0.1:30001; original localhost
ip = 192.168.1.20:30001  ;the IP of the client on the LAN
delay = 1

modify the line below in the original processing code
udp= new UDP(this,PORT_RX,HOST_IP);

to read
udp = new UDP (this,PORT_RX);

very cool  8)  Should be able to make an e-dash using the raspberry pi now



Hi, I am making a simrig for GPbikes and I ave the idea to potentialy lean this rig ...But for now I would like to learn a little bit UDP and everything else in order to know how to read output data from GPbikes,

I have an arduino R3 that I will use, and for now I would like to create the code in order just to see values in realtime but I do not know well arduino and code for that and I do not know UDP protocole at all, so with your helps I understood the code to read values and extract values from matrix in an arduino language but What do I need in order to test that ? Is it possible to use arduino over USB to read UDP data, DO I need wifi or ethernet absolutly to perform that ? Because if the arduino is connected over USB it is good for me because I have in mind to read data from GPbikes thanks to the arduino and send the lean angle to my motor (thanks to arduino too and shields) but for now I just want to test if I can extract porper values from GPbikes....I am a little bit lost with that.

SO if someone can give a little tuto about what do I need to do to connect my arduino to GPbikes UDP data stream and be able to see it than I will be able to use those values and mix them in order to have a right variable for my rig.

Thakns a lot for your help.

D4rw1n

April 18, 2019, 07:24:22 am #31 Last Edit: April 18, 2019, 07:30:13 am by D4rw1n
@poupou: For that, you will need to add an ethernet shield on your arduino and follow that example to capture UDP packets: https://www.arduino.cc/en/Reference/EthernetUDPRead

Another way (cheaper) would be to create a local program (for instance in python) that captures the telemetry data from UDP on the localhost and forward it straight away on the serial port to the arduino.

Keep in mind typical baud rate used on serial com port for arduino is 115200bps.
UDP payload of telemetry being 220bytes by default (more if you enable some options), it's 1760 bits per packet payload.

Dividing 115200 by 1760, you get a max rate of ~65x telemetry snapshots per second (it could even be less as you have some overhead on the serial bus).

So keep this in mind while setting up your proxy_udp.ini file.
I'd lower the frames per second to 50 max. That means 20ms, or 2 hundredths of a second.

Your proxy_udp.ini file should be set as followed:

[params]
(rest of the config as you want)
delay = 2

EDIT: There are higher baud rates values possible on arduino, you might need to check some of following links:
https://forum.arduino.cc/index.php?topic=98364.0
http://forum.arduino.cc/index.php/topic,61381.msg444421.html#msg44442
https://www.quora.com/What-is-the-baud-rate-and-why-does-Arduino-have-a-baud-rate-of-9-600


@Piboso: Thanks for the clarification. Will look at the result and come back if I have more questions.

poupou59890

Thanks for the explaination :) All those words seems from another world to me but I will look into it and try to understand well the concept. SO the easier way is to add a ethernet shield to my arduino, right ? Because If I understood well  the data transfer will be slower (lower amount of data possible..)  due to the restriction of the adruino serial port ? Thanks again for your time. I am a mechanical guy..I dot not use a lot arduino and programation... but I will look into it and try to understand better.

D4rw1n

Yep ethernet shield will enable you to directly get UDP packets to your arduino.

Based on other experiments, you would get a ~3mbits limitation due to arduino's microcontroller. That is more than enough for your application.
Check https://www.reddit.com/r/arduino/comments/9qn2fx/max_transfer_speed_possible_for_the_ethernet_2/

You should find such shield around 5 dollars on aliexpress.

Also, check you private messages ;)

D4rw1n

April 18, 2019, 11:31:05 am #34 Last Edit: April 18, 2019, 11:59:47 am by D4rw1n
@Piboso:
I have updated my code that is pulling matrix elements from the payload with offsets as you have shown in your last post, but I keep getting different angle values between what is given from m_fYaw, m_fPitch and m_fRoll offsets and what I calculate from the matrix.

Example:

Condition: Motorcycle at rest (vertical, stopped).

m_fYaw, m_fPitch & m_fRoll I get:
Yaw: -37.37
Pitch: 1.32
Roll: -2.51

Whilst matrix I get is:

[ 0.79   -0.04   0.61 ]
[ 1.00   0.04    1.32 ]
[ 0.79   -2.51   0.06 ]

Considering that following elements:
[ R11 R12 R13 ]
[ R21 R22 R23 ]
[ R31 R32 R33 ]

are mapped like so:

R11 @offset 73
R12 @offset 85
R13 @offset 97
R21 @offset 77
R22 @offset 89
R23 @offset 101
R31 @offset 81
R32 @offset 93
R33 @offset 105


I'm using these references to calculate angles from the matrix:

http://nghiaho.com/?page_id=846
http://planning.cs.uiuc.edu/node102.html
http://planning.cs.uiuc.edu/node101.html#fig:yawpitchroll

Taking for instance X (roll) with values from the example matrix above:



with R32 = -2.51 & R33 = 0.06, I get 178.63 degrees for Roll (used https://planetcalc.com/7954/).
That does not fit the -2.51 degrees I get from m_fRoll.


See also a screenshot attached with all other values.


I feel I'm missing something somewhere, but can't find what  :o  :-\

EDIT: don't pay attention to suspension length, forgot to multiply it by 1000 (i.e. right now it is displayed in meter unit)

HornetMaX

I really don't think using UDP for that is good idea.

If you want to send GPB data to some hardware it is fair to assume this hardware will be connected to the PC running GPB (e.g. via serial). If that's true, then you don't need to use UDP: just use an output plugin (from which you can directly send the data to the seriel port) or a proxy plugin (that will put the data in a shared memory area that an external program can read and send to the serial port). I'd probbaly use the 2nd approach (proxy pugin + external app).

D4rw1n

I was not expecting to use UDP on very long term, but it has been my easiest way to decode the data so far, compared to shared memory using the DLL/DLO method (I'm a very newbie with that in programming).
Ideally I'd like to read that through Python, and have read it seems doable as well, but haven't spent time enough on learning how to do it though.

However, my intent in last post was mostly to get how to read & understand the rotation matrix values.

HornetMaX

Quote from: D4rw1n on April 25, 2019, 06:16:21 pmHowever, my intent in last post was mostly to get how to read & understand the rotation matrix values.
The problem with rot matrices is always conventions.
So if your app needs to work with a rotation matrix,it's probably easier to create your own one (according to your own conventions) from the roll/pitch/yaw angles.

D4rw1n

At this point, I have honestly no particular purpose in using such matrix for now, but mostly curious to understand how the one given from the telemetry should be read and/or translated.
However, as seen on many websites, it seems a 3x3 rotation matrix should have the same spots for the same axis. I'm still wondering how this one is supposed to be read. but that won't be a blocking milestone in my case as hopefully all axis values are already given in alternative format.

PiBoSo

Quote from: D4rw1n on April 18, 2019, 11:31:05 am@Piboso:
I have updated my code that is pulling matrix elements from the payload with offsets as you have shown in your last post, but I keep getting different angle values between what is given from m_fYaw, m_fPitch and m_fRoll offsets and what I calculate from the matrix.

Example:

Condition: Motorcycle at rest (vertical, stopped).

m_fYaw, m_fPitch & m_fRoll I get:
Yaw: -37.37
Pitch: 1.32
Roll: -2.51

Whilst matrix I get is:

[ 0.79   -0.04   0.61 ]
[ 1.00   0.04    1.32 ]
[ 0.79   -2.51   0.06 ]

Considering that following elements:
[ R11 R12 R13 ]
[ R21 R22 R23 ]
[ R31 R32 R33 ]

are mapped like so:

R11 @offset 73
R12 @offset 85
R13 @offset 97
R21 @offset 77
R22 @offset 89
R23 @offset 101
R31 @offset 81
R32 @offset 93
R33 @offset 105

Please note that the rotation matrix represents three orthogonal unit vectors.
Therefore, all absolute values should be lower or equal to 1.

Please check the offsets you are using to parse the matrix.
"Obviously your ambition outweighs your talent".