Programming autopilots

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
Hi!

I haven't posted for a while, but I think this is a good place to ask this question! I'm interested in the maths behind how autopilots work. Right now I'm interested in programming something that will simulate a plane intercepting a localiser and flying along it towards a runway (for a simple ATC game). The simulation is very simple - basically the heading, altitude and speed of the selected plane change at constant rates until they match the values you assign to them. This is OK for issuing commands to the planes but there comes a point where you need to clear them for approach along the ILS, and the heading needs to be controlled by some sort of autopilot.

I guess I could do it with a lot of if statements and conditionals but perhaps there's some more elegant theory behind this? Any good books on autopilot coding?

Thanks :)
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,605
Reaction score
2,326
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I guess I could do it with a lot of if statements and conditionals but perhaps there's some more elegant theory behind this? Any good books on autopilot coding?

Thanks :)

Look for control theory, thats the term you are looking for...PI, P, PD-T1, PID-T1, all that stuff. Also the NTRS is full of interesting technical reports on basic and advanced autopilots, especially the math for them.

Fuzzy logic also a very helpful term there, since this allows you to reduce your programming code basically to statements like "if (high && fast) {"
 

thepenguin

Flying Penguin
Addon Developer
Joined
Jul 27, 2013
Messages
220
Reaction score
1
Points
16
Location
Earth-Moon Lagrange Point (L4)
If you are interested in finding an Orbiter-Based example of this, you could look at the DG's atmospheric autopilot code. You can find it in the file "Orbiter/Script/DG/aap.lua"

There are several different things that the AAP (atmospheric autopilot) does. One autopilot controls speed, another controls altitude, and another controls heading.

If you are looking for a good starting point for the math, I would recommend starting with PID Controllers ([ame="http://en.wikipedia.org/wiki/PID_controller"]PID controller - Wikipedia, the free encyclopedia[/ame]). These are some of the most widely-used algorithms used for control (of all systems, not just autopilots), and they are fairly simple to understand, when compared to some of the other control algorithms.

In addition, it is likely that you will need to have more than one layer of control. You say that you want a plane to land at an airfield, so you may need one algorithm to figure out how to get there (altitude, speed, and heading), and another set to figure out how to actually fly the plane.
 

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
Awesome, thanks for the replies! These keywords look like they are a good starting point :)

Also, re:

You say that you want a plane to land at an airfield, so you may need one algorithm to figure out how to get there (altitude, speed, and heading), and another set to figure out how to actually fly the plane.

The project I'm working on is just a simple ATC simulator, i.e. dots moving across a window with an assigned speed, altitude and heading. So I'm not actually simulating aircraft systems or aerodynamics, I'm just assigning them a vector and they accelerate/decelerate at a constant rate until the speed/altitude/heading matches what is assigned. Should make it a bit simpler :) Also the autopilot is just to make them turn towards and fly along a line that extends from the runway (the localizer).
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,605
Reaction score
2,326
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
The project I'm working on is just a simple ATC simulator, i.e. dots moving across a window with an assigned speed, altitude and heading. So I'm not actually simulating aircraft systems or aerodynamics, I'm just assigning them a vector and they accelerate/decelerate at a constant rate until the speed/altitude/heading matches what is assigned. Should make it a bit simpler :) Also the autopilot is just to make them turn towards and fly along a line that extends from the runway (the localizer).

You could also look at Smartcockpit.com, there are some files that explain how real-world autopilots react when descending or intercepting a localizer. Might be interesting for your project.
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
My RV Orientation MFD has a bunch of fuzzy logic AP coded in it. If you are controlling a known device, then you can code a tight PID algorithm with exactly the right amount of overcorrection and damping to get the behavior you want. If you are coding for an unknown vehicle, then you either have to behave like a human (i.e. control it a bit, see what happened, repeat), or do some pre-calibration exercises. For RV, I chose the latter, calibrating the thruster response for a heavy vessel and a light vessel.
 
Top