Board index FlightGear Support Interfacing

FG and Simulink: Running issue

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

FG and Simulink: Running issue

Postby flyingpanther » Fri May 04, 2018 11:55 am

Hi,

I am working on a visual flight analysis system using Matlab and FG. The idea is to take a flight log and visually see how the vehicle flew using FG.
I have successfully integrated FG with Simulink. However, once I start running FG, day and night starts rapidly changing. It obviously takes some duration of time as day, and night.
I have specified the time of day, time zone, etc, in BAT file. I have played with Simulation Rate and Time Warp. None has helped.
I am using FG 3.1 and Matlab R2015a. And, the input data to Simulink is in the form of a structure.

Any suggestion/idea on debugging this issue?

Thanks.
flyingpanther
 
Posts: 2
Joined: Fri May 04, 2018 8:02 am

Re: FG and Simulink: Running issue

Postby Gijs » Mon May 07, 2018 11:00 am

Welcome!

Sounds like a nice project :-)
How do you feed your data from Matlab to FlightGear? Could you share the contents of your bat file?

Cheers,
Gijs

PS: FlightGear 3.1 is pretty old by now (4+ years). Any particular reason why you cannot update or did you mean 2017.3.1?
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9429
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: FG and Simulink: Running issue

Postby flyingpanther » Tue May 08, 2018 8:47 am

The flight log data is processed in matlab and converted into the form of a struct with time. This data is captured from workspace by Simulink, and processed using components of inbuilt flight gear interfaces. The required data is finally sent to Flight Gear through 'Send net_fdm Packet to FlightGear' block. When the model is run, the aircraft does show the flight, and except for rapid day and night changes, it works fine. I use FG3.1 because that is the compatible version of FG for the version of Matlab that I use.
This is the content of my bat file:

C:
cd C:\Program Files\FlightGear

SET FG_ROOT=C:\Program Files\FlightGear\data
.\\bin\win64\fgfs --aircraft=c172p --fdm=null --enable-auto-coordination --time-match-local --native-fdm=socket,in,30,localhost,5502,udp --fog-disable --enable-clouds3d --timeofday=noon --enable-sound --visibility=15000 --in-air --start-date-lat=2017:02:01:12:12.97:77.59 --enable-clock-freeze --prop:/engines/engine0/running=true --disable-freeze --airport=1Q4 --runway=12 --altitude=2000 --heading=0 --offset-distance=0 --offset-azimuth=0 --enable-rembrandt

I have tried options in 'timeofday', 'start-date-lat', 'clock-freeze', and 'time'.
I'm attaching my simulink model.

Image
flyingpanther
 
Posts: 2
Joined: Fri May 04, 2018 8:02 am

Re: FG and Simulink: Running issue

Postby daveculp » Tue May 08, 2018 9:43 pm

One of the values in the net_fdm structure is called "warp". The code comment says it's "offset in seconds to unix time", however it sounds like the other meaning of "warp" might be what it's really doing. I'd make sure it's getting a zero value.

Also, you have several time-related command line options. Maybe they don't work nicely together? I'd try just using one, like timeofday=noon
User avatar
daveculp
 
Posts: 503
Joined: Sun Feb 24, 2013 1:50 am
Location: Las Vegas, USA
Callsign: DCulp
Version: 2017.3.1
OS: Ubuntu 17.10

Re: FG and Simulink: Running issue

Postby nikmad » Sat Feb 29, 2020 10:30 am

Hi,

I have developed a Simulink model for quadcopter where there is Guidance, Autopilot and Plant (6DOF model). Now I want to replace the Plant in Simulink with Flight Dynamics Model (FDM) in FlightGear (FG). I could not succeed in this. Basically I tried to use FlightGear blocks in Simulink > Aerospace Blockset > Animation > Flight simulator interface. After my Simulink Model runs through Guidance and Autopilot, it generates output of thrusts for 4 rotors and desired angles for elevator, ailerons, rudder. I am now trying to send these variables to FlightGear's FDM and get back the updated plane states such as velocities, accelerations, position, attitude, attitude rates etc. I used the Simulink blocks in the following order-
1. Pack net_fdm Packet for FlightGear
2. Send net_fdm Packet to FlightGear
3. Receive net_ctrl Packet from FlightGear
4. Unpack net_ctrl Packet from FlightGear
But the issue is that the last block "Unpack net_ctrl Packet from FlightGear" does not have a feature to return the plane states - velocities, accelerations, position, attitude, attitude rates etc. It only gives back control variables back. Is there no way to use Guidance and Autopilot in Simulink while using FG's Plant to visualize the flight?
nikmad
 
Posts: 1
Joined: Sat Feb 29, 2020 10:12 am

Re: FG and Simulink: Running issue

Postby Gijs » Mon Mar 02, 2020 10:52 am

Hi Nik,

Welcome! The whole aerospace blockset assumes that you are doing the FDM work in Simulink and only use FlightGear for visualisation; hence the inability to read back aircraft states from FlightGear. What you can do, is create a custom UDP protocol to send data from FlightGear to Simulink and then read that data. See for example the procedures described in https://www.aerosociety.com/media/11530/adil-loya.pdf

Also note that you're not using --fdm=null on FlightGear, as that would bypass FlightGear's FDM completely.

Cheers,
Gijs
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9429
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest