Autopilot PID controller tuning resources

From FlightGear wiki
Revision as of 17:06, 8 January 2007 by Joacim (talk | contribs) (→‎Flightgear PID Controler: spelling)
Jump to navigation Jump to search

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

First of all, have a look at the code where you will see the algorythm wich is used for our autopilot. The reading of the existing autopilots in Flightgear aircraft datas will do the rest.

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 controler.

Flightgear PID Controler

Knowing the algorithm is mandatory, certain values are forbiden, for exemple 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 wich is a good reminder while doing the tests.

PID parameter's application

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 Controler by testing directly the aircraft behaviour under the autopilot control, it can be really usefull to get everything in graphical view.

Datas of an Auto-trim PID Controler displayed as graphs

First of all you'll have to turn the PID Controler's debug mode on. That is in the autopilot.xml you are working on. (I didn't try to turn more than one PID controler's debug 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.


Kst, real-time large-dataset viewing and plotting tool