State overlay system

From FlightGear wiki
Jump to navigation Jump to search

Using the state overlay system, aircraft developers can add startup state overlays to an aircraft, that users can select when starting FlightGear.

Choosing a startup state

To start FlightGear with an existing state overlay add --state=statename to you command line.

In the launchers main tab, you can choose which state you want to start with:

States dropdown box in launcher

If you choose the Automatic state, FlightGear will try to guess which state you want.

That guess is based on the name (inside the state file). It will look for these names:

  • parked (meaning cold and dark)
  • take-off (standing on the runway with take-off configuration)
  • cruise (cruise configuration)
  • approach (approach configuration)
  • carrier-approach (approach configuration for an aircraft carrier landing)
  • carrier-take-off (take-off configuration for an aircraft carrier take-off, typically via catapult)

Implementing state overlays in an aircraft

Create state overlay files

To add state overlays to your aircraft, create a folder for example called States. In there you can put your state overlay files. In the beginning a state overlay file should look like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PropertyList>
  <name type="string">parked</name>
  <readable-name type="string">Parked</readable-name>
  <description type="string">Parked, cold and dark.  Everything switched off</description>

  <overlay>

  </overlay>
</PropertyList>

Now you can add your properties and values, which need to be set between the overlay tags. You only need to put properties in there that differ from your default setup. You should use the hierarchy of the root of the property tree.

Copying the property tree from the Nasal console

Note  This outputs the entire PropertyTree! This is several thousand lines long. You might want to dump only single folders of the property tree by changing the "/" to something like "/controls" or whatever folder you want to dump.

It is possible to dump the PropertyTree with a Nasal command. Open up the Nasal console from the developer menu and put in the following:

io.write_properties( path: "/home/myName/.fgfs/Export/PropTree.xml", prop: "/" );

Now you can simply delete everything from that file that you do not need and copy and paste it into your state overlay file.

Include state overlay files into the Aircraft-set.xml file

Now you need to include your state overlay file in your Aircraft-set.xml file like this:

<PropertyList>
  <sim>
    ...
    <state include="States/parked-overlay.xml" n="0" />
    <state include="States/taxi-overlay.xml" n="1" />
    ...
  </sim>
</PropertyList>

YASim aircraft

For YASim Piston Prop aircraft, two properties need to be set to have an engine running on startup:

  • /engines/engine[0]/rpm=1000
  • /controls/engines/engine[0]/magnetos=3

This ensures the engine is turning sufficiently quickly and the magnetos are switched on. You may also want to ensure you have any fuel taps on.

By default, YASim will attempt to set the gear state (/control/gear/gear-down) depending on whether the aircraft is on the ground or in the air. To over-ride this behaviour and ensure that whatever you set in the overlay file is respected, set /fdm/yasim/respect-external-gear-state=true.

So the following skeleton can be used for runway, cruise and approach overlays

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PropertyList>
  <name type="string">Approach</name>
  <readable-name type="string">Approach</readable-name>
  <description type="string">Approach configuration</description>

  <overlay>
    <controls>
      <engines>
        <engine n="0">
          <magnetos>3</magnetos>
        </engine>
      </engines>
    </controls>
   
    <engines>
      <engine n="0">
       <rpm>1000</rpm>
      </engine>
    </engines>

    <fdm>
      <yasim>
        <respect-external-gear-state type="bool">true</respect-external-gear-state>
      </yasim>
    </fdm>

  </overlay>
</PropertyList>

JSBSim Aircraft

/sim/presets/running=true should set the engines running (see FGJSBsim::init() in FDM/JSBSim/JSBSim.cxx). However, from observation this appear unreliable for reciprocating engines.

The overlay state is written to /sim/aircraft-state, and can be used to trigger autostart in appropriate circumstance (e.g. take-off, cruise, approach)

Background

Wayne Bragg has been working a bit with James on the state overly system.[1]

At this moment, the Citation, the Saab 37 Viggen, the J3 Cub, the Cessna 182s and the Tu-144 have this implemented.

References

References

Related content

Source code