danieleperot / fgfs-binary-protocol

A C++ UDP Binary protocol for Flightgear
4 stars 2 forks source link

Changing the code to receive data from the simulator #1

Open brightproject opened 4 months ago

brightproject commented 4 months ago

Hello @danieleperot I understand that the project is outdated and is no longer supported by you, but could you suggest, perhaps by analogy with your code, to receive data from flightgear via the serial port in arduino? Did you do this, or did you just send data to the simulator?

danieleperot commented 3 months ago

Hi there! Thanks for reaching out, and sorry for the delay :) As you mentioned I'm not really working on this any longer, mostly cause it was just a one-day project (almost ;) ) to see if I could get some controls on Arduino to connect to FGFS.

I would have loved to do bi-directional communication, but at the time I had no idea how to implement that in a nice way. I was thinking either to have two serial connections, or perhaps implement some kind of protocol for which every time Arduino would send a packet to me, I would be able to send back to Arduino some data about FGFS (maybe for displaying radios or for some forced feedback, stuff like that).

I think this would be quite wasteful though. Instead of just exchanging fixed size data packets, I think it would be better to exchange messages. I originally implemented fixed size packages as the binary protocol from FGFS to my program also worked that way, but I guess we could communicate with messages instead?

What were you thinking?

brightproject commented 3 months ago

What were you thinking?

I needed a way to get data from the FlightGear simulator. I was looking for various options and that’s how I actually found your project. But your code only sent data to the simulator, I needed the inverse task, and I thought that this could be done by analogy. In the end, I did it easier, using the generic protocol. I created a protocol *xml file in the folder, I indicated to the simulator what data I need to transfer to the com port, also known as the serial port. And using the console command I ran: fgfs --generic=serial,out,150,\\.\COM15,230400,insgns-imu2 I already receive this data using USB-TTL and submit it to the RX input of the STM32F411 microcontroller. On which the code program with the serial port parser runs. I needed to receive raw data from gyroscopes and accelerometers in order to process fusion algorithms on a microcontroller, similar to mems sensors. So far everything seems to be working out as planned. The video shows not just a duplication of orientation angles from the simulator, but actually a real-time calculation of angles inside an aircraft instrument.

https://github.com/danieleperot/fgfs-binary-protocol/assets/1788098/4b58e536-cb60-446c-aa3b-6ae3fd4fed18

In the future, there are plans to rewrite your code to output data from their simulator, and wrap it all in a library. Thanks for your response.