Skip to content

Commit 1b726c0

Browse files
Merge pull request #19 from LearningToOptimize/ar/update_class01
Add more on linear systems
2 parents 73b7ad5 + 0278021 commit 1b726c0

File tree

2 files changed

+277
-9
lines changed

2 files changed

+277
-9
lines changed

class01/class01_intro.html

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

class01/class01_intro.jl

Lines changed: 275 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ begin
6464
[^ArmManip]: Guechi, E.H., Bouzoualegh, S., Zennir, Y. and Blažič, S., 2018. [MPC control and LQ optimal control of a two-link robot arm: A comparative study](https://www.mdpi.com/2075-1702/6/3/37). Machines, 6(3), p.37.
6565
6666
[^ZachMIT]: Zachary Manchester talk at MIT - [MIT Robotics - Zac Manchester - Composable Optimization for Robotic Motion Planning and Control](https://www.youtube.com/watch?v=eSleutHuc0w&ab_channel=MITRobotics).
67+
68+
[^Hespanha]: Hespanha, J.P., 2018. Linear systems theory. Princeton university press.
6769
6870
"""
6971
)
@@ -430,7 +432,9 @@ section_outline(md"A Crash Course:",md" (Continuous-Time) Dynamics
430432
")
431433

432434
# ╔═╡ 8ea866a6-de0f-4812-8f59-2aebec709243
433-
md"General form for a smooth system:
435+
md"
436+
437+
The general form for the Continuous-Time Dynamics of a smooth system:
434438
435439
```math
436440
\dot{x} = f(x,u) \quad \text{First-Order Ordinary Differential Equation (ODE)}
@@ -799,23 +803,71 @@ A differentiable physics engine for robotics that simulates systems using optimi
799803
warning_box(md"But in general we need a *ReFeynman* of the these equations!")
800804

801805
# ╔═╡ 5f35a169-887f-477f-b010-167627f7ce4c
802-
md"## Linear Systems
806+
md"## (State–Space) Linear Systems
807+
808+
A system is **Continuous Linear** (CLTV / CLTI) if it can be written as:
803809
804810
```math
805811
\dot{x} = A_{t}x + B_{t}u
806812
```
807813
808-
When Time--Invariant vs Time--Variant?
814+
In state–space literature we often also see a **Output Equation**:
815+
```math
816+
y = C_{t}x + D_{t}u
817+
```
818+
819+
but we will neglect it for now.
820+
"
821+
822+
# ╔═╡ 5c8f6256-e818-4aa1-aea0-02422df8f77c
823+
Foldable(md" When do we have a Time--Invariant (TI) vs Time--Variant (TV)?", md"""
824+
825+
When (A,B) are constant we have an LTI system; otherwise it is LTV.
826+
827+
""")
809828

810-
Non--Linear Systems are often approximated by Linear Systems (locally).
829+
# ╔═╡ a3f47dad-3cfa-4f6d-9dc6-d4b09d209f86
830+
md"
831+
**Non--Linear Systems are often approximated by Linear Systems (locally).**
811832
"
812833

813834
# ╔═╡ e860d92b-cc8f-479b-a0fc-e5f7a11ae1fd
814835
Foldable(md" $\dot{x} = f(x,u) \; \implies \; A=? \; B=?$", md"""
815836
837+
Suppose now that we apply our dynamics equation to an input:
838+
816839
```math
817-
A= \frac{\partial f}{\partial x}, \quad A= \frac{\partial f}{\partial u}
840+
u(t) = u_{eq} + \delta u(t), \quad t \ge 0
818841
```
842+
where $u_{eq}$ is an fixed input and $\delta u(t)$ is a perturbation function such that the input is close
843+
but not equal to $u_{eq}$ and similarly we perturb the initial condition:
844+
845+
```math
846+
x(0) = x_e + \delta x(0)
847+
```
848+
849+
We will define the deviation from the reference state as:
850+
```math
851+
\delta x(t) = x(t) - x_e, \quad t \ge 0
852+
```
853+
854+
To determine the evolution of $\delta x(t)$, we can expand the dynamics around the reference point using a Taylor expansion:
855+
856+
```math
857+
\dot{\delta x}(t) = f(x_e + \delta x(t), u_{eq} + \delta u(t))
858+
```
859+
```math
860+
=\frac{\partial f}{\partial x}\bigg|_{(x_e, u_{eq})} \delta x(t) + \frac{\partial f}{\partial u}\bigg|_{(x_e, u_{eq})} \delta u(t) + \mathcal{O}(\|\delta x\|^2) + \mathcal{O}(\|\delta u\|^2)
861+
```
862+
863+
Considering just the first-order terms we obtain:
864+
865+
```math
866+
A= \frac{\partial f}{\partial x}|_{(x_e,u_e)}
867+
, \quad B= \frac{\partial f}{\partial u}|_{(x_e,u_e)}
868+
```
869+
870+
**Attention!** The linearization describes perturbations around the reference $(x_e,u_e)$; it is valid only while $\|\delta x\|$ and $\|\delta u\|$ remain small.
819871
820872
""")
821873

@@ -829,14 +881,19 @@ The problem becomes convex!!
829881
# ╔═╡ 2936c97e-a407-4e56-952f-0a2dfb7acf83
830882
md"""## Equilibria
831883
832-
A point at which the system is and will remain at "rest":
884+
A **Equilibrium** point $(x_{\mathrm{eq}},u_{\mathrm{eq}})$ is one at which the system is and will remain at "rest":
833885
834886
```math
835-
\dot{x} = f(x,u) = 0
887+
\dot{x} = f(x_{\mathrm{eq}},u_{\mathrm{eq}}) = 0
836888
```
837889
838890
The root of the dynamic equations!
839891
892+
In this case,
893+
894+
```math
895+
x(t) = x_{\mathrm{eq}}, \; u(t) = u_{\mathrm{eq}} \; \forall t
896+
```
840897
"""
841898

842899
# ╔═╡ 1a154d04-2b33-43b6-9cb6-accd935de7b7
@@ -1081,6 +1138,208 @@ But the $2^{\text{nd}}$ case is still not asymptotically stable!
10811138
# ╔═╡ da8a1e40-7e7c-472a-933a-c585754270bd
10821139
question_box(md"Can we add a continuous controler to make it asymptotically stable?")
10831140

1141+
# ╔═╡ 211f75ed-8acb-4261-bf97-8fc70be2a79b
1142+
Columns(md"""
1143+
### Example Unicycle Model
1144+
1145+
Consider a unicycle moving in a plane, described by the continuous-time dynamics
1146+
1147+
```math
1148+
\dot p_x = v\cos\theta,\qquad
1149+
\dot p_y = v\sin\theta,\qquad
1150+
\dot\theta = \omega ,
1151+
```
1152+
1153+
where the control input is given by
1154+
$u = [v,\,\omega]^\top$ and $(p_x, p_y)$ are the Cartesian coordinates of the wheel and $\theta$ its orientation.
1155+
1156+
#### Coordinate transformation
1157+
1158+
Introduce the new coordinates
1159+
1160+
```math
1161+
x = \begin{bmatrix}x_1\\x_2\\x_3\end{bmatrix}
1162+
:=
1163+
\begin{bmatrix}
1164+
p_x\cos\theta + (p_y-1)\sin\theta \\[4pt]
1165+
-\,p_x\sin\theta + (p_y-1)\cos\theta \\[4pt]
1166+
\theta
1167+
\end{bmatrix}
1168+
```
1169+
1170+
This transformation can be viewed as a rotation of the position vector about $\theta$.
1171+
""",@htl """
1172+
1173+
<img src="https://media.licdn.com/dms/image/v2/D4E22AQEL2gwfuHbjyg/feedshare-shrink_2048_1536/B4EZbV9cNyHMAo-/0/1747346377441?e=1758758400&v=beta&t=KsIL2efm-3OBWsn8rRMRdqVBDIk65og6WGYxMo7pwZc">
1174+
1175+
<img src="https://media.licdn.com/dms/image/v2/D4E22AQHjrdv5VJpqYw/feedshare-shrink_1280/B4EZbV9cOjGkAo-/0/1747346378871?e=1758758400&v=beta&t=i1gPZeObZyh-tJurAUPvYcpW-El8fx8oIMoG51G9oxw">
1176+
1177+
""")
1178+
1179+
# ╔═╡ 7e7ce801-a510-4ef2-910b-9e10b685ea58
1180+
md"""[Mini Wheelbot ICRA2025](https://www.linkedin.com/posts/sebastian-trimpe-2472a0a3_icra2025-ieee-robotics-activity-7328901914195103746-zr5j/)"""
1181+
1182+
# ╔═╡ 7ad76460-e60c-4579-bee0-ac6f3c511877
1183+
Foldable(md"#### Nonlinear state-space representation",
1184+
md"""
1185+
Differentiating each component gives
1186+
1187+
```math
1188+
\dot x_1 = v + \omega x_2, \qquad
1189+
\dot x_2 = -\omega x_1, \qquad
1190+
\dot x_3 = \omega.
1191+
```
1192+
1193+
Thus the system in compact form is
1194+
1195+
```math
1196+
\dot x =
1197+
\begin{bmatrix}
1198+
v + \omega x_2 \\[2pt]
1199+
-\omega x_1 \\[2pt]
1200+
\omega
1201+
\end{bmatrix}
1202+
```
1203+
1204+
This shows a control-affine nonlinear system.
1205+
"""
1206+
)
1207+
1208+
# ╔═╡ e055fdc3-fb83-4c13-85c9-6edcb661e2dd
1209+
Foldable(md"#### Linearization around the equilibrium ($x^{\ast} = 0, \; u^{\ast} = 0$)",
1210+
md"""
1211+
Define perturbations $\delta x = x - x^{\ast}, \; \delta u = u - u^{\ast}$.
1212+
The linearized dynamics are obtained from the Jacobians
1213+
1214+
```math
1215+
A = \left.\frac{\partial f}{\partial x}\right|_{(x^{\ast},u^{\ast})},
1216+
\quad
1217+
B = \left.\frac{\partial f}{\partial u}\right|_{(x^{\ast},u^{\ast})}.
1218+
```
1219+
1220+
Evaluating,
1221+
1222+
```math
1223+
A = 0_{3\times 3},
1224+
\qquad
1225+
B =
1226+
\begin{bmatrix}
1227+
1 & 0 \\
1228+
0 & 0 \\
1229+
0 & 1
1230+
\end{bmatrix}.
1231+
```
1232+
1233+
"""
1234+
)
1235+
1236+
# ╔═╡ db1c0c1e-9f3b-44b6-8974-6d5ab5e5e8b7
1237+
md"""
1238+
## Local Linearizations around Trajectories
1239+
1240+
Often it is convenient to consider perturbations around an arbitrary (feasible) reference trajectory (*ref*) ($x_{ref}(t)$, $u_{ref}(t)$) instead of an equilibrium point.
1241+
1242+
Now, assuming an input perturbed by a small signal $\delta u(t)$:
1243+
```math
1244+
u(t) = u_{ref}(t) + \delta u(t), \quad t \ge 0
1245+
```
1246+
and a deviation from the reference initial condition:
1247+
```math
1248+
x(0) = x_{ref}(0) + \delta x(0)
1249+
```
1250+
We can define the deviation from the reference state as:
1251+
```math
1252+
\delta x(t) = x(t) - x_{ref}(t), \quad t \ge 0
1253+
```
1254+
To determine the evolution of $\delta x(t)$, we can expand the dynamics around the reference point using a Taylor expansion:
1255+
```math
1256+
\dot{\delta x}(t) = f(x_{ref}(t) + \delta x(t), u_{ref}(t) + \delta u(t))
1257+
```
1258+
```math
1259+
=\frac{\partial f}{\partial x}\bigg|_{(x_{ref}(t), u_{ref}(t))} \delta x(t) + \frac{\partial f}{\partial u}\bigg|_{(x_{ref}(t), u_{ref}(t))} \delta u(t) + \mathcal{O}(\|\delta x\|^2) + \mathcal{O}(\|\delta u\|^2)
1260+
```
1261+
Considering just the first-order terms we obtain:
1262+
```math
1263+
A(t)= \frac{\partial f}{\partial x}|_{(x_{ref}(t),u_{ref}(t))}
1264+
, \quad B(t)= \frac{\partial f}{\partial u}|_{(x_{ref}(t),u_{ref}(t))}
1265+
```
1266+
1267+
> In general, local linearizations around trajectories lead to LTV systems because the partial derivatives need to be computed along the trajectory. However, for some nonlinear systems there are trajectories for which local linearizations actually lead to LTI systems. For models of vehicles (cars, airplanes, helicopters, hovercraft, submarines, etc.) trajectories that lead to LTI local linearizations are called trimming trajectories. They often correspond to motion along straight lines, circumferences, or helices. [^Hespanha]
1268+
1269+
"""
1270+
1271+
# ╔═╡ 04b6560f-aee2-41fd-86fa-d075f0b3d738
1272+
md"""
1273+
### Example Unicycle Model
1274+
1275+
Consider the Reference motion
1276+
```math
1277+
\omega(t)=1,\qquad v(t)=1,\qquad
1278+
p_x(t)=\sin t,\qquad
1279+
p_y(t)=1-\cos t,\qquad
1280+
\theta(t)=t,\quad t\ge 0 .
1281+
```
1282+
Then
1283+
```math
1284+
\dot p_x(t)=\cos t = v\cos\theta,\qquad
1285+
\dot p_y(t)=\sin t = v\sin\theta,\qquad
1286+
\dot\theta(t)=1=\omega,
1287+
```
1288+
so this is indeed a solution of the system.
1289+
1290+
In the rotated coordinates,
1291+
```math
1292+
\begin{align}
1293+
x_1 &= p_x\cos\theta + (p_y-1)\sin\theta \\
1294+
&= \sin t\cos t + (-\cos t)\sin t = 0, \\
1295+
x_2 &= -p_x\sin\theta + (p_y-1)\cos\theta \\
1296+
&= -\sin^2 t - \cos^2 t = -1, \\
1297+
x_3 &=\theta=t.
1298+
\end{align}
1299+
```
1300+
1301+
Hence the reference trajectory in $x$--coordinates is
1302+
```math
1303+
x_{\mathrm{ref}}(t) = \begin{bmatrix}0\\-1\\t\end{bmatrix},\qquad
1304+
u_{\mathrm{ref}}(t)=\begin{bmatrix}1\\1\end{bmatrix}.
1305+
```
1306+
"""
1307+
1308+
# ╔═╡ c7b11f27-1582-45d0-adef-32eb9c6de588
1309+
Foldable(md"Linearization along the trajectory",
1310+
md"""
1311+
Let $f(x,u)=\big[v+\omega x_2,\ -\omega x_1,\ \omega\big]^\top$.
1312+
The Jacobians are
1313+
```math
1314+
A(x,u)=\frac{\partial f}{\partial x}=
1315+
\begin{bmatrix}
1316+
0&\omega&0\\
1317+
-\omega&0&0\\
1318+
0&0&0
1319+
\end{bmatrix},\qquad
1320+
B(x,u)=\frac{\partial f}{\partial u}=
1321+
\begin{bmatrix}
1322+
1&x_2\\
1323+
0&-x_1\\
1324+
0&1
1325+
\end{bmatrix}.
1326+
```
1327+
Evaluating on $(x_{\mathrm{ref}}(t),u_{\mathrm{ref}}(t))$ gives the constant matrices
1328+
```math
1329+
A=\begin{bmatrix}
1330+
0&1&0\\
1331+
-1&0&0\\
1332+
0&0&0
1333+
\end{bmatrix},\qquad
1334+
B=\begin{bmatrix}
1335+
1&-1\\
1336+
0&0\\
1337+
0&1
1338+
\end{bmatrix},
1339+
```
1340+
Therefore time-invariant (LTI) linearization!
1341+
""")
1342+
10841343
# ╔═╡ 4cd2306d-e3f3-4895-8798-596f6c353bdc
10851344
question_box(md"### How do we include the dynamics in control/decision problems?")
10861345

@@ -1489,6 +1748,8 @@ question_box(md"### Why most simulators use Backward--Euler?")
14891748
# ╟─58c2e1f2-819d-40fc-8e92-03a1a3019a3d
14901749
# ╟─70690e72-c31e-4c91-b211-35c74d1d9973
14911750
# ╟─5f35a169-887f-477f-b010-167627f7ce4c
1751+
# ╟─5c8f6256-e818-4aa1-aea0-02422df8f77c
1752+
# ╟─a3f47dad-3cfa-4f6d-9dc6-d4b09d209f86
14921753
# ╟─e860d92b-cc8f-479b-a0fc-e5f7a11ae1fd
14931754
# ╟─bb4bfa72-bf69-41f5-b017-7cbf31653bae
14941755
# ╟─2936c97e-a407-4e56-952f-0a2dfb7acf83
@@ -1509,6 +1770,13 @@ question_box(md"### Why most simulators use Backward--Euler?")
15091770
# ╟─41e1934a-2a43-44c3-9bcf-bef56f4d057e
15101771
# ╟─fc585231-a650-4efb-aea4-95110dbf8fa5
15111772
# ╟─da8a1e40-7e7c-472a-933a-c585754270bd
1773+
# ╟─211f75ed-8acb-4261-bf97-8fc70be2a79b
1774+
# ╟─7e7ce801-a510-4ef2-910b-9e10b685ea58
1775+
# ╟─7ad76460-e60c-4579-bee0-ac6f3c511877
1776+
# ╟─e055fdc3-fb83-4c13-85c9-6edcb661e2dd
1777+
# ╟─db1c0c1e-9f3b-44b6-8974-6d5ab5e5e8b7
1778+
# ╟─04b6560f-aee2-41fd-86fa-d075f0b3d738
1779+
# ╟─c7b11f27-1582-45d0-adef-32eb9c6de588
15121780
# ╟─4cd2306d-e3f3-4895-8798-596f6c353bdc
15131781
# ╟─ca9d4d0c-40c2-4144-866f-db1417d42c8f
15141782
# ╟─3a576353-76bb-4c12-b2a2-b37e8e1dd17f

0 commit comments

Comments
 (0)