Autopilot PID controller tuning resources

From FlightGear wiki
Jump to navigation Jump to search

The FlightGear Autopilot is a modular system based on PID controllers. Here are some tips to help tuning such a controller. There is lot of documentation all over the Internet about how to tune the parameters, having this you will have to figure out how the Flightgear PID controller implementation works.

First of all, have a look at the code where you will see the algorithm wich is used for our autopilot. Checking existing autopilot configurations in Flightgear aircraft will also help.

There is actually a doc about filters in Flightgear documentation. Filters can be applied on input or ouput values, in other words, before and after the PID controller (execution).

FlightGear PID Controller

Knowing the algorithm is mandatory, certain values are forbidden, for example they can lead to a division by zero. Then you will have to understand where the parameters apply to act on the choosen correction module. See the schema which is a good reminder while testing.

PID parameter's application
Datas of an Auto-trim PID Controler displayed as graphs

You can find good explanations on how to practically tune the controller. Wikipedia's article on the PID Controler

Getting graphs of Controler action

While it's possible to tune a PID controller by testing directly the aircraft behaviour under the autopilot control, it can be really useful to get everything in graphical view.

First of all you'll have to turn the PID Controller's debug mode on. That is in the autopilot.xml you are working on. (I didn't try to turn on more than one PID controller's debugging support at the same time).

Then you will get 6 new values displayed on the console at each FG loop. You will need to catch them and format the values in one line. Here is an exemple of a parser script written in Perl:

#!/usr/bin/perl -w
# prints: "input reference P I D output"

while (<STDIN>) {
        if ($_ =~ /input\s=\s(-*\d+.*)\sref\s=\s(-*\d+.*)/) {
                print STDOUT "$1 $2 ";
        } elsif ($_ =~ /P:(-*\d+.*)\sI:(-*\d+.*)\sD:(-*\d+.*)/) {
                print STDOUT "$1 $2 $3";
        } elsif ($_ =~ /output\s=\s(.*)/) {
                print STDOUT " $1\n";
        }
}

Then you can write them in a file...

alexis@linear:~/fgfs$ /usr/local/bin/fgfs 2>&1 | ./PIDcontroler_parser.pl > my_file

If you use Linux, You can run Kst simultaneously to read the datas on the fly and watch them displayed together in real time while testing the aircraft.

Alternative Method

As an alternative to using the controller's debug output you can use the built in logging system of Flightgear. This can be configured through the preferences.xml file, or at runtime via the File->Logging menu option.

To tune a controller you would typically display the setpoint property and the controlled property in the same graph. Another property that is interresting too look at is the actuating property, wich can be for example the aileron control or the elevator control.