This is a sample of a binary protocol for Flightgear written in C++ with the purpose of controlling via Arduino (or CLI) the Cessna C172P Model.
DISCLAMER: I'm working on Ubuntu 18.04, and this repo is developed with Linux-only in mind.
Tested with Flightgear version: 2018.3.1. Using Arduino NANO.
- Clone this repository:
$ git clone https://github.com/danieleperot/fgfs-binary-protocol.git
- CD into the repository and build the executables:
# Build the client executable (control FlightGear through CLI)
$ make client
# Build the serial executable (control FlightGear through Arduino)
$ make seria
- Copy the generic protocol file
binary-protocol.xml
into the Protocol folder of Flightgear:
# Flightgear main folder ($FG_ROOT) is usually /usr/share/games/flightgear
# You might need to be root to execute this command!
$ cp ./binary-protocol.xml /usr/share/games/flightgear/Protocol/
# There is also a make option with the default $FG_ROOT folder
$ make copy-protocl
- Run Flightgear:
- Are you using the GUI? Click on
Settings
and add the following line underAdditional Settings
:
--generic=socket,in,1,,10540,udp,binary-protocol
- Are you using the CLI version? Execute this command:
$ fgfs --generic=socket,in,1,,10540,udp,binary-protocol
- Are you using the GUI? Click on
- Run the executable
# In the repository folder
$ ./client
# or
$ ./serial
If you want to use Arduino, build a prototype following this schematic:
You can find the sketch in arduino-protocol
.
The protocol is a binary protocol working on a UDP Socket on the port 10540.
You can change the port by going inside serial.cpp
or client.cpp
and changing the following line:
// From
FlightGear* flightgear = new FlightGear(10540);
// To
FlightGear* flightgear = new FlightGear(/* Your port number */);
Then change the port number in the --generic
string as well.
# From
--generic=socket,in,1,,10540,udp,binary-protocol
# To
--generic=socket,in,1,,[Your Port Number],udp,binary-protocol
Inside serial.cpp
, simply add the string of the USB port to the ArduinoConnect constructor:
ArduinoConnect *arduino = new ArduinoConnect("/dev/ttyUSB0");
Be aware that I'm not a real C++ developer, so don't get too scared on what you will see!
Feel free to fork and modify this repository as you need.
I'm actually happy to learn from other people, so don't esistate to share with me your ideas =)