From f9f4f07a16e4afe55b9213c9c8160a3164017bb0 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Mon, 19 Oct 2026 18:13:48 +1000 Subject: [PATCH] docs(notebooks): modernise two-link-dynamics.ipynb, including the sign convention of gravity Co-Authored-By: Claude Sonnet 5.5 --- docs/notebooks/two-link-dynamics.ipynb | 69 ++++++++++++++------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/docs/notebooks/two-link-dynamics.ipynb b/docs/notebooks/two-link-dynamics.ipynb index a5b450c2e..00a15e496 100644 --- a/docs/notebooks/two-link-dynamics.ipynb +++ b/docs/notebooks/two-link-dynamics.ipynb @@ -4,8 +4,29 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Dynamics of 2-link manipulator\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + "
Robotics Toolbox for Python
\n", "\n", + "

\n", + "
Dynamics of a 2-link manipulator
\n", + "

\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", @@ -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", @@ -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." ] }, { @@ -136,7 +157,7 @@ "outputs": [], "source": [ "print(robot)\n", - "print(robot.dyntable())" + "print(robot.dynamics())" ] }, { @@ -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", @@ -280,7 +301,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## ERobot notation" + "## ETS notation" ] }, { @@ -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])" ] }, { @@ -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": { @@ -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,