Board index FlightGear Support Interfacing

Howto: launch a simulation from simulink .bat file  Topic is solved

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

Howto: launch a simulation from simulink .bat file

Postby g_don.24 » Sun May 23, 2021 12:52 pm

Hi guys!
I want to run a FG simulation by using my simulink project in which I've used "FlightGear Preconfigured 6DoF Animation" block and the "Generate Run Script (for FligthGear simulation)" block. The problem is that I've installed aircraft and sceney within a custmoized folder at this path: "D:\FlightGear\Downloads". Here I've the two folders: "Aircrfat","TerraSync".
In "TerraSync" i've downloaded the airport "LIRN", instead in the first folder I have the Mig-29 (D:\FlightGear\Downloads\Aircraft\org.flightgear.fgaddon.stable_2020\Aircraft\Mig-29).
How I can generate the runscript file (.bat) in order to use the Mig-29 and LIRN airport or, in general, aircraft and scenery stored in my download folder (D:\FlightGear\Downloads).

This is the default .bat file in which I've used the deafult aircraft c172p and the LIRN airport but it has been downloaded again and saved in the path "C:\Users\peppe\FlightGear":
-------------------------------------------
Code: Select all
D:

cd D:\Programmi HDD\FlightGear 2020.3

SET FG_ROOT=D:\Programmi HDD\FlightGear 2020.3\data
.\\bin\fgfs --aircraft=c172p --fdm=null --native-fdm=socket,in,30,localhost,5502,udp --fog-fastest --disable-clouds --start-date-lat=2004:06:01:09:00:00 --disable-sound --in-air --enable-freeze --airport=LIRN --runway=24 --altitude=0 --heading=0 --offset-distance=0 --offset-azimuth=0 --prop:/sim/rendering/shaders/quality-level=0

-----------------------------------------------

This is the default setting of the "Generate Run Script (for FligthGear simulation)" block:
Image

Image
g_don.24
 
Posts: 12
Joined: Sat May 15, 2021 12:57 pm

Re: Howto: launch a simulation from simulink .bat file  

Postby Hooray » Mon May 24, 2021 8:31 am

g_don.24 wrote in Sun May 23, 2021 12:52 pm:Hi guys! I want to run a FG simulation by using my simulink project in which I've used "FlightGear Preconfigured 6DoF Animation" block and the "Generate Run Script (for FligthGear simulation)" block. The problem is that I've installed aircraft and sceney within a custmoized folder at this path: "D:\FlightGear\Downloads". Here I've the two folders: "Aircrfat","TerraSync".
[...]
How I can generate the runscript file (.bat) in order to use the Mig-29 and LIRN airport or, in general, aircraft and scenery stored in my download folder (D:\FlightGear\Downloads).


You can either set environment variables ($FG_SCENERY and $FG_AIRCRAFT) for your custom folders or edit the bat file to add the corresponding --fg-scenery= and --fg-aircraft= options there. See fgfs --help --verbose for details

https://wiki.flightgear.org/Command_lin ... al_Options
Code: Select all
--fg-scenery=path[:path...]  Specify the base scenery path;
                               Defaults to $FG_ROOT/Scenery
--fg-aircraft=path           Specify additional aircraft directory path(s)
                               (alternatively, you can use --aircraft-dir to
                               target a specific aircraft in a given
                               directory)


For the Mig-29/LIRN respectively, edit the batch file to pass --aircraft=Mig29 (didn't check if that's the correct name) and --airport=LIRN

https://wiki.flightgear.org/Command_line

Alternatively, you can also use one of the launchers to see how it builds the startup string and then copy/reuse that one :wink:
Obviously, you could also copy the relevant options from the batch file into your favorite launcher 8)
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: Howto: launch a simulation from simulink .bat file

Postby g_don.24 » Wed May 26, 2021 9:09 am

Thanks very much, I've solved the problem related to the aircraft but I've a problem about the scenery.
I try to explain better...
The following one is the new .bat file:
Code: Select all
D:
cd D:\Programmi HDD\FlightGear 2020.3

SET FG_ROOT=D:\Programmi HDD\FlightGear 2020.3\data
.\\bin\fgfs --fg-aircraft=D:\FlightGear\Downloads\Aircraft\org.flightgear.fgaddon.stable_2020\Aircraft --aircraft=Mig-29 --fdm=null --native-fdm=socket,in,30,localhost,5502,udp --fog-fastest --disable-clouds --start-date-lat=2021:06:01:09:00:00 --disable-sound --in-air --enable-freeze --terrasync-dir=D:\FlightGear\Downloads\TerraSync --lat=40.883561 --lon=14.2891 --altitude=5000 --heading=0 --offset-distance=0 --offset-azimuth=0 --prop:/sim/rendering/shaders/quality-level=5


Here I've spcified the path of the aircraft (and it works) and the path of the Terrasync data.
When I run the .bat file, it correctly shows the aircraft and the scenery, as you can see in the following image:
Image

The problem is when I run the simulation in the simulink project: here the scenery is completely different, as shonwn in the following image:
Image

I've integrating the equation of motion by setting the same initial latitude and longitude of the .bat file. The following one is the simulink project:
https://docdro.id/ATq6rEb.

How can I visualize the correct scenery during my simulation?
Last edited by Johan G on Wed May 26, 2021 9:15 am, edited 2 times in total.
Reason: Please do not quote the entire preceding post.
g_don.24
 
Posts: 12
Joined: Sat May 15, 2021 12:57 pm

Re: Howto: launch a simulation from simulink .bat file

Postby Gijs » Wed May 26, 2021 9:47 am

Hi,

For my understanding, you launch FlightGear with the .bat file and then the aircraft "teleports" to a different location when you run the simulation in Simulink? Does the aircraft move at all (i.e., is the link from Simulink to FlightGear working)?
Can you check in the property browser of FlightGear (press the /-key to open it) whether the values under /position/latitude-deg and /position/longitude-deg match those in Simulink when you run the simulation?

Also note that, instead of
Code: Select all
--terrasync-dir=D:\FlightGear\Downloads\TerraSync

you probably want to use:
Code: Select all
--fg-scenery=D:\FlightGear\Downloads\TerraSync

Because the TerraSync dir may be ignored if you don't have TerraSync enabled (there's no --enable-terrasync in your script).

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

Re: Howto: launch a simulation from simulink .bat file

Postby g_don.24 » Wed May 26, 2021 2:16 pm

Thanks for your prompts but I cannot solve the issue.

This is my updated .bat file:
Code: Select all
D:
cd D:\Programmi HDD\FlightGear 2020.3

SET FG_ROOT=D:\Programmi HDD\FlightGear 2020.3\data
.\\bin\fgfs --fg-aircraft=D:\FlightGear\Downloads\Aircraft\org.flightgear.fgaddon.stable_2020\Aircraft --aircraft=Mig-29 --fdm=null --native-fdm=socket,in,30,localhost,5502,udp --fog-fastest --disable-clouds --start-date-lat=2021:06:01:09:00:00 --disable-sound --in-air --enable-freeze --enable-terrasync --fg-scenery=D:\FlightGear\Downloads\TerraSync --terrasync-dir=D:\FlightGear\Downloads\TerraSync --lat=40.883561 --lon=14.2891 --altitude=5000 --heading=0 --offset-distance=0 --offset-azimuth=0 --prop:/sim/rendering/shaders/quality-level=3


When I run this file everything is ok in the FlightGear window, the problem of the "scenery change" occurs when I press the "Run" button in the simulink model.

The properties browser of FlightGear is:
Code: Select all
 
0: Back
1: Edit
2: [MAKALE UNICOM]
3: [ATC]
4: FG-8224 going around
5: Roger, FG-8224



Edit: I realized that the coordinates passed to FG by simulink are wrong. Is the block "flath earth to LLA" the responsible? How can I fix this?
Last edited by g_don.24 on Wed May 26, 2021 9:12 pm, edited 2 times in total.
g_don.24
 
Posts: 12
Joined: Sat May 15, 2021 12:57 pm

Re: Howto: launch a simulation from simulink .bat file

Postby wkitty42 » Wed May 26, 2021 7:26 pm

g_don.24 wrote in Wed May 26, 2021 2:16 pm:The property browser of FlightGear are:
Code: Select all
 
0: Back
1: Edit
2: [MAKALE UNICOM]
3: [ATC]
4: FG-8224 going around
5: Roger, FG-8224


that's actually one of the chats for artificila ATC... the property browser is accessed easiest by hitting the '/' when in-sim...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Howto: launch a simulation from simulink .bat file

Postby g_don.24 » Wed May 26, 2021 9:56 pm

PROBLEM SOLVED!
I have connected in the right order lat and lon in the FG block inside simulink !
Thanks to everyone for your support.

Image
g_don.24
 
Posts: 12
Joined: Sat May 15, 2021 12:57 pm

Re: Howto: launch a simulation from simulink .bat file

Postby Gijs » Thu May 27, 2021 4:48 pm

Yeah! That's an easy to make mistake, hence my question to check that the values were actually correct in FlightGear :-)
Have fun!

PS: Any chance you can share some more details about your project? Looks interesting!
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9544
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Howto: launch a simulation from simulink .bat file

Postby g_don.24 » Thu Jun 03, 2021 9:32 am

Of course! It's a simulink project developed with some University colleagues during the course of Flight Simulation and Dynamics (Aerospace Engineering) at University of Naples "Federico II".
The overall simulink project is the following one:
Image

We give in input some data, and then auxiliary kinematics equations (Gimbal and navigation equations) are intergated in order to obtain time histories of aircraft attitude and position.
Actually I'm improving my simulation via FG by inserting Aircraft effect as sounds, engine activation, cockipt indicators but this attempt is tricky for me. So I've oponed another topic in this forum: https://forum.flightgear.org/viewtopic.php?f=36&t=39273.
I'd be very happy if you or other forum users could take a look and give me help!
g_don.24
 
Posts: 12
Joined: Sat May 15, 2021 12:57 pm


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 3 guests