Board index FlightGear Support Interfacing

Simulink UDP Control Input to FlightGear

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

Simulink UDP Control Input to FlightGear

Postby locknutbushing » Fri Aug 11, 2017 4:44 pm

Hi everyone,

I'm trying to interface FlightGear and Simulink. Essentially, I want to use FlightGear to calculate flight dynamics, and I want Simulink to send control inputs (such as thrust and elevator position) and receive air data back.

Unfortunately, the Simulink Aerospace blockset seems to be built for the exact opposite purpose: Calculating flight dynamics in Simulink and using FlightGear just for visuals. The weirdest thing is that the "Pack net_fdm Packet for FlightGear" block (https://www.mathworks.com/help/aeroblks/packnet_fdmpacketforflightgear.html) forces me to specify even parameters such as longitude, latitude, roll, pitch, yaw and altitude, otherwise it sends zero values for those parameters and the airplane ends up teleporting underwater somewhere at the equator. Which is ridiculous. As a result, it is unusable for control input.

So I was able to get Simulink to receive UDP output from FG using a separate solution, but sending input isn't working. I'm using the UDP Send, Byte Reversal and Byte Pack blocks and I'm getting a Warning: read() not enough bytes error.

Here's my batch file:
Code: Select all
@C:
@cd "C:\Program Files\FlightGear 2016.3.1"

@SET FG_ROOT=data
.\\bin\fgfs ^
  --httpd=5400 ^
  --aircraft=777-200ER ^
  --airport=SBGL ^
  --disable-random-objects ^
  --prop:/sim/rendering/random-vegetation=false ^
  --disable-specular-highlight ^
  --disable-ai-models ^
  --disable-real-weather-fetch ^
  --disable-clouds ^
  --prop:/sim/frame-rate-throttle-hz=60 ^
  --fog-disable ^
  --geometry=1024x768 ^
  --bpp=32 ^
  --offset-distance=0 ^
  --altitude=0 ^
  --heading=100 ^
  --offset-azimuth=0 ^
  --log-level=debug ^
  --prop:/sim/rendering/multithreading-mode=DrawThreadPerContext ^
  --native-fdm=socket,out,30,127.0.0.1,5502,udp ^
  --generic=socket,in,30,127.0.0.1,5500,udp,control


And here's my protocol file (in data/Protocol):
Code: Select all
<?xml version="1.0"?>
<PropertyList>
    <generic>
        <input>
            <binary_mode>true</binary_mode>
            <!--binary_footer>magic,0x12345678</binary_footer-->
            <chunk>
                <name>throttleright</name>
                <type>double</type>
                <node>/controls/engines/engine</node>
            </chunk>
            <chunk>
                <name>throttleleft</name>
                <type>double</type>
                <node>/controls/engines/engine[1]</node>
            </chunk>
            <chunk>
                <name>elevator</name>
                <type>double</type>
                <node>/controls/flight/elevator</node>
            </chunk>
       <chunk>
                <name>aileron</name>
                <type>double</type>
                <node>/controls/flight/aileron</node>
            </chunk>
       <chunk>
                <name>flaps</name>
                <type>double</type>
                <node>/controls/flight/flaps</node>
            </chunk>
       <chunk>
                <name>AP</name>
                <type>bool</type>
                <node>/instrumentation/afds/inputs/AP</node>
            </chunk>
       <chunk>
                <name>actual-target-altitude</name>
                <type>double</type>
                <node>/autopilot/settings/actual-target-altitude-ft</node>
            </chunk>
       <chunk>
                <name>counter-set-altitude</name>
                <type>double</type>
                <node>/autopilot/settings/counter-set-altitude-ft</node>
            </chunk>
            <binary_footer>none</binary_footer>
        </input>
    </generic>
</PropertyList>


Has anyone managed to get this to work before?
locknutbushing
 
Posts: 6
Joined: Fri Jul 21, 2017 7:09 pm

Re: Simulink UDP Control Input to FlightGear

Postby locknutbushing » Wed Aug 16, 2017 2:46 pm

And that's why I switched to X-Plane. Thanks, guys.
locknutbushing
 
Posts: 6
Joined: Fri Jul 21, 2017 7:09 pm

Re: Simulink UDP Control Input to FlightGear

Postby wkitty42 » Thu Aug 17, 2017 8:11 pm

what is why you switched? lack of responses? we're all volunteers, here... i'd guess that someone with the knowledge you seek simply hasn't been around and seen your topic, yet... i know of at least two FG developers that are on vacation until the end of the month... maybe folks (not you personally) are too impatient?
"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: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: Simulink UDP Control Input to FlightGear

Postby drR0ckso » Thu Aug 24, 2017 6:03 pm

Did you look for relevant articles in the wiki? This is a software package with a long history, and no less than three different locations for information: the forums, the wiki, and the mailing lists.
I speak only for myself.
drR0ckso
 
Posts: 37
Joined: Fri May 12, 2017 4:14 am


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 1 guest