Skip to content

Commit 7e438db

Browse files
author
Murilo M. Marinho
committed
Added first version of lesson 4
1 parent d2ca574 commit 7e438db

8 files changed

Lines changed: 717 additions & 163 deletions

Lesson4.png

20.3 KB
Loading

Lesson4.svg

Lines changed: 243 additions & 0 deletions
Loading

cheat_sheet.ipynb

Lines changed: 163 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"cell_type": "code",
18-
"execution_count": null,
18+
"execution_count": 13,
1919
"metadata": {},
2020
"outputs": [],
2121
"source": [
@@ -26,6 +26,28 @@
2626
"%pip install roboticstoolbox-python --break-system-packages"
2727
]
2828
},
29+
{
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"# Macros\n",
34+
"\n",
35+
"$\\providecommand{\\myvec}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}$\n",
36+
"$\\providecommand{\\mymatrix}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}$"
37+
]
38+
},
39+
{
40+
"cell_type": "raw",
41+
"metadata": {
42+
"vscode": {
43+
"languageId": "raw"
44+
}
45+
},
46+
"source": [
47+
"\\providecommand{\\myvec}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}\n",
48+
"\\providecommand{\\mymatrix}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}"
49+
]
50+
},
2951
{
3052
"cell_type": "markdown",
3153
"metadata": {},
@@ -35,7 +57,7 @@
3557
},
3658
{
3759
"cell_type": "code",
38-
"execution_count": null,
60+
"execution_count": 14,
3961
"metadata": {},
4062
"outputs": [],
4163
"source": [
@@ -55,9 +77,38 @@
5577
},
5678
{
5779
"cell_type": "code",
58-
"execution_count": null,
80+
"execution_count": 15,
5981
"metadata": {},
60-
"outputs": [],
82+
"outputs": [
83+
{
84+
"name": "stdout",
85+
"output_type": "stream",
86+
"text": [
87+
" \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n",
88+
" \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n",
89+
" \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n",
90+
"\n",
91+
"The original SE(2) object was \n",
92+
" \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n",
93+
" \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n",
94+
" \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n",
95+
"\n",
96+
" and can be converted to: \n",
97+
"\tA rotation matrix \n",
98+
"[[ 6.123234e-17 -1.000000e+00]\n",
99+
" [ 1.000000e+00 6.123234e-17]]\n",
100+
" that has size = (2, 2).\n",
101+
"\tA position vector \n",
102+
"[1. 2.]\n",
103+
" that has size = (2,).\n",
104+
"\tA homogenous transformation matrix \n",
105+
"[[ 6.123234e-17 -1.000000e+00 1.000000e+00]\n",
106+
" [ 1.000000e+00 6.123234e-17 2.000000e+00]\n",
107+
" [ 0.000000e+00 0.000000e+00 1.000000e+00]]\n",
108+
" that has size = (3, 3).\n"
109+
]
110+
}
111+
],
61112
"source": [
62113
"import numpy as np\n",
63114
"import spatialmath as sm\n",
@@ -91,9 +142,42 @@
91142
},
92143
{
93144
"cell_type": "code",
94-
"execution_count": null,
145+
"execution_count": 16,
95146
"metadata": {},
96-
"outputs": [],
147+
"outputs": [
148+
{
149+
"name": "stdout",
150+
"output_type": "stream",
151+
"text": [
152+
" \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n",
153+
" \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n",
154+
" \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;4m 3 \u001b[0m \u001b[0m\n",
155+
" \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n",
156+
"\n",
157+
"The original SE(2) object was \n",
158+
" \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n",
159+
" \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n",
160+
" \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;4m 3 \u001b[0m \u001b[0m\n",
161+
" \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n",
162+
"\n",
163+
" and can be converted to: \n",
164+
"\tA rotation matrix \n",
165+
"[[ 6.123234e-17 -1.000000e+00 0.000000e+00]\n",
166+
" [ 1.000000e+00 6.123234e-17 0.000000e+00]\n",
167+
" [ 0.000000e+00 0.000000e+00 1.000000e+00]]\n",
168+
" that has size = (3, 3).\n",
169+
"\tA position vector \n",
170+
"[1. 2. 3.]\n",
171+
" that has size = (3,).\n",
172+
"\tA homogenous transformation matrix \n",
173+
"[[ 6.123234e-17 -1.000000e+00 0.000000e+00 1.000000e+00]\n",
174+
" [ 1.000000e+00 6.123234e-17 0.000000e+00 2.000000e+00]\n",
175+
" [ 0.000000e+00 0.000000e+00 1.000000e+00 3.000000e+00]\n",
176+
" [ 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00]]\n",
177+
" that has size = (4, 4).\n"
178+
]
179+
}
180+
],
97181
"source": [
98182
"import numpy as np\n",
99183
"import spatialmath as sm\n",
@@ -128,9 +212,17 @@
128212
},
129213
{
130214
"cell_type": "code",
131-
"execution_count": null,
215+
"execution_count": 17,
132216
"metadata": {},
133-
"outputs": [],
217+
"outputs": [
218+
{
219+
"name": "stdout",
220+
"output_type": "stream",
221+
"text": [
222+
"True\n"
223+
]
224+
}
225+
],
134226
"source": [
135227
"import numpy as np\n",
136228
"import spatialmath as sm\n",
@@ -149,11 +241,73 @@
149241
"# Compare HC.A and HC_np\n",
150242
"print(np.allclose(HC.A, HC_np))"
151243
]
244+
},
245+
{
246+
"cell_type": "markdown",
247+
"metadata": {},
248+
"source": [
249+
"If you're having problems comparing matrices with \"similar\" dimesions, try to use `numpy.squeeze` when applicable. \n",
250+
"\n",
251+
"To understand the problem, see $\\myvec{v}_1$ and $\\myvec{v}_2$ below"
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"execution_count": 18,
257+
"metadata": {},
258+
"outputs": [
259+
{
260+
"name": "stdout",
261+
"output_type": "stream",
262+
"text": [
263+
"Shapes are not equal, notice that in v1 we have [] and in v2 we have [[]].\n",
264+
"So, v1.shape=(2,) and v2.shape=(1, 2).\n",
265+
"True\n"
266+
]
267+
}
268+
],
269+
"source": [
270+
"import numpy as np\n",
271+
"from math import pi, sin, cos\n",
272+
"\n",
273+
"v1 = np.array([sin(pi/2), cos(pi/2)])\n",
274+
"v2 = np.array([[sin(pi/2), cos(pi/2)]])\n",
275+
"\n",
276+
"print(f\"Shapes are not equal, notice that in v1 we have [] and in v2 we have [[]].\")\n",
277+
"print(f\"So, v1.shape={v1.shape} and v2.shape={v2.shape}.\")\n",
278+
"\n",
279+
"print(np.allclose(v1, v2))"
280+
]
281+
},
282+
{
283+
"cell_type": "markdown",
284+
"metadata": {},
285+
"source": [
286+
"To compare, we do"
287+
]
288+
},
289+
{
290+
"cell_type": "code",
291+
"execution_count": 19,
292+
"metadata": {},
293+
"outputs": [
294+
{
295+
"name": "stdout",
296+
"output_type": "stream",
297+
"text": [
298+
"True\n"
299+
]
300+
}
301+
],
302+
"source": [
303+
"# Compare v1 and v2\n",
304+
"print(np.allclose(np.squeeze(v1), np.squeeze(v2)))"
305+
]
152306
}
153307
],
154308
"metadata": {
155309
"kernelspec": {
156-
"display_name": "Python 3",
310+
"display_name": ".venv",
157311
"language": "python",
158312
"name": "python3"
159313
},

0 commit comments

Comments
 (0)