Main Content

Design LQR Servo Controller in Simulink

This example shows the design of an LQR servo controller in Simulink® using an aircraft autopilot application.

Open the aircraft model.


In this model:

  • The Linearized Dynamics block contains the linearized airframe.

  • sf_aerodyn is an S-Function block that contains the nonlinear equations for (θ,ϕ)=(0,15).

  • The error signal between ϕ and the ϕref is passed through an integrator, which helps drive error to zero.

Opening the model also loads the lqrpilotData MAT file, which contains the following data.

  • State equation matrices A and B

  • Linearized state matrix A15

  • Final LQG gain matrix K_lqr

Aircraft State-Space Equations

The equation is the standard state equation of a state-space system.


For the aircraft system, the state vector is as follows.


The variables u, v, and w are the three velocities with respect to the body frame, as shown in the following figure.

The variables ϕ and θ are roll and pitch. p, q, and r are the roll, pitch, and yaw rates, respectively.

The airframe dynamics are nonlinear. The following equation shows the nonlinear components added to the state space equation, where g is the acceleration due to gravity.



For LQG design purposes, the nonlinear dynamics are trimmed at ϕ=15 and p, q, r, and θ set to zero. Since u, v, and w do not affect into the nonlinear term in the preceding equation, the result is a model linearized around (θ,ϕ)=(0,15) with all remaining states set to zero.

The lqrdes script shows how to compute the linearized model A15 at this trimmed operating point.

Problem Definition

The goal for the design is to perform a steady coordinated turn, as shown in this figure.

To achieve this goal, you must design a controller that commands a steady turn by going through a 60° roll. In addition, assume that the pitch angle θ must stay as close to zero as possible.


The lqrdes script shows how to calculate the LQG gain matrix K_lqr.

In the lqrpilot model, ensure that the switch block is configured to select the output of the Nonlinear Dynamics block.

Run the model.


View the response of the roll ϕ to a step-change of 60°. The system tracks the commanded roll within about 60 seconds.

open_system("lqrpilot/phi (roll angle)")

View the pitch angle θ. The controller was able to keep the pitch angle relatively small.

open_system("lqrpilot/theta (pitch angle)")

Finally, view the control inputs.

open_system("lqrpilot/Control Inputs")

You can adjust the Q and R values in the lqrdes script to try different potential designs. Also, you can compare simulations of the linear and nonlinear system dynamics to see the effects of the nonlinearities on the system performance.

Related Topics