Dynamics essentials
A robot arm holds a 2 kg weight straight out. Nobody is moving it, yet the shoulder motor is working hard and getting warm. Now the arm swings fast and the elbow motor suddenly struggles even though the weight has not changed. Kinematics cannot explain either fact. Dynamics can: it connects the torques your motors produce to the motion you get, and it tells you which motor to buy.
You will be able to
- Explain what rigid-body dynamics adds to kinematics and state Newton-Euler and Lagrange approaches in words.
- Read the manipulator equation term by term.
- Compute the mass matrix, Coriolis and gravity terms for a 2-link arm in NumPy.
- Use forward and inverse dynamics, and check a motion against joint torque limits.
Why dynamics?
Dynamicsthe study of how forces and torques cause motion, taking mass and inertia into account answers two practical questions.
- Inverse dynamics: given the motion I want (positions, velocities, accelerations), which joint torques do I need? Used for control, for sizing motors, and for checking a plan is feasible.
- Forward dynamics: given the torques I apply, how will the robot move? Used by every physics simulator, including the ones in the simulation module.
Both come from one equation. Before we meet it, build the intuition for the forces that appear.
Newton-Euler intuition
Newton's law for a body is . Its rotating twin, Euler's law, is (torque equals rotational inertia times angular acceleration). The moment of inertiathe rotational analogue of mass: how hard it is to change an object’s spinning speed about a given axis depends on both the mass and how far from the axis it sits. A long arm is much harder to spin than the same mass held close to the shoulder.
The Newton-Euler method applies these two laws link by link. A forward pass starts at the base and works outward, computing each link's velocity and acceleration. A backward pass starts at the hand and works inward, computing the force and torque each joint must supply to produce that motion and carry the links beyond it. It is efficient, running in time proportional to the number of joints, and it is what most real-time dynamics libraries use.
The Lagrange method reaches the same equations from energy. Write down the kinetic energy and potential energy , form , and apply a derivative recipe. It gives neat symbolic equations for small arms, which is why we use it by hand here.
The manipulator equation
For any serial arm the result has the same shape:
Each term has a meaning you can feel.
- : inertia. is the mass matrixa symmetric, positive-definite matrix describing the arm’s effective inertia as seen at each joint, which depends on the arm’s posture. It changes with posture: an extended arm has more inertia about the shoulder than a folded one.
- : velocity-dependent forces. Centrifugal forces (a spinning link wants to fly outward) and Coriolis forces (swinging one joint pushes on another). They grow with the square of speed.
- : gravity. The torque needed just to hold the arm still. It depends on posture but not on speed.
- : the joint torques your motors supply. (Real arms also have joint friction, which we leave out for clarity.)
A 2-link arm, with numbers
Take a planar arm moving in a vertical plane, with link masses , , lengths , , centres of mass at distances , from each joint, and inertias , about those centres. Joint angles are measured from the horizontal. Using the Lagrange method, the pieces are
with
and, defining ,
Three observations. is symmetric. Its off-diagonal term couples the joints: accelerating joint 2 needs torque at joint 1. And is largest when the arm is horizontal () and zero when it points straight up or down.
import numpy as np
m1, m2 = 2.0, 1.5 # link masses (kg)
l1, l2 = 0.4, 0.3 # link lengths (m)
lc1, lc2 = l1 / 2, l2 / 2 # centre of mass at the middle of each rod
I1 = m1 * l1**2 / 12 # thin-rod inertia about the centre
I2 = m2 * l2**2 / 12
G = 9.81
def mass_matrix(q):
c2 = np.cos(q[1])
m11 = m1 * lc1**2 + m2 * (l1**2 + lc2**2 + 2 * l1 * lc2 * c2) + I1 + I2
m12 = m2 * (lc2**2 + l1 * lc2 * c2) + I2
m22 = m2 * lc2**2 + I2
return np.array([[m11, m12], [m12, m22]])
def coriolis(q, qd):
h = -m2 * l1 * lc2 * np.sin(q[1])
return np.array([[h * qd[1], h * (qd[0] + qd[1])],
[-h * qd[0], 0.0]])
def gravity(q):
g1 = (m1 * lc1 + m2 * l1) * G * np.cos(q[0]) + m2 * lc2 * G * np.cos(q[0] + q[1])
g2 = m2 * lc2 * G * np.cos(q[0] + q[1])
return np.array([g1, g2])
def inverse_dynamics(q, qd, qdd):
"""Torques needed to produce acceleration qdd at state (q, qd)."""
return mass_matrix(q) @ qdd + coriolis(q, qd) @ qd + gravity(q)
def forward_dynamics(q, qd, tau):
"""Acceleration produced by torques tau at state (q, qd)."""
return np.linalg.solve(mass_matrix(q), tau - coriolis(q, qd) @ qd - gravity(q))
if __name__ == "__main__":
q = np.array([0.5, 0.8])
qd = np.array([1.0, -0.5])
qdd = np.array([2.0, 1.0])
tau = inverse_dynamics(q, qd, qdd)
print("torques needed:", np.round(tau, 3), "N·m")
print("forward dynamics recovers qdd:", np.allclose(forward_dynamics(q, qd, tau), qdd))
print("holding torque, arm horizontal:", np.round(gravity(np.array([0.0, 0.0])), 3), "N·m")
print("mass matrix eigenvalues (all > 0):", np.round(np.linalg.eigvalsh(mass_matrix(q)), 4))
The round trip, inverse then forward dynamics, returning the same acceleration is a useful self-test for any dynamics code you write or import.
Gravity compensation and computed torque
Because you now have and , you can cancel the arm's own dynamics. Suppose a simple controller asks for a desired acceleration (computed from position error, as in the next lesson). The computed-torque command is
Plugging it into the manipulator equation gives : the nonlinear arm now behaves like a pile of simple, independent joints that obey whatever you ask for. This is called feedback linearisation. It depends on a good model: wrong masses mean imperfect cancellation, which is one reason real controllers keep feedback on top.
Forces at the hand
Often you care about a force on the hand: pressing a sponge on a table, pushing a door. The Jacobian from the last lesson converts a hand force into the joint torques that produce it:
This is the same Jacobian, transposed. It also explains a useful fact about singularities: in the direction the arm cannot move, a hand force needs almost no joint torque, because the stiff straight links carry the load. A stretched arm can brace hard, but it cannot move or sense gently in that direction. The relationship is also the basis of the impedance control you will meet at the end of this module.
Torque limits and what they mean
Every motor and gearbox has a peak torque (short bursts) and a continuous torque (what it can supply indefinitely without overheating). Dynamics lets you check a motion against them before you run it.
- If the holding torque alone exceeds the continuous rating, the joint will overheat even when "standing still".
- Fast motions raise and . Doubling the speed of a swing roughly quadruples the Coriolis torque.
- A payload adds to the mass of the last link. Many arms specify torque-limited payload versus reach curves: carrying more at a longer reach demands more shoulder torque.
A planner that ignores torque limits can produce a path that is geometrically perfect and physically impossible. Time-optimal trajectory methods, such as time-optimal path parameterisation, bake these limits into the speed profile for exactly this reason.
Never run a new, fast motion on a real arm without first checking it against the torque and speed limits, either in simulation or with a slow trial. A joint that saturates in the middle of a fast move can make the arm deviate from the planned path suddenly.
Hands-on lab
You will size the motors for a motion.
- Save
dynamics.pyand run it. Confirm the round trip printsTrue. - Write a function
tau_for_trajectorythat takes joint paths sampled at 100 Hz for 2 seconds, going from to with a smooth cubic profile where . Compute and analytically or withnp.gradient. - For each sample, call
inverse_dynamics, and print the peak absolute torque on each joint. - Add a 1 kg payload by increasing
m2by 1.0 and re-running. How much did the peak shoulder torque rise? - Pretend the shoulder motor's peak rating is 20 N·m. Does your motion respect it? If not, lengthen the motion time and re-check.
You know it worked when the shoulder peak torque rises noticeably with the payload and drops when you slow the motion down.
Exercises
Holding torqueBeginner
A uniform rod of mass 2 kg and length 0.5 m is held horizontally by a motor at one end. What static torque is needed? The weight acts at the centre, 0.25 m from the joint, so N·m. If the rod points straight up, the torque falls to zero (ignoring friction), because the weight line passes through the joint.Show solutionHide solution
Which term dominates?Intermediate
Using Compute dynamics.py, evaluate the three torque contributions separately at for , , then again with . Describe how the shares change.Show solutionHide solution
mass_matrix(q) @ qdd, coriolis(q, qd) @ qd and gravity(q) separately. At slow speed gravity dominates and the Coriolis term is tiny. At the faster speed the velocities are 15 to 20 times larger, and because the Coriolis term grows with velocity squared it becomes a couple of hundred times larger, while gravity stays unchanged. The lesson: gravity matters at rest and slow speed, velocity terms matter during fast motion.
Why is M symmetric and positive definite?Advanced
Give a physical reason that every eigenvalue of must be positive. The kinetic energy of the arm is . Any real motion of a body with mass has strictly positive kinetic energy, so for every nonzero . That is the definition of positive definite. It also guarantees is invertible, which is why forward dynamics can always solve for .Show solutionHide solution
Check your understanding
Takeaways
- Dynamics links joint torques to motion; kinematics alone cannot say what a motor must supply.
- The manipulator equation has inertia, velocity-dependent, and gravity terms plus the applied torque.
- Inverse dynamics gives torques for a desired motion; forward dynamics gives motion from torques and powers simulators.
- Gravity is usually the largest torque for slow motions; velocity terms grow with speed squared.
- The mass matrix is symmetric and positive definite, and depends on posture.
- Check planned motions against continuous and peak torque limits before running them on hardware.
Stuck? Ask Rivet, the course assistant, bottom-right.
Go deeper
- Modern Robotics, chapter 8 (dynamics of open chains): Lagrange and Newton-Euler in depth.
- Pinocchio documentation: rigid-body algorithms (RNEA, CRBA) that compute these terms for any robot.
- Featherstone, Rigid Body Dynamics Algorithms: the standard reference for efficient dynamics.
Next: Control and PID
Finished the lab and the quiz?
Mark it done to track your progress through the course.