Module 12 built an aircraft and Module 13 the tools for flying it. This capstone puts them together: the nonlinear model of 12.4 6-DOF Aircraft Equations of Motion in a loop with an autopilot that holds altitude and heading, flown through a gust, a turn and a failure. A controller designed on a linear model is a claim about a small neighbourhood of trim, and the simulator tests it, so we spend as much time on what breaks as on what works.
Transcript
- Capstone sixteen point two is a flight simulator. It is the nonlinear light aircraft of lesson 12.4, thirteen states: position, body velocity, a quaternion for attitude and the body rates, with no small angle approximation. The coefficients are those of 12.4, unchanged, integrated by Runge-Kutta 4 at 0.02 seconds, the controller's 50 hertz period. Three things are new, and all three are assumptions: a vertical wind, actuators with a lag of 0.05 seconds and a rate limit of 60 degrees per second, and an altimeter with 1 metre of noise. A 60 second flight runs in 10 to 17 milliseconds.
- Trim comes first. At 50 metres per second the 12.4 Newton solve gives an angle of attack of 2.6606 degrees, an elevator of minus 2.7452 degrees and a throttle of 0.3880. Linearise there and the phugoid has a period of 27.98 seconds. Do the nonlinear aircraft follow the linear model? Kick the pitch rate and compare altitudes. At 0.02 radians per second the gap is 0.3 percent. At 0.2 it is 2.8 percent. At 0.5 it is 7.1 percent. The linear modes describe small disturbances well and degrade smoothly as they grow.
- The autopilot is Module 13. Both channels are a discrete LQR designed once at 50 hertz. The altitude command goes through a rate limiter into the longitudinal LQR, whose elevator row reads as a PID: 2.20 radians of elevator per radian of pitch error, a pitch rate gain of 0.817 seconds, 0.0233 radians per metre of altitude error, and an integral gain of 0.004102 that removes steady error. The heading error becomes a bank command, limited to 25 degrees, and the lateral LQR drives aileron and rudder. Its rudder row has minus 1.0355 on yaw rate: the yaw damper falls out of the optimum.
- First test: an altitude step of plus 100 metres at 5 seconds. The command goes through the 5 metres per second rate limiter, and the aircraft follows with an overshoot of 9.727 metres, then settles to within 2 metres at 30.62 seconds. The elevator peaks at only 3.994 degrees and the angle of attack reaches 4.429 degrees, so the step never asks for anything extreme. This is the loop working inside the region it was designed for.
- Second test: a heading change of plus 90 degrees with the bank limited to 25 degrees. Bank peaks at 25.036 degrees, and heading is within 1 degree 23.62 seconds after the command. A steady 25 degree turn goes at 5.242 degrees per second, so 90 degrees alone would take 17.17 seconds; the rest is rolling in and closing the last degrees. Altitude holds to 1.631 metres. The yaw damper and the turn feedforward keep it coordinated.
- Third, a vertical gust of 5 metres per second, one cosine bump lasting 4 seconds. With the autopilot the altitude deviation is 8.554 metres and it recovers. With the autopilot off the gust excites the phugoid and the deviation reaches 15.324 metres. Now the engine fails at 5 seconds. Altitude hold pulls back to trade speed for height. Speed falls to 26.23 metres per second, and at 35.28 seconds the lift reaches its cap. After that the simulation is wrong: a real aircraft stalls well before that, and this one cannot. The numbers past that point are not a prediction.
- Now the failures. First, windup. Climb 100 metres with the elevator limited to 3.5 degrees. With conditional integration, which freezes the integrator while the command is past the limit, the overshoot is 5.063 metres. Without it the integrator keeps charging against the stop, and the overshoot is 62.660 metres. The gains are the same in both runs. A linear design is being asked for more than its limits allow.
- Three more failures. Far from trim: in the heading change the altitude error is 1.631 metres at 25 degrees of bank and 10.671 metres at 60. My reading, not a separate test, is that the linear model has no loss of lift in a steep turn. Unmodelled actuator lag: the bank peak is 25.036 degrees at a time constant of 0.05 seconds and 31.305 degrees at 1.5 seconds. And noise: with a 1 metre altimeter, the elevator's rms movement is 0.042 degrees with the observer and 0.644 degrees without it, fifteen times more.
- What this simulator does not do matters as much. There is no stall model: lift is only capped at 1.4. There is no density change, no ground, no turbulence beyond one gust, no flexibility, fuel or engine dynamics, and no sensor delay. The actuator and sensor numbers are assumptions, and the aerodynamic coefficients are typical and from memory. A real flight-dynamics tool adds stall and post-stall tables, an atmosphere, ground effect, engine and propeller models, turbulence, sensor delay and gain scheduling, and its coefficients come from flight test.
- That closes the physics arc: derivatives and vectors, the flow equations and a solver, then an aircraft and a controller flying inside it. The simulator gave honest answers where the linear design holds, and showed where it breaks. The next row in the course is lesson 9.1, What Is a PDE, on conservation laws and classification. It is not yet written.
Exactly what is simulated
The vehicle is the 12.4 light aircraft: kg, wing area m, span m, the inertia matrix of 12.3 Rigid-Body Dynamics & Rotations, and the coefficients of 12.1 Airfoils, Circulation & Lift to 12.4 6-DOF Aircraft Equations of Motion unchanged: , , the drag polar with and , the moment and side-force derivatives, and a maximum thrust of N. 12.4 said those derivatives are typical of a Cessna-172 class aircraft, quoted from memory; every number below inherits that. This is a plausible aircraft, not a particular one.
The state is thirteen numbers: position, body velocity, a unit quaternion and body rates. All six degrees of freedom move, with no small-angle approximation. Three things are new, all assumptions of this lesson:
- Wind. A vertical world wind changes the air-relative velocity used by the aerodynamics, . With it matches 12.4’s derivative exactly (difference on a tumbling test state).
- Actuators. Each command passes a position clamp, then a first-order lag with time constant s and a rate limit of /s. Limits: elevator , aileron , rudder . The throttle has a s lag. These numbers are chosen, not measured.
- Sensors. The altimeter has white noise (default m, off until switched on). Everything else is read perfectly.
Not simulated: stall (lift is capped at , a ceiling and not stall physics), density change, the ground, turbulence beyond one gust, flexibility, fuel, engine dynamics, sensor delay and shear. As in 12.4 there is no adverse yaw, or .
Integration: quaternions and RK4
Attitude is a quaternion because Euler angles are singular at . Its rate is , renormalised after every step so rounding does not shrink the rotation; Euler angles are computed only for readouts and the heading loop.
The step is the classical RK4 of 4.3 Runge–Kutta Methods & Butcher Tableaux at s with controls held constant across it. That is the controller’s Hz period, so a zero-order hold is what the plant really sees, and is well inside RK4’s stability limit (Problem 3). A 60 s scenario takes 10 to 17 ms in Node, so the lab runs the nonlinear model live.
Trim, and the linearisation check
Trim at m/s and m is Newton’s method on the 12.4 derivative: , elevator , throttle . Linearising there (12.5 Trim, Linearization & Longitudinal Modes, 12.6 Lateral-Directional Modes) gives those lessons’ modes:
- short period and phugoid (period s);
- roll subsidence , Dutch roll and spiral .
Does the nonlinear aircraft follow that linear model? Autopilot off, from trim, a pitch-rate kick , s:
- rad/s: the altitude peaks at m, the largest gap between nonlinear and linear altitude is m (about ), and the phugoid period is s.
- rad/s: peak m, gap m (), period s, the same as the 12.4 lab.
- rad/s: peak m, gap m ().
A sideslip in the lateral block gives a yaw-rate peak of rad/s and a gap of . The linear modes describe small disturbances well and degrade smoothly as they grow.
The autopilot
Both channels are the discrete LQR of 13.7 LQR & State Estimation, designed once at Hz: an exact zero-order-hold discretisation by matrix exponential, and a Riccati solution by doubling (14 and 10 iterations, residual below ). Nothing heavy runs per frame.
Longitudinal. The state is : the 12.5 states, the altitude error and its integral . The inputs are elevator and throttle (thrust per unit throttle is m/s). Weights: , , , , , , , chosen by the weight rule of the LQR lesson. The elevator row, in radians, is
Read it as a PID: rad of elevator per rad of pitch error, a pitch-rate (derivative) gain of s, rad per metre ( per metre) of altitude error, and an integral term of rad per metre-second ( per metre-second) that removes steady error. The gains on and are the extra feedback a three-term PID lacks. The throttle row is an autothrottle that mainly reacts to speed. The closed-loop roots, mapped back to the -plane, are , , , and : the lightly damped phugoid () is replaced by a pair with , and no oscillatory short-period pair remains. The altitude command goes through a m/s rate limiter so a step never asks for an impossible pitch.
Lateral. The state is with aileron and rudder as inputs. The gains act on the error from the steady coordinated turn at the commanded bank, with a feedforward from the linear model: steady (against ) and a little rudder. So the damper does not fight the turn, 12.6’s flaw in the plain yaw damper. Weights: , , , , , . The rudder row has on : the yaw damper as a by-product of the optimum. Closed-loop roots: , (), .
Heading hold is an outer proportional loop, . Pitch hold is the term, altitude hold the and terms. Anti-windup is conditional integration: stops accumulating while the elevator command is past its limit and the error would push it further. The lab can switch it off.
Actuators and sensors
The LQR plant has no actuator: the design assumes the elevator goes where it is told. The lag, rate limit and stop above are what the real loop adds, and that unmodelled lag causes the third failure below.
The altimeter reading would feed directly, and the gain on turns white noise into elevator motion. The lab’s filter is . The rate comes from the air-relative velocity and attitude (an assumption: what an air-data and attitude system would supply), so a gust is an error in the filter’s model that the correction term must remove. s by default: a s time constant, the first-order case of the observer of 13.7 LQR & State Estimation.
The lab
The attitude indicator and heads-up display show the state as a pilot sees it. With the autopilot off, three pilot sliders command elevator, aileron and rudder directly: the manual flying of 12.4 on a plant with limits. The weight sliders redesign the LQR when you let go, so you can watch a more aggressive design hit its limits earlier.
Scenarios, with numbers
Every figure is from the lab at s with the default weights, anti-windup on, no noise and s unless a change is stated. An independent NumPy implementation of the same equations agrees to better than relative.
Altitude step, m at s. Overshoot m (), settling to within m at s, final error m. Peak elevator , up to , speed down to m/s as the climb costs speed, throttle up to . Weight gives overshoot m and a slower s settle; gives m and s.
Heading change, at s, bank limit . Bank peaks at ; heading is within s after the command and ends at . A steady turn goes at /s, so takes s plus roll-in and approach. Altitude holds to m; aileron peaks at and rudder at .
Gust, m/s vertical, one cosine bump of s from s (an assumed shape). With the autopilot: altitude deviation m, to , speed to m/s, recovered by the end. Without it the gust excites the phugoid: m peak and still m off at s. A m/s gust gives m with the autopilot, m without, and .
Engine out at s. Altitude hold pulls back to trade speed for height. Speed falls to m/s, the elevator command is past its limit for s, the altitude error reaches m s after the failure, and at s lift hits the cap, at . After that the simulation is wrong: the cap holds lift flat where a real wing would stall and lose it, and keeps climbing with nothing to stop it, so the final m is not a prediction. With the autopilot off the aircraft just glides, m low at s. The honest conclusion is qualitative: altitude hold is the wrong law after an engine failure and should hand over to speed hold.
What the autopilot gets wrong
Windup. Climb m with the elevator limited to and no command rate limit. With anti-windup: overshoot m, settling s, saturated s. Without it the integrator keeps charging against the stop: overshoot m, settling s, saturated s, minimum speed m/s. With a limit, m against m. The gains are fine; a linear design is being asked for more than its limits allow.
Nonlinearity far from trim. The heading change at larger bank limits: at the altitude error peaks at m and at ; at , m and (load factor ), with elevator and speed down to m/s; at , m and . Aileron nearly saturates at () and sits on its stop from . My reading, not a separate test: the linear model has no lift loss, so the altitude loop hears of it only after the aircraft sinks.
Unmodelled actuator lag. In the turn the bank peak is at s, at s, at s and at s. A rate limit of /s alone gives . The loop has lost phase it was designed to have (13.5 Frequency Response & Bode Plots).
Noise. At m in level flight the elevator’s rms movement about trim is with the observer () and without, fifteen times more, with the elevator hitting its /s rate limit. gives ; gives but a slower estimate. Observer off with m: .
Computing it
The playground reduces windup to its smallest form. The plant is with a limit of , the controller is with , and the command is a m step, with s, over s. Without anti-windup the overshoot is m and the command is saturated for s; with conditional integration the overshoot is m and the saturated time s. It also prints the discrete roll pole .
The exercise. Write the discrete LQR that the autopilot uses: iterate the Riccati equation with until it settles. The tests are a scalar case with a known golden-ratio answer and a double integrator sampled at s.
Concept checks
Problems
At m/s and m/s, find the turn rate in a coordinated turn at of bank, and the time to turn at that rate. Why did the lab take longer?
Show worked solution
rad/s /s. Ninety degrees takes s. The lab took s to get within : the heading loop is proportional and the bank is rolled in first, so the aircraft turns at the steady rate only in the middle, and the last degrees take time to close.
The integral gain from the elevator’s LQR row is rad per metre-second. Suppose the aircraft is held m below its target for s while the elevator is saturated, and the integrator is not frozen. How much elevator does the integral term alone demand when the aircraft arrives?
Show worked solution
The integral is m s, so the term is rad, about . The elevator saturates at , so the integral term dominates the command until the integrator is pulled back down by an overshoot of the opposite sign. That demand is far beyond the limit, and so the elevator stays stuck long after the error has reversed.
The fastest closed-loop root is s in the lateral loop. RK4 is stable on when (4.5 Stability Regions & Stiffness). Find at s, the largest stable , and the discrete pole of the zero-order-hold model.
Show worked solution
, inside the interval. The largest stable step is s, about four times the step used. The ZOH discrete pole is , inside the unit circle. A faster root, or a stiffer actuator, would shrink that margin, and above s RK4 would be unstable for that root.
What comes next
A real flight-dynamics tool adds what this lacks: stall and post-stall aerodynamics from measured tables, a standard atmosphere, ground effect and gear, engine and propeller models, turbulence spectra, structural flexibility, sensor and computer delay, and gain scheduling so the controller changes with speed and altitude instead of being one design at one trim. Its coefficients come from flight test, ours from memory. The physics arc ends here: derivatives and vectors, the flow equations and a solver, then an aircraft and a controller flying inside it.
The next row in the course is L-9.1, 9.1 What Is a PDE? Conservation Laws & Classification, on conservation laws and classification.
Key Takeaways
- The simulator is the 12.4 aircraft with thirteen states and quaternions, RK4 at s, plus assumed actuator limits, a vertical gust and a noisy altimeter; stall, density, ground, flexibility and delay are absent.
- Trim at m/s is , elevator , throttle ; the nonlinear-to-linear gap grows from to as the kick grows from to rad/s.
- One discrete LQR gives pitch, speed and altitude hold, its elevator row reading as a PID; a bank LQR with a proportional heading loop gives roll and heading hold, and its rudder row is the yaw damper.
- Altitude step: m overshoot, s settling; gust of m/s: m against m with no autopilot.
- Windup: with a elevator limit overshoot goes from m to m without conditional integration.
- Far from trim the design degrades ( m at bank), and actuator lag raises the bank peak to at s.
- Past the lift cap the simulation is not a prediction, and the observer cuts noise at the elevator from to rms.