Skip to content
Merged
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
69 changes: 38 additions & 31 deletions docs/notebooks/two-link-dynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Dynamics of 2-link manipulator\n",
"<!-- RTB_HEADER -- generated from the notebook metadata (rtb_header) by sync_bootstrap.py, do not hand-edit -->\n",
"<table>\n",
" <tr>\n",
" <td><div align=\"left\"><font size=\"30\">Robotics Toolbox for Python</font></div></td>\n",
" <td><img src=\"figs/RobToolBox_RoundLogoB.png\" width=\"300\"></td>\n",
" </tr>\n",
"</table>\n",
"\n",
"<p></p>\n",
"<div align=\"center\" style=\"font-size: 1.5em;\">Dynamics of a 2-link manipulator</div>\n",
"<p></p>\n",
"\n",
"(c) Peter Corke 2026\n",
"\n",
"The gravity and velocity torques of the two-link planar arm in Spong, Hutchinson and Vidyasagar, computed by the Toolbox from a DH model and from an ETS model, and compared with the analytic Euler-Lagrange equations.\n",
"\n",
"> **Modernised 2026-10-19** to address API drift: this notebook was written for an earlier release of the Toolbox, and has been updated so that it runs with the current one."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Spong book](figs/spong-2link.png)\n",
"\n",
"Reference:\n",
Expand Down Expand Up @@ -75,7 +96,7 @@
"metadata": {},
"outputs": [],
"source": [
"from roboticstoolbox import DHRobot, RevoluteDH, ERobot, ELink, ETS\n",
"from roboticstoolbox import DHRobot, RevoluteDH, Robot, Link, ET\n",
"from math import pi, sin, cos\n",
"import numpy as np\n",
"\n",
Expand Down Expand Up @@ -119,14 +140,14 @@
"source": [
"L1 = RevoluteDH(a=l1, m=m1, r=[-lc1, 0, 0])\n",
"L2 = RevoluteDH(a=l2, m=m2, r=[-lc2, 0, 0])\n",
"robot = DHRobot([L1, L2], gravity=[0, g, 0])"
"robot = DHRobot([L1, L2], gravity=[0, -g, 0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The DH notation only allows rotation about the z-axis, which is out of the page in the Figure above. Gravity acts downward so we set the gravity acceleration to be `[0, g, 0]` - accelerating upward at `g` provides the weight force experienced on Earth."
"The DH notation only allows rotation about the z-axis, which is out of the page in the Figure above. The `gravity` argument is the acceleration due to gravity, a vector in the world frame. Gravity acts downward, in the $-y$ direction of the figure, so we set it to `[0, -g, 0]` (the default is `[0, 0, -9.81]`). The gravity load is the torque the joints must exert to hold the arm still against gravity, so it is positive for an arm stretched out horizontally."
]
},
{
Expand All @@ -136,7 +157,7 @@
"outputs": [],
"source": [
"print(robot)\n",
"print(robot.dyntable())"
"print(robot.dynamics())"
]
},
{
Expand Down Expand Up @@ -268,7 +289,7 @@
"\n",
"L1 = RevoluteDH(a=l1, m=m1, r=[-lc1, 0, 0])\n",
"L2 = RevoluteDH(a=l2, m=m2, r=[-lc2, 0, 0])\n",
"robot = DHRobot([L1, L2], gravity=[0, g, 0], symbolic=True)\n",
"robot = DHRobot([L1, L2], gravity=[0, -g, 0], symbolic=True)\n",
"\n",
"\n",
"q = symbol(\"q_:2\")\n",
Expand All @@ -280,7 +301,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## ERobot notation"
"## ETS notation"
]
},
{
Expand Down Expand Up @@ -324,9 +345,9 @@
"metadata": {},
"outputs": [],
"source": [
"L1 = ELink(ets=ETS.rz(), m=1, r=[0.5, 0, 0], name=\"L1\")\n",
"L2 = ELink(ets=ETS.tx(1) * ETS.rz(), m=1, r=[0.5, 0, 0], parent=L1, name=\"L2\")\n",
"robot = ERobot([L1, L2], gravity=[0, g, 0])"
"L1 = Link(ets=ET.Rz(), m=1, r=[0.5, 0, 0], name=\"L1\")\n",
"L2 = Link(ets=ET.tx(1) * ET.Rz(), m=1, r=[0.5, 0, 0], parent=L1, name=\"L2\")\n",
"robot = Robot([L1, L2], gravity=[0, -g, 0])"
]
},
{
Expand All @@ -340,27 +361,6 @@
" tau_el = EL_grav(q)\n",
" print(tau_rne, \"vs\", tau_el)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down Expand Up @@ -409,6 +409,13 @@
"_Feature"
],
"window_display": false
},
"rtb_header": {
"title": "Dynamics of a 2-link manipulator",
"paragraphs": [
"The gravity and velocity torques of the two-link planar arm in Spong, Hutchinson and Vidyasagar, computed by the Toolbox from a DH model and from an ETS model, and compared with the analytic Euler-Lagrange equations."
],
"modernised": "2026-10-19"
}
},
"nbformat": 4,
Expand Down
Loading