Skip to content

Commit 79fc380

Browse files
committed
using widgets backend, work locally
1 parent 7afcfbf commit 79fc380

File tree

2 files changed

+62
-83
lines changed

2 files changed

+62
-83
lines changed

notebooks/chap2.ipynb

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
"try:\n",
2323
" import google.colab\n",
2424
" print('Running on CoLab')\n",
25+
" !pip install spatialmath-python\n",
26+
" !pip install ipympl\n",
2527
" COLAB = True\n",
26-
" !pip install roboticstoolbox-python>=1.0.2\n",
2728
" SWIFT = False\n",
2829
"except ModuleNotFoundError:\n",
2930
" COLAB = False\n",
@@ -32,16 +33,10 @@
3233
"InteractiveShell.ast_node_interactivity = \"last_expr_or_assign\"\n",
3334
"from IPython.display import HTML\n",
3435
"\n",
35-
"# add RTB examples folder to the path\n",
36-
"import sys\n",
37-
"import os.path\n",
38-
"import roboticstoolbox as rtb\n",
39-
"sys.path.append(os.path.join(rtb.__path__[0], 'examples'))\n",
40-
"\n",
4136
"# standard imports\n",
42-
"%matplotlib inline\n",
4337
"import numpy as np\n",
4438
"from scipy import linalg\n",
39+
"%matplotlib widget\n",
4540
"import matplotlib.pyplot as plt\n",
4641
"import math\n",
4742
"from math import pi\n",
@@ -50,7 +45,18 @@
5045
" 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\n",
5146
"np.random.seed(0)\n",
5247
"from spatialmath import *\n",
53-
"from spatialmath.base import *\n"
48+
"from spatialmath.base import *"
49+
]
50+
},
51+
{
52+
"attachments": {},
53+
"cell_type": "markdown",
54+
"id": "b1de4c86",
55+
"metadata": {},
56+
"source": [
57+
"There are some minor code changes compared to the book. These are to support \n",
58+
"the Matplotlib widget (ipympl) backend. This allows 3D plots to be rotated\n",
59+
"so the changes are worthwhile."
5460
]
5561
},
5662
{
@@ -102,6 +108,7 @@
102108
"metadata": {},
103109
"outputs": [],
104110
"source": [
111+
"plotvol2(new=True) # for matplotlib/widget\n",
105112
"trplot2(R);"
106113
]
107114
},
@@ -298,7 +305,7 @@
298305
"metadata": {},
299306
"outputs": [],
300307
"source": [
301-
"plotvol2([0, 5]); # new plot with both axes from 0 to 5\n",
308+
"plotvol2([0, 5], new=True); # new plot with both axes from 0 to 5\n",
302309
"trplot2(TA, frame=\"A\", color=\"b\");\n",
303310
"T0 = transl2(0, 0);\n",
304311
"trplot2(T0, frame=\"0\", color=\"k\"); # reference frame\n",
@@ -359,7 +366,7 @@
359366
"metadata": {},
360367
"outputs": [],
361368
"source": [
362-
"plotvol2([-5, 4, -1, 5]);\n",
369+
"plotvol2([-5, 4, -1, 5], new=True); # for matplotlib/widget\n",
363370
"T0 = transl2(0, 0);\n",
364371
"trplot2(T0, frame=\"0\", color=\"k\");\n",
365372
"TX = transl2(2, 3);\n",
@@ -590,6 +597,7 @@
590597
"metadata": {},
591598
"outputs": [],
592599
"source": [
600+
"plotvol3(new=True) # for matplotlib/widget\n",
593601
"trplot(R);"
594602
]
595603
},
@@ -601,6 +609,7 @@
601609
"outputs": [],
602610
"source": [
603611
"# tranimate(R)\n",
612+
"plotvol3(new=True)\n",
604613
"HTML(tranimate(R, movie=True))"
605614
]
606615
},
@@ -661,6 +670,7 @@
661670
"metadata": {},
662671
"outputs": [],
663672
"source": [
673+
"plotvol3(new=True) # for matplotlib/widget\n",
664674
"trplot(Ryx);"
665675
]
666676
},
@@ -1165,6 +1175,7 @@
11651175
"metadata": {},
11661176
"outputs": [],
11671177
"source": [
1178+
"plotvol3(new=True) # for matplotlib/widget\n",
11681179
"q.plot();"
11691180
]
11701181
},
@@ -1201,6 +1212,7 @@
12011212
"metadata": {},
12021213
"outputs": [],
12031214
"source": [
1215+
"plotvol3(new=True) # for matplotlib/widget\n",
12041216
"trplot(T);"
12051217
]
12061218
},
@@ -1621,7 +1633,7 @@
16211633
"metadata": {},
16221634
"outputs": [],
16231635
"source": [
1624-
"plotvol3([-5, 5]) # setup volume in which to display the line\n",
1636+
"plotvol3([-5, 5], new=True) # setup volume in which to display the line\n",
16251637
"line.plot(\"k:\", linewidth=2);"
16261638
]
16271639
},
@@ -1851,6 +1863,7 @@
18511863
"metadata": {},
18521864
"outputs": [],
18531865
"source": [
1866+
"plotvol2(new=True) # for matplotlib/widget\n",
18541867
"TA.plot(frame=\"A\", color=\"b\");"
18551868
]
18561869
},
@@ -1919,7 +1932,7 @@
19191932
"name": "python",
19201933
"nbconvert_exporter": "python",
19211934
"pygments_lexer": "ipython3",
1922-
"version": "3.11.0"
1935+
"version": "3.10.9"
19231936
},
19241937
"vscode": {
19251938
"interpreter": {

notebooks/chap3.ipynb

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,25 @@
2323
" import google.colab\n",
2424
" print('Running on CoLab')\n",
2525
" COLAB = True\n",
26-
" !pip install roboticstoolbox-python>=1.0.2\n",
26+
" !pip install spatialmath-python\n",
27+
" !pip install ipympl\n",
28+
" !pip install --no-deps roboticstoolbox-python>=1.0.2\n",
2729
" !pip install --no-deps rvc3python\n",
30+
"\n",
2831
"except ModuleNotFoundError:\n",
2932
" COLAB = False\n",
3033
"\n",
3134
"from IPython.core.interactiveshell import InteractiveShell\n",
3235
"InteractiveShell.ast_node_interactivity = \"last_expr_or_assign\"\n",
36+
"\n",
3337
"from IPython.display import HTML\n",
38+
"import urllib.request\n",
3439
"\n",
3540
"# add RTB examples folder to the path\n",
3641
"import sys, os.path\n",
3742
"import roboticstoolbox as rtb\n",
3843
"import RVC3\n",
39-
"sys.path.append(os.path.join(rtb.__path__[0], 'examples'))\n",
44+
"# sys.path.append(os.path.join(rtb.__path__[0], 'examples'))\n",
4045
"sys.path.append(os.path.join(RVC3.__path__[0], 'examples'))\n",
4146
"\n",
4247
"# standard imports\n",
@@ -50,7 +55,20 @@
5055
"np.random.seed(0)\n",
5156
"from spatialmath import *\n",
5257
"from spatialmath.base import *\n",
53-
"from roboticstoolbox import quintic, trapezoidal, mtraj, mstraj, xplot, ctraj"
58+
"from roboticstoolbox import quintic, trapezoidal, mtraj, mstraj, xplot, ctraj\n",
59+
"%matplotlib widget\n",
60+
"import matplotlib.pyplot as plt\n"
61+
]
62+
},
63+
{
64+
"attachments": {},
65+
"cell_type": "markdown",
66+
"id": "faa9a9d4",
67+
"metadata": {},
68+
"source": [
69+
"There are some minor code changes compared to the book. These are to support \n",
70+
"the Matplotlib widget (ipympl) backend. This allows 3D plots to be rotated\n",
71+
"so the changes are worthwhile."
5472
]
5573
},
5674
{
@@ -257,9 +275,9 @@
257275
" orientation *= UnitQuaternion.EulerVec(w * dt)\n",
258276
" yield orientation.R\n",
259277
"\n",
260-
"plt.close(\"all\")\n",
261-
"# tranimate(update(), dims=[-1.5,1.5,-1.5,1.5,-1.5,1.5]);\n",
262-
"HTML(tranimate(update(), dims=[-1.5,1.5,-1.5,1.5,-1.5,1.5], movie=True));"
278+
"# tranimate(update(), dim=1.5);\n",
279+
"plotvol3(new=True)\n",
280+
"HTML(tranimate(update(), dim=1.5, movie=True))"
263281
]
264282
},
265283
{
@@ -558,7 +576,8 @@
558576
"outputs": [],
559577
"source": [
560578
"# qtraj.animate()\n",
561-
"HTML(qtraj.animate(movie=True));"
579+
"plotvol3(new=True) # for matplotlib/widget\n",
580+
"HTML(qtraj.animate(movie=True))"
562581
]
563582
},
564583
{
@@ -578,8 +597,9 @@
578597
"source": [
579598
"q0 = UnitQuaternion.Rz(-2); q1 = UnitQuaternion.Rz(2);\n",
580599
"q = q0.interp(q1, 50);\n",
581-
"# q.animate()\n",
582-
"HTML(q.animate(movie=True))"
600+
"# q.animate(dim=1.])\n",
601+
"plotvol3(new=True) # for matplotlib/widget\n",
602+
"HTML(q.animate(movie=True, dim=1.5))"
583603
]
584604
},
585605
{
@@ -591,7 +611,8 @@
591611
"source": [
592612
"q = q0.interp(q1, 50, shortest=True);\n",
593613
"# q.animate()\n",
594-
"HTML(q.animate(movie=True))"
614+
"plotvol3(new=True) # for matplotlib/widget\n",
615+
"HTML(q.animate(movie=True, dim=1.5))"
595616
]
596617
},
597618
{
@@ -651,7 +672,8 @@
651672
"outputs": [],
652673
"source": [
653674
"# Ts.animate()\n",
654-
"HTML(Ts.animate(movie=True))"
675+
"plotvol3(new=True) # for matplotlib/widget\n",
676+
"HTML(Ts.animate(movie=True, dim=1.5))"
655677
]
656678
},
657679
{
@@ -732,14 +754,6 @@
732754
"## 3.4.1 Gyroscopes\n"
733755
]
734756
},
735-
{
736-
"cell_type": "markdown",
737-
"id": "8f4c845b",
738-
"metadata": {},
739-
"source": [
740-
"### 3.4.1.1 How Gyroscopes Work\n"
741-
]
742-
},
743757
{
744758
"cell_type": "markdown",
745759
"id": "c8b681b9",
@@ -790,7 +804,7 @@
790804
"outputs": [],
791805
"source": [
792806
"# orientation.animate(time=true.t)\n",
793-
"HTML(orientation.animate(time=true.t, movie=True))"
807+
"HTML(orientation.animate(time=true.t, movie=True, dim=1.5))"
794808
]
795809
},
796810
{
@@ -803,54 +817,6 @@
803817
"xplot(true.t, orientation.rpy(), labels=\"roll pitch yaw\");"
804818
]
805819
},
806-
{
807-
"cell_type": "markdown",
808-
"id": "7b7a9cb6",
809-
"metadata": {},
810-
"source": [
811-
"## 3.4.2 Accelerometers\n"
812-
]
813-
},
814-
{
815-
"cell_type": "markdown",
816-
"id": "5ecd0f01",
817-
"metadata": {},
818-
"source": [
819-
"### 3.4.2.1 How Accelerometers Work\n"
820-
]
821-
},
822-
{
823-
"cell_type": "markdown",
824-
"id": "e853b684",
825-
"metadata": {},
826-
"source": [
827-
"### 3.4.2.2 Estimating Pose and Body Acceleration\n"
828-
]
829-
},
830-
{
831-
"cell_type": "markdown",
832-
"id": "01e778eb",
833-
"metadata": {},
834-
"source": [
835-
"## 3.4.3 Magnetometers\n"
836-
]
837-
},
838-
{
839-
"cell_type": "markdown",
840-
"id": "b2a83e52",
841-
"metadata": {},
842-
"source": [
843-
"### 3.4.3.1 How Magnetometers Work\n"
844-
]
845-
},
846-
{
847-
"cell_type": "markdown",
848-
"id": "10cafe42",
849-
"metadata": {},
850-
"source": [
851-
"### 3.4.3.2 Estimating Heading\n"
852-
]
853-
},
854820
{
855821
"cell_type": "markdown",
856822
"id": "f358dff8",
@@ -943,7 +909,7 @@
943909
"name": "python",
944910
"nbconvert_exporter": "python",
945911
"pygments_lexer": "ipython3",
946-
"version": "3.11.0"
912+
"version": "3.10.9"
947913
},
948914
"vscode": {
949915
"interpreter": {
@@ -953,4 +919,4 @@
953919
},
954920
"nbformat": 4,
955921
"nbformat_minor": 5
956-
}
922+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy