Skip to content

Commit 7821e2b

Browse files
committed
add jupyter notebooks to documentation + updated notebooks
1 parent bd1e8e0 commit 7821e2b

9 files changed

Lines changed: 212 additions & 93 deletions

doc/examples.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ using running examples in FBS2e.
4444

4545
cruise
4646
describing_functions
47+
kincar-fusion
4748
mpc_aircraft
4849
steering
4950
pvtol-lqr-nested
51+
pvtol-outputfbk
52+
stochresp

doc/kincar-fusion.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../examples/kincar-fusion.ipynb

doc/pvtol-outputfbk.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../examples/pvtol-outputfbk.ipynb

doc/stochresp.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../examples/stochresp.ipynb

examples/kincar-fusion.ipynb

Lines changed: 93 additions & 37 deletions
Large diffs are not rendered by default.

examples/pvtol-lqr-nested.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
],
533533
"metadata": {
534534
"kernelspec": {
535-
"display_name": "Python 3",
535+
"display_name": "Python 3 (ipykernel)",
536536
"language": "python",
537537
"name": "python3"
538538
},

examples/pvtol-outputfbk.ipynb

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"id": "c017196f",
66
"metadata": {},
77
"source": [
8-
"# PVTOL LQR + EQF example\n",
8+
"# Output feedback control using LQR and extended Kalman filtering\n",
99
"RMM, 14 Feb 2022\n",
1010
"\n",
11-
"This notebook illustrates the implementation of an extended Kalman filter and the use of the estimated state for LQR feedback."
11+
"This notebook illustrates the implementation of an extended Kalman filter and the use of the estimated state for LQR feedback of a vectored thrust aircraft model."
1212
]
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 1,
16+
"execution_count": 11,
1717
"id": "544525ab",
1818
"metadata": {},
1919
"outputs": [],
@@ -30,26 +30,40 @@
3030
"metadata": {},
3131
"source": [
3232
"## System definition\n",
33-
"The dynamics of the system\n",
34-
"with disturbances on the $x$ and $y$ variables is given by\n",
33+
"We consider a (planar) vertical takeoff and landing aircraf model:\n",
34+
"\n",
35+
"![PVTOL diagram](https://murray.cds.caltech.edu/images/murray.cds/7/7d/Pvtol-diagram.png)\n",
36+
"\n",
37+
"The dynamics of the system with disturbances on the $x$ and $y$ variables are given by\n",
38+
"\n",
3539
"$$\n",
3640
" \\begin{aligned}\n",
3741
" m \\ddot x &= F_1 \\cos\\theta - F_2 \\sin\\theta - c \\dot x + d_x, \\\\\n",
3842
" m \\ddot y &= F_1 \\sin\\theta + F_2 \\cos\\theta - c \\dot y - m g + d_y, \\\\\n",
3943
" J \\ddot \\theta &= r F_1.\n",
4044
" \\end{aligned}\n",
4145
"$$\n",
46+
"\n",
4247
"The measured values of the system are the position and orientation,\n",
4348
"with added noise $n_x$, $n_y$, and $n_\\theta$:\n",
49+
"\n",
4450
"$$\n",
4551
" \\vec y = \\begin{bmatrix} x \\\\ y \\\\ \\theta \\end{bmatrix} + \n",
4652
" \\begin{bmatrix} n_x \\\\ n_y \\\\ n_z \\end{bmatrix}.\n",
47-
"$$\n"
53+
"$$"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"id": "198a068d",
59+
"metadata": {},
60+
"source": [
61+
"The dynamics are defined in the `pvtol` module:"
4862
]
4963
},
5064
{
5165
"cell_type": "code",
52-
"execution_count": 2,
66+
"execution_count": 12,
5367
"id": "ffafed74",
5468
"metadata": {},
5569
"outputs": [
@@ -93,9 +107,17 @@
93107
"print(noisy_pvtol)"
94108
]
95109
},
110+
{
111+
"cell_type": "markdown",
112+
"id": "be6ec05c",
113+
"metadata": {},
114+
"source": [
115+
"We also define the properties of the disturbances, noise, and initial conditions:"
116+
]
117+
},
96118
{
97119
"cell_type": "code",
98-
"execution_count": 3,
120+
"execution_count": 13,
99121
"id": "1e1ee7c9",
100122
"metadata": {},
101123
"outputs": [],
@@ -114,20 +136,22 @@
114136
"id": "e4c52c73",
115137
"metadata": {},
116138
"source": [
117-
"## Control system design"
139+
"## Control system design\n",
140+
"\n",
141+
"We start be defining an extended Kalman filter to estimate the state of the system from the measured outputs."
118142
]
119143
},
120144
{
121145
"cell_type": "code",
122-
"execution_count": 4,
146+
"execution_count": 14,
123147
"id": "3647bf15",
124148
"metadata": {},
125149
"outputs": [
126150
{
127151
"name": "stdout",
128152
"output_type": "stream",
129153
"text": [
130-
"Object: sys[1]\n",
154+
"Object: sys[3]\n",
131155
"Inputs (5): x0, x1, x2, F1, F2, \n",
132156
"Outputs (6): xh0, xh1, xh2, xh3, xh4, xh5, \n",
133157
"States (42): x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19], x[20], x[21], x[22], x[23], x[24], x[25], x[26], x[27], x[28], x[29], x[30], x[31], x[32], x[33], x[34], x[35], x[36], x[37], x[38], x[39], x[40], x[41], \n"
@@ -175,9 +199,17 @@
175199
"print(estimator)"
176200
]
177201
},
202+
{
203+
"cell_type": "markdown",
204+
"id": "8c97626d",
205+
"metadata": {},
206+
"source": [
207+
"We now define an LQR controller, using a physically motivated weighting:"
208+
]
209+
},
178210
{
179211
"cell_type": "code",
180-
"execution_count": 5,
212+
"execution_count": 15,
181213
"id": "9787db61",
182214
"metadata": {},
183215
"outputs": [
@@ -209,14 +241,11 @@
209241
"Object: xh5\n",
210242
"Inputs (13): xd[0], xd[1], xd[2], xd[3], xd[4], xd[5], ud[0], ud[1], Dx, Dy, Nx, Ny, Nth, \n",
211243
"Outputs (14): x0, x1, x2, x3, x4, x5, F1, F2, xh0, xh1, xh2, xh3, xh4, xh5, \n",
212-
"States (48): noisy_pvtol_x0, noisy_pvtol_x1, noisy_pvtol_x2, noisy_pvtol_x3, noisy_pvtol_x4, noisy_pvtol_x5, sys[1]_x[0], sys[1]_x[1], sys[1]_x[2], sys[1]_x[3], sys[1]_x[4], sys[1]_x[5], sys[1]_x[6], sys[1]_x[7], sys[1]_x[8], sys[1]_x[9], sys[1]_x[10], sys[1]_x[11], sys[1]_x[12], sys[1]_x[13], sys[1]_x[14], sys[1]_x[15], sys[1]_x[16], sys[1]_x[17], sys[1]_x[18], sys[1]_x[19], sys[1]_x[20], sys[1]_x[21], sys[1]_x[22], sys[1]_x[23], sys[1]_x[24], sys[1]_x[25], sys[1]_x[26], sys[1]_x[27], sys[1]_x[28], sys[1]_x[29], sys[1]_x[30], sys[1]_x[31], sys[1]_x[32], sys[1]_x[33], sys[1]_x[34], sys[1]_x[35], sys[1]_x[36], sys[1]_x[37], sys[1]_x[38], sys[1]_x[39], sys[1]_x[40], sys[1]_x[41], \n"
244+
"States (48): noisy_pvtol_x0, noisy_pvtol_x1, noisy_pvtol_x2, noisy_pvtol_x3, noisy_pvtol_x4, noisy_pvtol_x5, sys[3]_x[0], sys[3]_x[1], sys[3]_x[2], sys[3]_x[3], sys[3]_x[4], sys[3]_x[5], sys[3]_x[6], sys[3]_x[7], sys[3]_x[8], sys[3]_x[9], sys[3]_x[10], sys[3]_x[11], sys[3]_x[12], sys[3]_x[13], sys[3]_x[14], sys[3]_x[15], sys[3]_x[16], sys[3]_x[17], sys[3]_x[18], sys[3]_x[19], sys[3]_x[20], sys[3]_x[21], sys[3]_x[22], sys[3]_x[23], sys[3]_x[24], sys[3]_x[25], sys[3]_x[26], sys[3]_x[27], sys[3]_x[28], sys[3]_x[29], sys[3]_x[30], sys[3]_x[31], sys[3]_x[32], sys[3]_x[33], sys[3]_x[34], sys[3]_x[35], sys[3]_x[36], sys[3]_x[37], sys[3]_x[38], sys[3]_x[39], sys[3]_x[40], sys[3]_x[41], \n"
213245
]
214246
}
215247
],
216248
"source": [
217-
"#\n",
218-
"# LQR design w/ physically motivated weighting\n",
219-
"#\n",
220249
"# Shoot for 1 cm error in x, 10 cm error in y. Try to keep the angle\n",
221250
"# less than 5 degrees in making the adjustments. Penalize side forces\n",
222251
"# due to loss in efficiency.\n",
@@ -256,12 +285,14 @@
256285
"id": "7bf558a0",
257286
"metadata": {},
258287
"source": [
259-
"## Simulations"
288+
"## Simulations\n",
289+
"\n",
290+
"We now simulate the response of the system, starting with an instantiation of the noise:"
260291
]
261292
},
262293
{
263294
"cell_type": "code",
264-
"execution_count": 6,
295+
"execution_count": 16,
265296
"id": "c2583a0e",
266297
"metadata": {},
267298
"outputs": [
@@ -302,7 +333,7 @@
302333
},
303334
{
304335
"cell_type": "code",
305-
"execution_count": 7,
336+
"execution_count": 17,
306337
"id": "ad7a9750",
307338
"metadata": {},
308339
"outputs": [
@@ -337,17 +368,17 @@
337368
},
338369
{
339370
"cell_type": "code",
340-
"execution_count": 8,
371+
"execution_count": 18,
341372
"id": "c5f24119",
342373
"metadata": {},
343374
"outputs": [
344375
{
345376
"data": {
346377
"text/plain": [
347-
"<matplotlib.legend.Legend at 0x7f85f8d6ebb0>"
378+
"<matplotlib.legend.Legend at 0x7fa431d8b3a0>"
348379
]
349380
},
350-
"execution_count": 8,
381+
"execution_count": 18,
351382
"metadata": {},
352383
"output_type": "execute_result"
353384
},
@@ -389,12 +420,14 @@
389420
"id": "0c0d5c99",
390421
"metadata": {},
391422
"source": [
392-
"### Full state feedback"
423+
"### Full state feedback\n",
424+
"\n",
425+
"As a comparison, we can investigate the response of the system if the exact state was available:"
393426
]
394427
},
395428
{
396429
"cell_type": "code",
397-
"execution_count": 9,
430+
"execution_count": 19,
398431
"id": "3b6a1f1c",
399432
"metadata": {},
400433
"outputs": [

examples/stochresp.ipynb

Lines changed: 55 additions & 31 deletions
Large diffs are not rendered by default.

examples/vehicle-steering.png

13.2 KB
Loading

0 commit comments

Comments
 (0)