Skip to content

Commit 257625e

Browse files
committed
update CDS 110, L1
1 parent ac7d910 commit 257625e

2 files changed

Lines changed: 31 additions & 21 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ venv/
4242
ENV/
4343
env.bak/
4444
venv.bak/
45+
46+
# Files for MacOS
47+
.DS_Store

examples/cds110-L1_servomech-python.ipynb

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"\n",
1616
"[Open in Google Colab](https://colab.research.google.com/drive/1a9ECA-g4Vfi-D3LtbN21xtV9dLzA2RrF)\n",
1717
"\n",
18-
"In this lecture we show how to model an input/output system and design a controller for the system (using eigenvalue placement). This main intent of this lecture is to introduction the Python Control Systems Toolbox ([python-control](https://python-control.org)) and how it can be used to design a control system.\n",
18+
"In this lecture we show how to model an input/output system and design a controller for the system (using eigenvalue placement). This main intent of this lecture is to introduce the Python Control Systems Toolbox ([python-control](https://python-control.org)) and how it can be used to design a control system.\n",
1919
"\n",
2020
"We consider a class of control systems know as *servomechanisms*. Servermechanisms are mechanical systems that use feedback to provide high precision control of position and velocity. Some examples of servomechanisms are shown below:\n",
2121
"\n",
@@ -27,6 +27,14 @@
2727
"| | |"
2828
]
2929
},
30+
{
31+
"cell_type": "markdown",
32+
"id": "2c284896-bcff-4c06-b80d-d9d6fbc0690f",
33+
"metadata": {},
34+
"source": [
35+
"The python-control toolbox can be installed using `pip` over from conda-forge. The code below will import the control toolbox either from your local installation or via pip. We use the prefix `ct` to access control toolbox commands:"
36+
]
37+
},
3038
{
3139
"cell_type": "code",
3240
"execution_count": null,
@@ -54,7 +62,13 @@
5462
"source": [
5563
"## System dynamics\n",
5664
"\n",
57-
"Consider a simple mechanism for positioning a mechanical arm whose equations of motion are given by\n",
65+
"Consider a simple mechanism consisting of a spring loaded arm that is driven by a motor, as shown below:\n",
66+
"\n",
67+
"<center><img src=\"https://www.cds.caltech.edu/~murray/courses/cds110/sp2024/servomech-diagram.png\" width=200 alt=\"servomech-diagram\"></center>\n",
68+
"\n",
69+
"The motor applies a torque that twists the arm against a linear spring and moves the end of the arm across a rotating platter. The input to the system is the motor torque $\\tau_\\text{m}$. The force exerted by the spring is a nonlinear function of the head position due to the way it is attached.\n",
70+
"\n",
71+
"The equations of motion for the system are given by\n",
5872
"\n",
5973
"$$\n",
6074
"J \\ddot \\theta = -b \\dot\\theta - k r\\sin\\theta + \\tau_\\text{m},\n",
@@ -68,12 +82,6 @@
6882
" + \\begin{bmatrix} 0 \\\\ 1/J \\end{bmatrix} \\tau_\\text{m}.\n",
6983
"$$\n",
7084
"\n",
71-
"The system consists of a spring loaded arm that is driven by a motor, as shown below:\n",
72-
"\n",
73-
"<center><img src=\"https://www.cds.caltech.edu/~murray/courses/cds110/sp2024/servomech-diagram.png\" width=200 alt=\"servomech-diagram\"></center>\n",
74-
"\n",
75-
"The motor applies a torque that twists the arm against a linear spring and moves the end of the arm across a rotating platter. The input to the system is the motor torque $\\tau_\\text{m}$. The force exerted by the spring is a nonlinear function of the head position due to the way it is attached.\n",
76-
"\n",
7785
"The system parameters are given by\n",
7886
"\n",
7987
"$$\n",
@@ -203,7 +211,7 @@
203211
"id": "naH-Nl7V4c2R"
204212
},
205213
"source": [
206-
"Alternatively, we can look at the eigenvalues of the \"dynamics matrix\" for the linearized system (we will learn about this formulation in week 3):"
214+
"Alternatively, we can look at the eigenvalues of the \"dynamics matrix\" for the linearized system (we will learn about this formulation in [Lecture 3](cds110-L3_lti-systems.ipynb)):"
207215
]
208216
},
209217
{
@@ -278,7 +286,7 @@
278286
"plt.plot([0, 0], [0, 2.5], 'k:')\n",
279287
"plt.plot([results['SettlingTime'], results['SettlingTime']], [0, 2.5], 'k:')\n",
280288
"plt.arrow(0, 1.5, results['SettlingTime'], 0)\n",
281-
"plt.text(results['SettlingTime']/2, 1.6, '$T_s$')\n"
289+
"plt.text(results['SettlingTime']/2, 1.6, '$T_s$');\n"
282290
]
283291
},
284292
{
@@ -317,7 +325,7 @@
317325
"plt.xlabel(\"Time $t$ [ms]\")\n",
318326
"plt.ylabel(\"Position $y$ [cm]\")\n",
319327
"plt.title(\"Step response for the open-loop system\")\n",
320-
"plt.legend()"
328+
"plt.legend();"
321329
]
322330
},
323331
{
@@ -356,7 +364,7 @@
356364
"\n",
357365
"# Find the gains required to place the gains at the desired location\n",
358366
"K = ct.place(P.A, P.B, [-10 + 10*1j, -10 - 10*1j])\n",
359-
"print(f\"{K=}\")\n",
367+
"print(f\"{K=}\\n\")\n",
360368
"\n",
361369
"# Implement an I/O system implementing this control law\n",
362370
"def statefbk_output(t, x, u, params):\n",
@@ -370,7 +378,8 @@
370378
" None, statefbk_output, name='statefbk',\n",
371379
" inputs=['y', 'thdot', 'y_d', 'thdot_d'],\n",
372380
" outputs=['tau']\n",
373-
")"
381+
")\n",
382+
"print(statefbk)"
374383
]
375384
},
376385
{
@@ -404,7 +413,8 @@
404413
" [servomech, statefbk],\n",
405414
" inputs=['y_d', 'thdot_d'],\n",
406415
" outputs=['y', 'tau']\n",
407-
")"
416+
")\n",
417+
"print(clsys)"
408418
]
409419
},
410420
{
@@ -470,7 +480,7 @@
470480
"\n",
471481
"where the magnitude $M$ and phase $\\phi$ depend on the input frequency.\n",
472482
"\n",
473-
"We can plot the magnitude (also called the \"gain\" of the system) and the phase as a function of the frequency $\\omega$ and plot these values on a log-log and log-linear scale (called a *Bode* plot):"
483+
"We can plot the magnitude (also called the \"gain\") and the phase of the system as a function of the frequency $\\omega$ and plot these values on a log-log and log-linear scale (called a *Bode* plot):"
474484
]
475485
},
476486
{
@@ -481,14 +491,11 @@
481491
"outputs": [],
482492
"source": [
483493
"# Compute the linearization of the closed loop system\n",
484-
"G = clsys.linearize([theta_e, 0], [0, 0])\n",
494+
"G = clsys.linearize([theta_e, 0], [0, 0], name=\"G\")\n",
485495
"\n",
486496
"# Plot the Bode plot (input[0] = yd, outut[0] = y)\n",
487-
"print(\"Bode plot:\")\n",
488497
"response = ct.frequency_response(G[0, 0])\n",
489-
"out = response.plot()\n",
490-
"axs = ct.get_plot_axes(out)\n",
491-
"axs[1, 0].set_xlabel(\"Frequency [rad/ms]\");"
498+
"cplt = response.plot(title=\"Bode plot for G\", freq_label=\"Frequency [rad/ms]\")"
492499
]
493500
},
494501
{
@@ -508,7 +515,7 @@
508515
"id": "rocky-hobby"
509516
},
510517
"source": [
511-
"## Trajectory tracking (if time)\n",
518+
"## Trajectory tracking\n",
512519
"\n",
513520
"Another type of analysis we might do is to see how well the system can track a more complicated reference trajectory. For the disk drive example, we might move the system from one point on the disk to a second and then to a third (as we read different portions of the disk).\n",
514521
"\n",

0 commit comments

Comments
 (0)