<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://murray.cds.caltech.edu/index.php?action=history&amp;feed=atom&amp;title=Python-control%2FExample%3A_Vertical_takeoff_and_landing_aircraft</id>
	<title>Python-control/Example: Vertical takeoff and landing aircraft - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://murray.cds.caltech.edu/index.php?action=history&amp;feed=atom&amp;title=Python-control%2FExample%3A_Vertical_takeoff_and_landing_aircraft"/>
	<link rel="alternate" type="text/html" href="https://murray.cds.caltech.edu/index.php?title=Python-control/Example:_Vertical_takeoff_and_landing_aircraft&amp;action=history"/>
	<updated>2026-09-10T07:53:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://murray.cds.caltech.edu/index.php?title=Python-control/Example:_Vertical_takeoff_and_landing_aircraft&amp;diff=14517&amp;oldid=prev</id>
		<title>Murray: /* Lateral control using inner/outer loop design */</title>
		<link rel="alternate" type="text/html" href="https://murray.cds.caltech.edu/index.php?title=Python-control/Example:_Vertical_takeoff_and_landing_aircraft&amp;diff=14517&amp;oldid=prev"/>
		<updated>2012-09-03T05:01:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Lateral control using inner/outer loop design&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:01, 3 September 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l192&quot;&gt;Line 192:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 192:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;of the lateral position  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;of the lateral position  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;dynamics &amp;lt;math&amp;gt;P_o&amp;lt;/math&amp;gt; and controller &amp;lt;math&amp;gt;C_o&amp;lt;/math&amp;gt;.   &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;dynamics &amp;lt;math&amp;gt;P_o&amp;lt;/math&amp;gt; and controller &amp;lt;math&amp;gt;C_o&amp;lt;/math&amp;gt;.   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;center&amp;gt;[[Image:pvtol-nested.png]]&amp;lt;/center&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;center&amp;gt;[[Image:pvtol-nested&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;-1&lt;/ins&gt;.png]]&amp;lt;/center&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The closed inner loop dynamics &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; control the roll angle of the aircraft using&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The closed inner loop dynamics &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; control the roll angle of the aircraft using&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;the vectored thrust while the outer loop controller &amp;lt;math&amp;gt;C_o&amp;lt;/math&amp;gt; commands the&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;the vectored thrust while the outer loop controller &amp;lt;math&amp;gt;C_o&amp;lt;/math&amp;gt; commands the&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Murray</name></author>
	</entry>
	<entry>
		<id>https://murray.cds.caltech.edu/index.php?title=Python-control/Example:_Vertical_takeoff_and_landing_aircraft&amp;diff=14504&amp;oldid=prev</id>
		<title>Murray: Created page with &quot;This page demonstrates the use of the python-control package for analysis and design of a controller for a vectored thrust aircraft model that is used as a running example thr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://murray.cds.caltech.edu/index.php?title=Python-control/Example:_Vertical_takeoff_and_landing_aircraft&amp;diff=14504&amp;oldid=prev"/>
		<updated>2012-09-03T04:44:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This page demonstrates the use of the python-control package for analysis and design of a controller for a vectored thrust aircraft model that is used as a running example thr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page demonstrates the use of the python-control package for analysis and design of a controller for a vectored thrust aircraft model that is used as a&lt;br /&gt;
running example through the text &amp;#039;&amp;#039;[http://www.cds.caltech.edu/~murray/amwiki Feedback Systems]&amp;#039;&amp;#039; by Astrom and Murray.  This example makes use of MATLAB compatible commands.  The following files contain the code that is demonstrated here:&lt;br /&gt;
* {{SFfile|examples/pvtol-lqr.py|pvtol-lqr.py}} - state feedback control design&lt;br /&gt;
* {{SFfile|examples/pvtol-nested.py|pvtol-nested.py}} - inner/outer loop design using transfer functions&lt;br /&gt;
&lt;br /&gt;
== System Description ==&lt;br /&gt;
&lt;br /&gt;
This example uses a simplified model for a (planar) vertical takeoff and landing aircraft (PVTOL), as shown below:&lt;br /&gt;
{| align=center&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| width=10% | &amp;amp;nbsp;&lt;br /&gt;
| width=35% align=center | [[Image:pvtol-diagram.png]]&lt;br /&gt;
| width=10% | &amp;amp;nbsp;&lt;br /&gt;
| width=35% align=center | [[Image:pvtol-dynamics.png]]&lt;br /&gt;
| width=10% | &amp;amp;nbsp;&lt;br /&gt;
|}&lt;br /&gt;
The position and orientation of the center of mass of the aircraft is denoted by&lt;br /&gt;
&amp;lt;math&amp;gt;(x,y,\theta)&amp;lt;/math&amp;gt;, &lt;br /&gt;
&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the mass of the vehicle, &amp;lt;math&amp;gt;J&amp;lt;/math&amp;gt; the moment of inertia, &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; the&lt;br /&gt;
gravitational constant and &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; the damping coefficient.&lt;br /&gt;
The forces generated by the main downward thruster and the&lt;br /&gt;
maneuvering thrusters are modeled as a pair of forces &amp;lt;math&amp;gt;F_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_2&amp;lt;/math&amp;gt; acting at a&lt;br /&gt;
distance &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; below the aircraft (determined by the geometry of the&lt;br /&gt;
thrusters). &lt;br /&gt;
&lt;br /&gt;
It is convenient to redefine the inputs so that the origin is an&lt;br /&gt;
equilibrium point of the system with zero input.  Letting &amp;lt;math&amp;gt;u_1 =&lt;br /&gt;
F_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_2 = F_2 - mg&amp;lt;/math&amp;gt;, the equations can be written in state space form as&lt;br /&gt;
{| align=center&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center | [[Image:pvtol-statespace.png]]&lt;br /&gt;
| width=10% | &amp;amp;nbsp;&lt;br /&gt;
| align=center |&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| Parameter || Value || Comment &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; || 4 kg || system mass&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;J&amp;lt;/math&amp;gt; || 0.0475 kg m^2 &amp;amp;nbsp; || system inertia&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; || 0.25 m || thrust offset&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; || 9.8 m/s || gravitational constant &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; || 0.05 N s/m || rotational damping&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== LQR state feedback controller ==&lt;br /&gt;
&lt;br /&gt;
This section demonstrates the design of an LQR state feedback controller for the vectored thrust aircraft example.  This example is pulled from Chapter 6 (State Feedback) of [http:www.cds.caltech.edu/~murray/amwiki Astrom and Murray].  The python code listed here are contained the the file {{SFfile|examples/pvtol-lqr.py|pvtol-lqr.py}}.&lt;br /&gt;
&lt;br /&gt;
To execute this example, we first import the libraries for SciPy, MATLAB plotting and the python-control package:&lt;br /&gt;
 from numpy import *             # Grab all of the NumPy functions&lt;br /&gt;
 from matplotlib.pyplot import * # Grab MATLAB plotting functions&lt;br /&gt;
 from control.matlab import *    # MATLAB-like functions&lt;br /&gt;
The parameters for the system are given by&lt;br /&gt;
 m = 4;                         # mass of aircraft&lt;br /&gt;
 J = 0.0475;                    # inertia around pitch axis&lt;br /&gt;
 r = 0.25;                      # distance to center of force&lt;br /&gt;
 g = 9.8;                       # gravitational constant&lt;br /&gt;
 c = 0.05;                      # damping factor (estimated)&lt;br /&gt;
The linearization of the dynamics near the equilibrium point &amp;lt;math&amp;gt;x_e = (0, 0, 0, 0, 0, 0)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;u_e = (0, mg)&amp;lt;/math&amp;gt; are given  by&lt;br /&gt;
 # State space dynamics&lt;br /&gt;
 xe = [0, 0, 0, 0, 0, 0];        # equilibrium point of interest&lt;br /&gt;
 ue = [0, m*g];                  # (note these are lists, not matrices)&lt;br /&gt;
&lt;br /&gt;
 # Dynamics matrix (use matrix type so that * works for multiplication)&lt;br /&gt;
 A = matrix(&lt;br /&gt;
    [[ 0,    0,    0,    1,    0,    0],&lt;br /&gt;
     [ 0,    0,    0,    0,    1,    0],&lt;br /&gt;
     [ 0,    0,    0,    0,    0,    1],&lt;br /&gt;
     [ 0, 0, (-ue[0]*sin(xe[2]) - ue[1]*cos(xe[2]))/m, -c/m, 0, 0],&lt;br /&gt;
     [ 0, 0, (ue[0]*cos(xe[2]) - ue[1]*sin(xe[2]))/m, 0, -c/m, 0],&lt;br /&gt;
     [ 0,    0,    0,    0,    0,    0 ]])&lt;br /&gt;
 &lt;br /&gt;
 # Input matrix&lt;br /&gt;
 B = matrix(&lt;br /&gt;
    [[0, 0], [0, 0], [0, 0],&lt;br /&gt;
     [cos(xe[2])/m, -sin(xe[2])/m],&lt;br /&gt;
     [sin(xe[2])/m,  cos(xe[2])/m],&lt;br /&gt;
     [r/J, 0]])&lt;br /&gt;
 &lt;br /&gt;
 # Output matrix &lt;br /&gt;
 C = matrix([[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0]])&lt;br /&gt;
 D = matrix([[0, 0], [0, 0]])&lt;br /&gt;
&lt;br /&gt;
To compute a linear quadratic regulator for the system, we write the cost&lt;br /&gt;
function as&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:pvtol-lqrcost.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;z = z - z_e&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v = u - u_e&amp;lt;/math&amp;gt; represent the local coordinates&lt;br /&gt;
around the desired equilibrium point &amp;lt;math&amp;gt;(z_e, u_e)&amp;lt;/math&amp;gt;.  We begin with&lt;br /&gt;
diagonal matrices for the state and input costs:&lt;br /&gt;
 Qx1 = diag([1, 1, 1, 1, 1, 1]);&lt;br /&gt;
 Qu1a = diag([1, 1]);&lt;br /&gt;
 (K, X, E) = lqr(A, B, Qx1, Qu1a); K1a = matrix(K);&lt;br /&gt;
This gives a control law of the form &amp;lt;math&amp;gt;v = -K z&amp;lt;/math&amp;gt;, which can then be&lt;br /&gt;
used to derive the control law in terms of the original variables:&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
  u = v + u_d = - K(z - z_d) + u_d.&lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;u_d = (0, mg)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;z_d = (x_d, y_d, 0, 0, 0, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the python-control package only supports SISO systems, in order to compute the closed loop dynamics, we must extract the dynamics for the lateral and altitude dynamics as individual systems.  In addition, we simulate the closed loop dynamics using the &amp;lt;tt&amp;gt;step&amp;lt;/tt&amp;gt; command with &amp;lt;math&amp;gt;K x_d&amp;lt;/math&amp;gt; as the input vector (assumes that the &amp;quot;input&amp;quot; is unit size,  with &amp;lt;math&amp;gt;xd&amp;lt;/math&amp;gt; corresponding to the desired steady state.  The following code performs these operations:&lt;br /&gt;
 xd = matrix([[1], [0], [0], [0], [0], [0]]); &lt;br /&gt;
 yd = matrix([[0], [1], [0], [0], [0], [0]]);  &lt;br /&gt;
&lt;br /&gt;
 # Indices for the parts of the state that we want&lt;br /&gt;
 lat = (0,2,3,5);&lt;br /&gt;
 alt = (1,4);&lt;br /&gt;
 &lt;br /&gt;
 # Decoupled dynamics&lt;br /&gt;
 Ax = (A[lat, :])[:, lat];       #! not sure why I have to do it this way&lt;br /&gt;
 Bx = B[lat, 0]; Cx = C[0, lat]; Dx = D[0, 0];&lt;br /&gt;
  &lt;br /&gt;
 Ay = (A[alt, :])[:, alt];       #! not sure why I have to do it this way&lt;br /&gt;
 By = B[alt, 1]; Cy = C[1, alt]; Dy = D[1, 1];&lt;br /&gt;
 &lt;br /&gt;
 # Step response for the first input&lt;br /&gt;
 H1ax = ss(Ax - Bx*K1a[0,lat], Bx*K1a[0,lat]*xd[lat,:], Cx, Dx);&lt;br /&gt;
 (Tx, Yx) = step(H1ax, T=linspace(0,10,100));&lt;br /&gt;
 &lt;br /&gt;
 # Step response for the second input&lt;br /&gt;
 H1ay = ss(Ay - By*K1a[1,alt], By*K1a[1,alt]*yd[alt,:], Cy, Dy);&lt;br /&gt;
 (Ty, Yy) = step(H1ay, T=linspace(0,10,100));&lt;br /&gt;
&lt;br /&gt;
 plot(Tx, Yx[0,:].T, &amp;#039;-&amp;#039;, Ty, Yy[0,:].T, &amp;#039;--&amp;#039;); hold(True);&lt;br /&gt;
 plot([0, 10], [1, 1], &amp;#039;k-&amp;#039;); hold(True);&lt;br /&gt;
 ylabel(&amp;#039;position&amp;#039;);&lt;br /&gt;
 legend((&amp;#039;x&amp;#039;, &amp;#039;y&amp;#039;), loc=&amp;#039;lower right&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
The response of the closed loop system to a step change in the desired position is shown below.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{|&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center | [[Image:pvtol-lqrstep-xy.png]]&lt;br /&gt;
| width=10% | &amp;amp;nbsp;&lt;br /&gt;
| align=center | [[Image:pvtol-lqrstep-rho.png]]&lt;br /&gt;
|-&lt;br /&gt;
| align=center | Step response in &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt;&lt;br /&gt;
| width=10% | &amp;amp;nbsp;&lt;br /&gt;
| align=center | Effect of control weight &amp;lt;math&amp;gt;\rho&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
The plot on the left shows the &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; positions of the aircraft when it is&lt;br /&gt;
commanded to move 1 m in each direction.  &lt;br /&gt;
&lt;br /&gt;
The response can be tuned by adjusting the weights in the LQR cost.&lt;br /&gt;
The plot on the right shows&lt;br /&gt;
the &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; motion for control  weights &amp;lt;math&amp;gt;\rho = 1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;10^2&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;10^4&amp;lt;/math&amp;gt;.  A higher weight of the input term&lt;br /&gt;
in the cost function causes a more sluggish response.  It is created using the code:&lt;br /&gt;
 # Look at different input weightings&lt;br /&gt;
 Qu1a = diag([1, 1]); (K1a, X, E) = lqr(A, B, Qx1, Qu1a);&lt;br /&gt;
 H1ax = ss(Ax - Bx*K1a[0,lat], Bx*K1a[0,lat]*xd[lat,:], Cx, Dx);&lt;br /&gt;
 &lt;br /&gt;
 Qu1b = (40**2)*diag([1, 1]); (K1b, X, E) = lqr(A, B, Qx1, Qu1b);&lt;br /&gt;
 H1bx = ss(Ax - Bx*K1b[0,lat], Bx*K1b[0,lat]*xd[lat,:],Cx, Dx);&lt;br /&gt;
 &lt;br /&gt;
 Qu1c = (200**2)*diag([1, 1]); (K1c, X, E) = lqr(A, B, Qx1, Qu1c);&lt;br /&gt;
 H1cx = ss(Ax - Bx*K1c[0,lat], Bx*K1c[0,lat]*xd[lat,:],Cx, Dx);&lt;br /&gt;
 &lt;br /&gt;
 [T1, Y1] = step(H1ax, T=linspace(0,10,100));&lt;br /&gt;
 [T2, Y2] = step(H1bx, T=linspace(0,10,100));&lt;br /&gt;
 [T3, Y3] = step(H1cx, T=linspace(0,10,100));&lt;br /&gt;
&lt;br /&gt;
 plot(T1, Y1[0,:].T, &amp;#039;b-&amp;#039;); hold(True);&lt;br /&gt;
 plot(T2, Y2[0,:].T, &amp;#039;b-&amp;#039;); hold(True);&lt;br /&gt;
 plot(T3, Y3[0,:].T, &amp;#039;b-&amp;#039;); hold(True);&lt;br /&gt;
 plot([0 ,10], [1, 1], &amp;#039;k-&amp;#039;); hold(True);&lt;br /&gt;
 &lt;br /&gt;
 axis([0, 10, -0.1, 1.4]); &lt;br /&gt;
 # arcarrow([1.3, 0.8], [5, 0.45], -6);&lt;br /&gt;
 text(5.3, 0.4, &amp;#039;rho&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
== Lateral control using inner/outer loop design ==&lt;br /&gt;
&lt;br /&gt;
This section demonstrates the design of loop shaping controller for the vectored thrust aircraft example.  This example is pulled from Chapter 11 (Frequency Domain Design) of [http:www.cds.caltech.edu/~murray/amwiki Astrom and Murray].  The python code listed here are contained the the file {{SFfile|examples/pvtol-nested.py|pvtol-nested.py}}.&lt;br /&gt;
&lt;br /&gt;
To design a controller for the lateral dynamics of the vectored thrust aircraft, we&lt;br /&gt;
make use of a &amp;quot;inner/outer&amp;quot; loop design methodology.  We begin by representing the dynamics using the block diagram&lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:pvtol-lateraltf.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
  H_{\theta u_1} = \frac{r}{J s^2}, \qquad&lt;br /&gt;
  H_{x u_1} = \frac{J s^2 - m g r}{J s^2 (m s^2 + c s)}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
The controller is constructed by splitting the process dynamics and controller into&lt;br /&gt;
two components: an &amp;#039;&amp;#039;inner loop&amp;#039;&amp;#039;&lt;br /&gt;
consisting of the roll dynamics &amp;lt;math&amp;gt;P_i&amp;lt;/math&amp;gt; and &lt;br /&gt;
control &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; and an &amp;#039;&amp;#039;outer loop&amp;#039;&amp;#039; consisting&lt;br /&gt;
of the lateral position &lt;br /&gt;
dynamics &amp;lt;math&amp;gt;P_o&amp;lt;/math&amp;gt; and controller &amp;lt;math&amp;gt;C_o&amp;lt;/math&amp;gt;.  &lt;br /&gt;
&amp;lt;center&amp;gt;[[Image:pvtol-nested.png]]&amp;lt;/center&amp;gt;&lt;br /&gt;
The closed inner loop dynamics &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; control the roll angle of the aircraft using&lt;br /&gt;
the vectored thrust while the outer loop controller &amp;lt;math&amp;gt;C_o&amp;lt;/math&amp;gt; commands the&lt;br /&gt;
roll angle to regulate the lateral position.  &lt;br /&gt;
&lt;br /&gt;
The following code imports the libraries that are required and defines the dynamics:&lt;br /&gt;
 from matplotlib.pyplot import * # Grab MATLAB plotting functions&lt;br /&gt;
 from control.matlab import *    # MATLAB-like functions&lt;br /&gt;
&lt;br /&gt;
 # System parameters&lt;br /&gt;
 m = 4;                         # mass of aircraft&lt;br /&gt;
 J = 0.0475;                    # inertia around pitch axis&lt;br /&gt;
 r = 0.25;                      # distance to center of force&lt;br /&gt;
 g = 9.8;                       # gravitational constant&lt;br /&gt;
 c = 0.05;                      # damping factor (estimated)&lt;br /&gt;
&lt;br /&gt;
 # Transfer functions for dynamics&lt;br /&gt;
 Pi = tf([r], [J, 0, 0]);       # inner loop (roll)&lt;br /&gt;
 Po = tf([1], [m, c, 0]);       # outer loop (position)&lt;br /&gt;
&lt;br /&gt;
For the inner loop, use a lead compensator&lt;br /&gt;
 k = 200;  a = 2;  b = 50&lt;br /&gt;
 Ci = k*tf([1, a], [1, b])              # lead compensator&lt;br /&gt;
 Li = Pi*Ci&lt;br /&gt;
The closed loop dynamics of the inner loop, &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt;, are given by&lt;br /&gt;
 Hi = parallel(feedback(Ci, Pi), -m*g*feedback(Ci*Pi, 1));&lt;br /&gt;
Finally, we design the lateral compensator using another lead compenstor&lt;br /&gt;
 # Now design the lateral control system&lt;br /&gt;
 a = 0.02; b = 5; K = 2;&lt;br /&gt;
 Co = -K*tf([1, 0.3], [1, 10]);         # another lead compensator&lt;br /&gt;
 Lo = -m*g*Po*Co;&lt;br /&gt;
&lt;br /&gt;
The performance of the system can be characterized using the sensitivity function and the complementary sensitivity function&lt;br /&gt;
 L = Co*Hi*Po;&lt;br /&gt;
 S = feedback(1, L);&lt;br /&gt;
 T = feedback(L, 1);&lt;br /&gt;
The frequency response and Nyquist plot for the loop transfer function are computing using the commands&lt;br /&gt;
 bode(L));&lt;br /&gt;
 &lt;br /&gt;
 nyquist(L, (0.0001, 1000));&lt;br /&gt;
 axis([-700, 5300, -3000, 3000]);&lt;br /&gt;
 &lt;br /&gt;
 gangof4(Hi*Po, Co);&lt;br /&gt;
The corresponding plots are shown below:&lt;br /&gt;
{| width=100%&lt;br /&gt;
|- valign=middle&lt;br /&gt;
| align=center | [[Image:pvtol-nested-bode.png]]&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| align=center | [[Image:pvtol-nested-nyquist.png]]&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| align=center | [[Image:pvtol-nested-gangof4.png|x192px]]&lt;br /&gt;
|-&lt;br /&gt;
| align=center | Bode plot&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| align=center | Nyquist plot&lt;br /&gt;
| &amp;amp;nbsp;&lt;br /&gt;
| align=center | Gang of 4&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Murray</name></author>
	</entry>
</feed>