RobotForge
Published·~15 min

Lagrangian dynamics of a serial arm

From kinetic + potential energy to the equation of motion. M(q)q̈ + C(q,q̇)q̇ + g(q) = τ — the canonical form behind every torque-control loop and feedback-linearization scheme.

by RobotForge
#kinematics#dynamics#lagrangian

Forward kinematics gives geometry. The Jacobian gives velocity. To control the arm with torques, you need dynamics — how the joints accelerate when you apply torques and what the arm's mass distribution does to that motion. Lagrangian mechanics is the cleanest derivation. The output is the equation every arm controller in the world is built on.

The recipe

Lagrangian dynamics is mechanical: define energies, take derivatives, get equations of motion. The Lagrangian is

where is total kinetic energy and is total potential energy. The Euler-Lagrange equations are:

One equation per joint. Crank through them and the result is the standard manipulator equation:

Three terms:

  • — the mass matrix (n×n, symmetric, positive-definite). How much force is needed to accelerate each joint, given the current configuration.
  • Coriolis and centrifugal forces. Quadratic in joint velocity; arises from cross-coupling between joints.
  • gravity torques. The torque each joint must exert just to hold the arm against gravity at configuration q.

That's the canonical form. Plug in a controller, simulate, control. Every arm software stack is built on it.

What each term does intuitively

The mass matrix

changes with configuration. A 2-link arm folded has tiny effective inertia at the shoulder; fully extended it has 4× more (the second link's mass acts on a long lever). This is why a fixed-gain PID retuned after extending an arm doesn't behave the same.

is always positive-definite — for any non-zero , kinetic energy is positive.

Coriolis and centrifugal

If joint 1 spins, joint 2 feels a centrifugal force pulling it outward. If both spin together, they each feel Coriolis forces from the other. captures all that. Quadratic in — proportional to the speeds, not the positions.

For slow arms, is small enough to often ignore. For fast arms or close to high-speed maneuvers, it matters significantly.

Gravity

is the constant tax. Without joint torques compensating gravity, the arm falls. Gravity compensation is the simplest controller: alone makes the arm float in place under gravity.

Worked example: 2-link planar arm

Two revolute joints; link masses concentrated at link tips; link lengths .

Mass matrix:

Coriolis matrix:

Gravity:

Three matrices. Plug in to and you have a complete model. Forward simulation: solve for , integrate. Inverse dynamics: given desired , compute .

What you do with it

Inverse dynamics control

Given a desired motion , command the torques:

The arm follows the desired acceleration exactly. Pair with a PD on tracking error:

This is feedback linearization in disguise. The "linearizing" inner loop cancels M, C, g; the outer PD operates on what's now a linear system. Covered in the Feedback Linearization lesson.

Gravity-only control

The simplest non-trivial controller:

PD plus gravity comp. The arm holds position against gravity; PD handles tracking. Robust, easy to tune, used on most cobots.

Forward dynamics for simulation

Solve the equation for :

Integrate forward in time, then forward. Welcome to physics simulation. MuJoCo, PyBullet, Drake all do this internally — you just supply the URDF + masses + torques.

The Newton-Euler alternative

Lagrangian gives clean derivation. Numerical robotics code rarely uses the analytical Lagrangian; instead they use recursive Newton-Euler — a forward+backward pass through the chain that computes torques in O(n) instead of O(n³). Pinocchio, KDL, RBDL all use Newton-Euler under the hood.

Pseudocode:

# Forward pass: propagate kinematic quantities outward
for i in 1..n:
    velocity[i] = velocity[i-1] + joint_velocity[i] * axis[i]
    acceleration[i] = ...

# Backward pass: propagate forces inward
for i in n..1:
    force[i] = mass[i] * acceleration[i] + gravity_term + force[i+1]
    torque[i] = ... project force onto axis[i]

Same physics, different organization. Faster.

The matrices in 2026 toolkits

  • Pinocchio: state-of-the-art; symbolic + numerical. Used by Stack-of-Tasks, Crocoddyl. Recommended.
  • KDL / Orocos: long-standing C++ library. ROS-default for inverse kinematics.
  • Drake: dynamics + planning + optimization in one library. MIT-developed.
  • RBDL: Rigid Body Dynamics Library. Lightweight, well-documented.
  • MuJoCo: dynamics + sim. Use this when you want both.

What the math doesn't capture

  • Friction: not in the Lagrangian. Add it as term.
  • Joint flexibility: real harmonic-drive arms aren't perfectly rigid. Need extended models for high-bandwidth control.
  • Cable / belt drives: introduce hysteresis and backlash. Modeled empirically.
  • Contact: the dynamics above describe free motion. Contact adds constraint forces — handled by Lagrangian multipliers (covered separately).

Exercise

For the 2-link arm above, implement forward simulation in Python: integrate the Lagrangian equations with a torque input. First with — watch the arm fall under gravity. Then with (gravity comp) — arm holds anywhere it starts. Then add a PD outer loop and command it to a target. Three controllers, ten lines each, complete dynamics intuition.

Next

Mobile robot kinematics — the same machinery applied to wheels: differential, Ackermann, omnidirectional, all in one lesson.

Comments

    Sign in to post a comment.