Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions RVC3/models/RRMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
# define the blocks
jacobian = bd.JACOBIAN(robot=puma, frame="0", inverse=True, name="Jacobian")
velocity = bd.CONSTANT([0, 0.05, 0, 0, 0, 0])
qdot = bd.PROD("**", matrix=True)
integrator = bd.DINTEGRATOR(clock, x0=q0, name="q")
qdot = bd.PROD("**")
integrator = bd.INTEGRATOR_S(clock, x0=q0, name="q")
robot = bd.ARMPLOT(robot=puma, q0=q0, name="plot")
# robot = bd.PRINT('{:.3f}')

Expand Down
4 changes: 2 additions & 2 deletions RVC3/models/RRMC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
delta = bd.TR2DELTA()
jacobian = bd.JACOBIAN(robot=puma, frame="e", inverse=True, name="Jacobian")
gain = bd.GAIN(Kp)
qdot = bd.PROD("**", matrix=True)
integrator = bd.DINTEGRATOR(clock, x0=q0, name="q")
qdot = bd.PROD("**")
integrator = bd.INTEGRATOR_S(clock, x0=q0, name="q")
fkine = bd.FKINE(puma)
robot = bd.ARMPLOT(robot=puma, q0=q0, name="plot")
tr2t = bd.TR2T()
Expand Down
23 changes: 3 additions & 20 deletions notebooks/chap15.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,7 @@
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy import linalg\n",
"import matplotlib.pyplot as plt\n",
"import math\n",
"from math import pi\n",
"np.set_printoptions(\n",
" linewidth=120, formatter={\n",
" 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\n",
"np.random.seed(0)\n",
"\n",
"from machinevisiontoolbox.base import *\n",
"from machinevisiontoolbox import *\n",
"from spatialmath.base import *\n",
"from spatialmath import *"
]
"source": "import numpy as np\nfrom scipy import linalg\nimport matplotlib.pyplot as plt\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\n\nfrom machinevisiontoolbox.base import *\nfrom machinevisiontoolbox import *\nfrom spatialmath.base import *\nfrom spatialmath import *\n\nimport sys, os.path\nimport RVC3 as rvc\nmodels_dir = os.path.join(rvc.__path__[0], 'models')"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -518,9 +503,7 @@
"id": "48",
"metadata": {},
"outputs": [],
"source": [
"%run -m IBVS-main -H"
]
"source": "%run -i $models_dir/IBVS-main.py -H"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -791,4 +774,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
47 changes: 8 additions & 39 deletions notebooks/chap16.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,7 @@
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"import sys, os.path\n",
"import RVC3 as rvc\n",
"sys.path.append(os.path.join(rvc.__path__[0], 'models'))\n",
"\n",
"import numpy as np\n",
"from scipy import linalg\n",
"import matplotlib.pyplot as plt\n",
"import math\n",
"from math import pi\n",
"np.set_printoptions(\n",
" linewidth=120, formatter={\n",
" 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\n",
"np.random.seed(0)\n",
"\n",
"from machinevisiontoolbox.base import *\n",
"from machinevisiontoolbox import *\n",
"from spatialmath.base import *\n",
"from spatialmath import *"
]
"source": "import numpy as np\nfrom scipy import linalg\nimport matplotlib.pyplot as plt\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\n\nfrom machinevisiontoolbox.base import *\nfrom machinevisiontoolbox import *\nfrom spatialmath.base import *\nfrom spatialmath import *\n\nimport sys, os.path\nimport RVC3 as rvc\nmodels_dir = os.path.join(rvc.__path__[0], 'models')"
},
{
"cell_type": "markdown",
Expand All @@ -79,9 +60,7 @@
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"%run -m IBVS-partitioned-main -H"
]
"source": "%run -i $models_dir/IBVS-partitioned-main.py -H"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -185,19 +164,15 @@
"id": "15",
"metadata": {},
"outputs": [],
"source": [
"%run -m IBVS-arm-main -H"
]
"source": "%run -i $models_dir/IBVS-arm-main.py -H"
},
{
"cell_type": "code",
"execution_count": null,
"id": "16",
"metadata": {},
"outputs": [],
"source": [
"plt.plot(out.clock1.t, out.clock1.x)"
]
"source": "plt.plot(out.clock1.t, out.clock1.X)"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -251,9 +226,7 @@
"id": "22",
"metadata": {},
"outputs": [],
"source": [
"%run -m IBVS-holonomic-main -H"
]
"source": "%run -i $models_dir/IBVS-holonomic-main.py -H"
},
{
"cell_type": "markdown",
Expand All @@ -269,9 +242,7 @@
"id": "24",
"metadata": {},
"outputs": [],
"source": [
"%run -m IBVS-nonholonomic-main -H"
]
"source": "%run -i $models_dir/IBVS-nonholonomic-main.py -H"
},
{
"cell_type": "markdown",
Expand All @@ -287,9 +258,7 @@
"id": "26",
"metadata": {},
"outputs": [],
"source": [
"%run -m IBVS-quadrotor-main -H"
]
"source": "%run -i $models_dir/IBVS-quadrotor-main.py -H"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -349,4 +318,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
11 changes: 3 additions & 8 deletions notebooks/chap5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"outputs": [],
"source": "from IPython.display import HTML\n\nimport matplotlib.pyplot as plt\n\n# add RTB examples folder to the path\nimport sys, os.path\nimport RVC3 as rvc\nsys.path.append(os.path.join(rvc.__path__[0], 'models'))\n\n# helper function to run bdsim in a subprocess and transfer results using a pickle file\nimport pickle\ndef run_shell(tool, **params):\n global out\n pyfile = os.path.join(rvc.__path__[0], \"models\", tool+\".py\")\n cmd = f\"python {pyfile} -H +a -o\"\n for key, value in params.items():\n cmd += f' --global \"{key}={value}\"'\n print(cmd)\n os.system(cmd)\n with open(\"bd.out\", \"rb\") as f:\n out = pickle.load(f)\n \n# ------ standard imports ------ #\nimport numpy as np\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\nfrom spatialmath import *\nfrom spatialmath.base import *\nfrom roboticstoolbox import *"
"source": "from IPython.display import HTML\n\nimport matplotlib.pyplot as plt\n\n# add RTB examples folder to the path\nimport sys, os.path\nimport RVC3 as rvc\nmodels_dir = os.path.join(rvc.__path__[0], 'models')\nsys.path.append(models_dir)\n\n# ------ standard imports ------ #\nimport numpy as np\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\nfrom spatialmath import *\nfrom spatialmath.base import *\nfrom roboticstoolbox import *"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -69,20 +69,15 @@
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": "<div class=\"alert alert-block alert-warning\">\n\n**Warning:** There are issues in running bdsim from inside Jupyter. We have two options, disable all graphics (which is a bit dull) or run bdsim from a subprocess with its own popout windows.\n\nFor Colab we can only do the first option. \n\nOtherwise, we use the wrapper function `run_shell()` defined in the first cell to spawn a new Python instance to run the block diagram which will pop up new windows on your screen to display a simple animation showing the vehicle's motion in the plane. This makes it a bit harder to get parameters and data between Jupyter and the `bdsim` simulation, so:\n* parameter values are passed to `bdsim` as `--global` command line options.\n* the `-o` command line option to `bdsim` causes it to write results as a pickle file, which are then imported back into Jupyter.\n\n</div>"
"source": "<div class=\"alert alert-block alert-info\">\n\n**Note:** Earlier editions of this notebook ran `bdsim` in a subprocess to work around animation issues inside Jupyter. That's no longer necessary — `bdsim`'s notebook animation support now works directly in-kernel, so these examples just use `%run -i` to run the block-diagram script in place, sharing the notebook's own namespace (so parameter variables set above are visible to the script, and its results, e.g. `out`, appear directly here afterward).\n\n</div>"
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"if COLAB:\n",
" %run -m braitenberg -H -g # no graphics\n",
"else:\n",
" run_shell(\"braitenberg\")"
]
"source": "%run -i $models_dir/braitenberg.py"
},
{
"cell_type": "code",
Expand Down
13 changes: 3 additions & 10 deletions notebooks/chap7.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"outputs": [],
"source": "from IPython.display import HTML\n\nimport matplotlib.pyplot as plt\n\n# add RTB examples folder to the path\nimport sys, os.path\nimport RVC3 as rvc\nsys.path.append(os.path.join(rvc.__path__[0], 'models'))\n\n# helper function to run bdsim in a subprocess and transfer results using a pickle file\nimport pickle\ndef run_shell(tool, **params):\n global out\n pyfile = os.path.join(rvc.__path__[0], \"models\", tool+\".py\")\n cmd = f\"python {pyfile} -H +a -o\"\n for key, value in params.items():\n cmd += f' --global \"{key}={value}\"'\n print(cmd)\n os.system(cmd)\n with open(\"bd.out\", \"rb\") as f:\n out = pickle.load(f)\n \n# ------ standard imports ------ #\nimport numpy as np\nfrom scipy import optimize\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\nfrom spatialmath import *\nfrom spatialmath.base import *\nfrom roboticstoolbox import *"
"source": "from IPython.display import HTML\n\nimport matplotlib.pyplot as plt\n\n# add RTB examples folder to the path\nimport sys, os.path\nimport RVC3 as rvc\nmodels_dir = os.path.join(rvc.__path__[0], 'models')\nexamples_dir = os.path.join(rvc.__path__[0], 'examples')\nsys.path.append(models_dir)\n\n# ------ standard imports ------ #\nimport numpy as np\nfrom scipy import optimize\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\nfrom spatialmath import *\nfrom spatialmath.base import *\nfrom roboticstoolbox import *"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -1615,12 +1615,7 @@
"id": "161",
"metadata": {},
"outputs": [],
"source": [
"if COLAB:\n",
" %run -m jointspace -H -g # no graphics\n",
"else:\n",
" run_shell(\"jointspace\")"
]
"source": "%run -i $models_dir/jointspace.py"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -2029,9 +2024,7 @@
"id": "201",
"metadata": {},
"outputs": [],
"source": [
"%run -m walking"
]
"source": "%run -i $examples_dir/walking.py"
},
{
"cell_type": "markdown",
Expand Down
28 changes: 5 additions & 23 deletions notebooks/chap8.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"id": "2",
"metadata": {},
"outputs": [],
"source": "from IPython.display import HTML\n\nimport matplotlib.pyplot as plt\n\n# add RTB examples folder to the path\nimport sys, os.path\nimport RVC3 as rvc\nsys.path.append(os.path.join(rvc.__path__[0], 'models'))\n\n# helper function to run bdsim in a subprocess and transfer results using a pickle file\nimport pickle\ndef run_shell(tool, **params):\n global out\n pyfile = os.path.join(rvc.__path__[0], \"models\", tool+\".py\")\n cmd = f\"python {pyfile} -H +a -o\"\n for key, value in params.items():\n cmd += f' --global \"{key}={value}\"'\n print(cmd)\n os.system(cmd)\n with open(\"bd.out\", \"rb\") as f:\n out = pickle.load(f)\n\n# ------ standard imports ------ #\nimport numpy as np\nfrom scipy import linalg\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\nfrom spatialmath import *\nfrom spatialmath.base import *\nfrom roboticstoolbox import *"
"source": "from IPython.display import HTML\n\nimport matplotlib.pyplot as plt\n\n# add RTB examples folder to the path\nimport sys, os.path\nimport RVC3 as rvc\nmodels_dir = os.path.join(rvc.__path__[0], 'models')\nexamples_dir = os.path.join(rvc.__path__[0], 'examples')\nsys.path.append(models_dir)\n\n# ------ standard imports ------ #\nimport numpy as np\nfrom scipy import linalg\nimport math\nfrom math import pi\nnp.set_printoptions(\n linewidth=120, formatter={\n 'float': lambda x: f\"{0:8.4g}\" if abs(x) < 1e-10 else f\"{x:8.4g}\"})\nnp.random.seed(0)\nfrom spatialmath import *\nfrom spatialmath.base import *\nfrom roboticstoolbox import *"
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -194,23 +194,15 @@
"id": "19",
"metadata": {},
"outputs": [],
"source": [
"if COLAB:\n",
" %run -m RRMC -H -g # no graphics\n",
"else:\n",
" run_shell(\"RRMC\")\n"
]
"source": "%run -i $models_dir/RRMC.py"
},
{
"cell_type": "code",
"execution_count": null,
"id": "20",
"metadata": {},
"outputs": [],
"source": [
"t = out.clock0.t;\n",
"q = out.clock0.x;"
]
"source": "t = out.clock0.t;\nq = out.clock0.X;"
},
{
"cell_type": "code",
Expand All @@ -228,12 +220,7 @@
"id": "22",
"metadata": {},
"outputs": [],
"source": [
"from roboticstoolbox.models.DH import Puma560 # need to explicitly import this because we run RRMC in a subprocess\n",
"puma = Puma560()\n",
"\n",
"Tfk = puma.fkine(q);"
]
"source": "from roboticstoolbox.models.DH import Puma560\npuma = Puma560()\n\nTfk = puma.fkine(q);"
},
{
"cell_type": "code",
Expand All @@ -251,12 +238,7 @@
"id": "24",
"metadata": {},
"outputs": [],
"source": [
"if COLAB:\n",
" %run -m RRMC2 -H -g # no graphics\n",
"else:\n",
" run_shell(\"RRMC2\")\n"
]
"source": "%run -i $models_dir/RRMC2.py"
},
{
"cell_type": "markdown",
Expand Down
Loading