Board index FlightGear Support Interfacing

Flight gear mavlink interface

Connecting two computers, using generic protocol, connecting with Matlab?

Flight gear mavlink interface

Postby srinath79 » Wed Apr 23, 2014 6:35 pm

Hi

There is a communication protocol called Mavlink, which can be used to send aircraft state information (position, velocity, attitude) to a GUI.
A serial device (Xbee/Bluetooth)is to transmit these mavlink messages for display on a GUI like QGroundControl.
I would prefer the visualization to be done in flightGear.

So this is what i would like to do
1) Plug in a xbee into the usb port of the groundComputer.
2) Decode and display the mavlink messages it recieves for display in flightGear

Has this been done before?
What is the best way to do this ?
srinath79
 
Posts: 5
Joined: Wed Apr 23, 2014 6:12 pm

Re: Flight gear mavlink interface

Postby Hooray » Wed Apr 23, 2014 6:42 pm

Hi & welcome,

this kind of thing would typically be implemented in either of two ways:

  • a separate/standalone program acting as a proxy between FlightGear and your hardware/telemetry
  • directly modifying FlightGear by adding support for the required I/O protocols

The latter obviously requires being able to build from source, and knowing sufficient C++.

Regarding #1, you'll want to look at existing I/O means and see if/how they could be reused/adapted to be useful, see for example: viewtopic.php?f=36&t=10173

If this involves any form of USB devices that are currently not supported by FlightGear, there's also the pending USB/HID-support effort, see: http://wiki.flightgear.org/USB_HID_Support

For FlightGear as a project it would obviously be better to identify building blocks required to pull this off and then augment/extend the simulator accordingly.
On the other hand, a more modular approach may be easier to implement initially, especially for people new to FG, new to C++ - who may already have experience doing this sort of thing outside FG.

If you'd like to see additional suggestions posted, please provide some details on the hardware/transport mechanisms, protocols and message formats involved.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Flight gear mavlink interface

Postby srinath79 » Wed Apr 23, 2014 7:43 pm

Hi

Thanks for the links
I think i will go with option 1 first.
Since i want to just use flight gear for display, i would be sending lat/lon/alt/Vn/Ve/Vd/roll/pitch/yaw/angular rates and accelerations

After reading the file README.protocol, it appears i need to create an xml file as detailed here
https://gitorious.org/fg/fgdata/source/ ... otocol#L13
And classify all the variables listed above as inputs.

Is that the right approach ?
srinath79
 
Posts: 5
Joined: Wed Apr 23, 2014 6:12 pm

Re: Flight gear mavlink interface

Postby Hooray » Wed Apr 23, 2014 7:55 pm

it depends, there are several I/O options - the generic protocol requires an XML file like you say, see: http://wiki.flightgear.org/Generic_Protocol

For the sake of simplicity, you could also use the props/telnet protocol, which simply requires a TCP connection, and you can run commands to get/set properties directly - i.e. using less than 10 lines of code (python/perl etc): http://wiki.flightgear.org/Telnet_usage

Another option is a web-based protocol, recently we also have support for AJAX/web sockets.

Personally, I would probably go with telnet for starters, just because it is so straightforward - and because it supports polling, but also subscription-based notifications

The generic protocol can be also extended to do similar things, but requires a fair amount of scripting space workarounds

And do note that you'll typically want to explicitly disable controls/fdm to pull this off, as in sync'ing multiple instances, see for example: http://wiki.flightgear.org/Property_Tre ... ol_Slaving

You may want to test how this works: http://wiki.flightgear.org/Slaving_for_Dummies
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Flight gear mavlink interface

Postby srinath79 » Thu Apr 24, 2014 2:03 am

I just remembered that Simulink(part of Matlab) has a flight gear interface, that basically does this.
First it starts flightGear with the following options
#! /bin/csh

cd C:\Program Files\FlightGear

#setenv LD_LIBRARY_PATH C:\Program Files\FlightGear/lib:$LD_LIBRARY_PATH
#setenv FG_ROOT C:\Program Files\FlightGear/data
#setenv FG_SCENERY C:\Program Files\FlightGear/Scenery:$FG_ROOT/Scenery:$FG_ROOT/WorldScenery

fgfs --aircraft=HL20 --fdm=network,localhost,5501,5502,5503 --fog-fastest --disable-clouds --start-date-lat=2004:06:01:09:00:00 --disable-sound --in-air --enable-freeze --airport-id=KSFO --runway=10L --altitude=7224 --heading=113 --offset-distance=4.72 --offset-azimuth=0

Then it has a net_fdm packet for flightgear which sends FG the data in the format that it requires.

If i start FG with the above options(a lot of the options like airport etc are redundant for me), i guess i would just need to have a middleware(not Matlab) that packs data in the fright format.
Where can i find more details about the net_fdm packet ?
srinath79
 
Posts: 5
Joined: Wed Apr 23, 2014 6:12 pm

Re: Flight gear mavlink interface

Postby Hooray » Thu Apr 24, 2014 2:34 am

srinath79 wrote in Thu Apr 24, 2014 2:03 am:If i start FG with the above options(a lot of the options like airport etc are redundant for me), i guess i would just need to have a middleware(not Matlab) that packs data in the fright format.
Where can i find more details about the net_fdm packet ?


It's always a good idea to search the forum and the wiki prior to asking:

http://wiki.flightgear.org/Property_Tree/Sockets
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Flight gear mavlink interface

Postby robotop » Tue Jun 15, 2021 10:13 am

Hi, did you finally make this work?

I am working in the same case, but now I only can test in SITL (using Ardupilot with FG).

I tought that Ardupilot was sending MAVLink messages to FG (and my GroundStation) and I only need to run a command like "fgfs --generic=socket,out,20,,5503,udp,MAVLink" (I had previously installed FG, copy the MAVLink.xml in the Protocol path and give permissions to the path). As I said I was testing as SITL, all running in my laptop. ¿This should work for catch MAVLink messages from a real drone and paint it in FG?

Thanks.
robotop
 
Posts: 1
Joined: Tue Jun 15, 2021 9:59 am

Re: Flight gear mavlink interface

Postby kwikius » Tue Jun 15, 2021 3:44 pm

robotop wrote in Tue Jun 15, 2021 10:13 am:Hi, did you finally make this work?

I am working in the same case, but now I only can test in SITL (using Ardupilot with FG).

I tought that Ardupilot was sending MAVLink messages to FG (and my GroundStation) and I only need to run a command like "fgfs --generic=socket,out,20,,5503,udp,MAVLink" (I had previously installed FG, copy the MAVLink.xml in the Protocol path and give permissions to the path). As I said I was testing as SITL, all running in my laptop. ¿This should work for catch MAVLink messages from a real drone and paint it in FG?

Thanks.


Note that Flightgear directory and Mavlink.xml doesnt appear to be available in latest ardupilot source code, so it doesnt seem to be supported any more.

ArduPilot uses Mavlink to communicate with ground station, but ArduPilot runs FlightGear only as a Viewer, meaning that ArduPilot sends attitude and location commands to FlightGear using FlightGear's own protocol and then FlightGear just places the aircraft where it is told to. However ArduPilot uses socket not Mavlink to send data, but it would be quite easy to make a Mavlink parsing app to do it. All that is required is to parse mavlink data, fill in the FlightGear FGNetFDM structure
and then send that to FlightGear via --fdm=external --native-fdm=socket,in... protocol.

This app could easily be modified to parse the Mavlink commands and use them to fill the structure.

(N.B The code in the mavlink parsing link is quite old. There is a new version of MavLink since then!)
kwikius
 
Posts: 7
Joined: Fri May 28, 2021 10:24 pm


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 5 guests