Autopilot configuration reference
| Work in progress|
This article or section will be worked on in the upcoming hours or days.
See for the latest developments.
This page serves as a reference for the elements of FlightGear xml autopilot configuration files. It describes all elements available within the autopilot configuration file supported in the bleeding edge CVS sources. Some of the elements may not be available in the current release version of FlightGear. Refer to Howto: Design an autopilot as a guide how to use these elements.
- 1 Structure Of a Configuration File
- 2 Adding a Autopilot Configuration to Aircraft
- 3 Available Elements
- 4 Common Elements Used By All Elements
- 5 filter
- 6 pid-controller
- 7 pi-simple-controller
- 8 predict-simple
- 9 logic
Structure Of a Configuration File
Autopilot configurations live in a separate file, formatted using the well known XML syntax like so many other FlightGear files with a PropertyList node as a root element. A basic skeleton file looks like this:
<?xml version="1.0" encoding="utf8"?> <PropertyList> <params> <controls> <aileron>controls/flight/aileron</aileron> <rudder>controls/flight/rudder</rudder> <elevator>controls/flight/elevator</elevator> </controls> </params> </PropertyList>
Note: Using aliased property names is good style and makes the configuration file more readable. For complex autopilot systems spread over multiple autopilot configuration files, the params section may be included from an external file using <params include="my-params.xml"/> to avoid duplication of code.
The location and the name of the configuration file is up to the developer. A descriptive name like 'autopilot.xml' might be a good choice. Most developers put these files into the Systems folder of the aircraft.
Adding a Autopilot Configuration to Aircraft
Autopilot configuration files are added to the aircraft by adding
<autopilot> <path>Aircraft/MyAircraft/Systems/my-autopilot.xml</path> </autopilot>
<sim> <systems> <!- - many other elements live here - -> <autopilot> <path>Aircraft/MyAircraft/Systems/my-autopilot.xml</path> </autopilot> </systems> </sim>
node of your aircraft-set.xml file. Note, that more than one <autopilot> node may be present, each will create a new instance of the autopilot subsystem when running FlightGear. They run in the order of appearance under <systems>. For example, lateral and vertical autopilot modes could live in separate files, as could a yaw-damper system.
All elements may contain the attributes "include" and "alias". The "include" property takes a file name as a parameter. This can be used to read the document tree of an external XML file into the node containing the "include" attribute. The included file must have a PropertyList node as the root node. All nodes under this PropertyList node will be added to the node containing the "include" attribute. The "alias" attribute refers to an element defined elsewhere in this XMl document. Alias references are in a path-style syntax, either as a relative or absolute path. Absolute paths start with a slash, like <foo alias="/params/bar/baz"/>. Use the colon to move through the document tree, similar to file system paths like <foo alias="../../bar/baz"/>.
Any top-level element can appear in an autopilot XML file, but only the following elements will be recognised and used:
Common Elements Used By All Elements
Input values for controllers may be specified in several notations. Values may be supplied as constants, from properties or by means of simple linear transformations. Conditions allow the selection of one of multiple input sources. The following text will use the reference element as an example but it may be substituted by any other input element like Kp, gain etc. Input values will be interpreted as double values.
A constant value
A constant value is defined by just adding the value as text to the input element:
<reference> <value>3.5</value> </reference>
The shortcut syntax is also valid:
If the text can be parsed by strtod() to a double value, it will be used as a constant value, otherwise it will be interpreted as a property value (see next paragraph)
A property value
To evaluate the value of a property, place the name of the property into the text element:
<reference> <property>/my/property</property> </reference>
The shortcut syntax is also valid:
Note: the shortcut syntax is only valid, if neither <property> nor <value> element exists. If both, <property> and <value> element exist, the property will be initialized with the given value with scale and offset applied correctly. Properties don't have to exist, the will be created as needed.
Note: for backward compatibility, the notation <prop> instead of <property> is also valid but considered deprecated and might go away in future releases.
Linear transformation of the input value
Input values may be scaled and shifted before they are processed by the controller using the formula y = value * scale + offset To use a celsius temperature property in a controller which expects the temperature in fahrenheit you might use
<reference> <property>/environment/temperature-degc</property> <scale>1.8</scale> <offset>32</offset> </reference>
Periodical transformation of the input value
Periodical (like angular) input values can be transformed to appear in the correct phase before they are processed by the controller by adding or substracting multiples of the period to the input value until the values is in the requested periods interval. The following example converts the heading which comes in the range of [0..360] into the range of [-180..+180]. This will cause a heading of 270 to be processed as a value of -90.
<reference> <property>/orientation/heading-deg</property> <period> <min>-180.0</min> <max>180.0</max> </period> </reference>
To clamp the input to a minimum value, maximum value or both, the tags <min> and <max> can be used. Clamping will occur after the linear transformation has been applied. Note the difference of input clamping to output clamping. While input clamping is applied before the signal reaches the controller, output clamping will be applied to the output signal after it has been processed. The following code will keep the input to the controller in the range of 60 to 80 degrees Fahrenheit:
<reference> <property>/environment/temperature-degc</property> <scale>1.8</scale> <offset>32</offset> <min>60</min> <max>80</max> </reference>
To use the absolute (unsigned) value of the input, add <abs type="bool">true</abs>.
<reference> <property>/autopilot/internal/course-error-deg</property> <abs type="bool">true</abs> </reference>
The elements <scale>, <offset>, <min> and <max> itself can be defined as input values. This code uses as reference the value of course-error-deg, scaled by two and an offset applied which is calculated as the product of the bank-angle-de and the property some/property which itself is limited within the range of -1.5 .. +1.5.
<reference> <property>/autopilot/internal/course-error-deg</property> <scale>2.0</scale> <offset> <property>orientation/bank-angle-deg</property> <scale> <property>some/property <min>-1.5</min> <max>1.5</max> </scale> </offset> </reference>
Conditional input values
The direct inputs of controller and filter elements support so called input value lists. This is useful, if the input should be connected to one of many separate inputs like autopilots connected to NAV1, NAV2 or the GPS. The well known <condition> element is allowed within an input value element. The input value list will be traversed until the first input value with a successful condition is found. The behavior is much like the switch statement in programming languages.
<reference> <condition> <property>/autopilot/coupled-to-gps</property> </condition> <property>instrumentation/gps/desired-track-deg</property> </reference> <reference> <condition> <property>/autopilot/coupled-to-nav2</property> </condition> <property>instrumentation/nav/radials/selected-deg</property> </reference> <reference>instrumentation/nav/radials/selected-deg</reference>
Note the unconditional last <reference<> element which acts as an "if all others fail, use NAV1" anchor. If no input value return with a successful condition, the input value is undefined.
The <scale>, <offset>, <min> and <max> elements of input values itself currently don't support input value lists.
The PID controller is the swiss army knife of automation and this implementation is suitable for most situations. It has a builtin anti-windup logic, and usage of <max> and <min> elements for clamping the output is mandatory. The most important thing to know is that this controller 'does not' compute absolute output values but an offset from the current value of the output property. This can lead to unexpected behavior if the current value of the output property is unknown when the controller is enabled. This behavior is different to that of the pi-simple-controller. The xml element creating a pid controller is <pid-controller>.
Legal elements are:
|Kp||the overall gain for the proportional, integral and derivative part|
|Ts||sampling interval (default: sample at frame rate)|
|alpha||scaling factor for Td (defaults to 0.1)|
|beta||reference weighing factor for the proportional component (defaults to 1.0)|
|gamma||reference weighing factor for the derivate component (defaults to 0.0)|
This controller implements a PI controller. Other than the PID controller, it computes absolute output values, regardless of the value of the output property. It can by configured as an I-only, P-only or PI-controller. It has anti windup logic if <min> and <max> elements are present. The xml element creating a PI controller is <pi-simple-controller> Legal elements are:
|Kp||gain of the proportional component|
|Ki||gain of the integrator component|