Robot Dynamics: Lagrange and Newton-Euler
What You'll Learn
- 1Write the manipulator equation and identify the inertia, Coriolis, and gravity terms
- 2Derive joint torques from the Lagrangian for a one-link and a two-link arm
- 3Evaluate gravity compensation torques at a stated configuration
- 4Compare the closed-form Lagrangian route with the recursive Newton-Euler algorithm
Torque is the currency of a robot drive, and dynamics is the exchange rate: it converts a desired acceleration and a pose into the current the drive must produce. A wrong model leaves a bias the controller must fight, wasting bandwidth. This lesson builds the manipulator equation from energy, computes real gravity torques for a two-link arm, and contrasts the Lagrangian route with the recursion a controller runs each cycle.
Theory and Foundations
A rigid-link manipulator obeys one second-order matrix equation whose three groups of terms have distinct physical origins: inertia couples all joints through the motion of the links, velocity-squared terms arise from rotating frames, and gravity depends on pose alone.
The Lagrangian route starts from energy rather than forces. Kinetic energy of a multibody chain is quadratic in joint rates with a configuration-dependent matrix, and potential energy is a sum of center-of-mass heights.
Substituting into the Euler-Lagrange equations produces the whole equation of motion term by term.
Each entry of comes from the second derivatives of the kinetic energy, and positive definiteness of follows directly: any nonzero carries positive kinetic energy, so .
The velocity terms are quadratic in joint rates with coefficients built from derivatives of , which is why nothing in this group survives at rest.
Gravity follows from one differentiation of the potential energy, and it is the term a controller must cancel before any motion is accurate.
The alternative, the recursive Newton-Euler method, propagates quantities link by link instead of differentiating energies: an outward pass computes angular and linear acceleration of each link, and an inward pass back-substitutes forces and torques.
Here selects revolute or prismatic action and is the joint axis direction in link i. The recursion costs order operations, so a six-axis controller evaluates the full inverse dynamics inside one millisecond servo tick, while the Lagrangian form stays the readable one for analysis and identification.
Energy conservation gives a final sanity check on any model: with no losses, applied power equals the rate of change of stored energy.
Key Formulas
Worked Examples
| Dynamic term | Symbol | Depends on | Example magnitude | Controller treatment |
|---|---|---|---|---|
| Inertia matrix | M(q) | configuration | 0.25 to 5 kg m2 | feedforward or adaptive |
| Coriolis and centrifugal | C(q,q dot)q dot | joint rates squared | up to 30 percent of torque | computed feedforward |
| Gravity | g(q) | pose only | 6.4 to 23 N m here | always cancelled first |
| Viscous and Coulomb friction | b q dot + f | velocity sign | 0.8 N m in example 1 | offline identification |
| Reflected load inertia | J load over gear ratio squared | load and gearing | drops by N squared | added to joint inertia |
Real-World Examples
- Industrial servo drives - Drives evaluate inverse dynamics at 1 to 4 kHz and inject torque feedforward, letting a 200 kg arm track fast current demand without lagging the position loop.
- Collaborative arms - Force-limited cobots carry joint torque sensors and use the gravity model to subtract link weight, giving about 1 N resolution on a 100 N safety limit.
- Model identification - Fitting , , and with least squares over a chirp trajectory recovers torques to within 2 to 5 percent of measured values.
- Energy monitoring - Integrating over a duty cycle separates regenerative braking from dissipative losses and verifies the cell power budget.
đĄCancel gravity before raising gains
Gravity Torques as a Function Call
Feeding pose-dependent gravity torques forward every cycle is what separates a controller that holds position from one that fights itself, and the model is short enough to review line by line. Compute the elbow term first because the shoulder expression repeats it, measure angles from the same reference the derivation assumed, and cache the pair across a pose grid at commissioning so the runtime evaluation becomes a table lookup. A shoulder value fifteen times the elbow value at this pose is normal, which means a drive sized on inertia alone will not hold still when the arm stops.
import math
def gravity_torques(th1_deg, th2_deg, m1=4.0, lc1=0.25, L1=0.50,
m2=3.0, lc2=0.20, g=9.81):
th1, th2 = math.radians(th1_deg), math.radians(th2_deg)
elbow = m2 * lc2 * g * math.cos(th1 + th2)
shoulder = (m1 * lc1 + m2 * L1) * g * math.cos(th1) + elbow
return shoulder, elbow
t1, t2 = gravity_torques(30, 45)
print(round(t1, 2), round(t2, 2)) # 22.76 1.52
Verifying the Model With a Power Balance
Any model you derive, from Lagrange or from Newton-Euler, must satisfy one identity at every instant: applied mechanical power equals the rate of change of kinetic and potential energy plus whatever the losses dissipate. Evaluating that identity numerically at a handful of random states turns a symbolic error into a failing assertion, and it catches what dimensional checks miss, such as a sign flipped in the potential energy or a center-of-mass distance silently replaced by a full link length.
import math
m, L = 3.0, 0.50
lc, g, b = L / 2.0, 9.81, 0.40
I = m * L * L / 3.0 # rod pivoted at one end
th, w, a = math.radians(60.0), 2.0, 4.0
tau = I * a + m * g * lc * math.sin(th) + b * w
dK = I * w * a # kinetic energy rate
dP = m * g * lc * math.sin(th) * w # potential energy rate
loss = b * w * w # viscous dissipation
print(round(tau, 2), round(tau * w, 2), round(dK + dP + loss, 2))
# 8.17 16.34 16.34
Common Mistakes
Measuring angles from the wrong reference
Fix: The gravity term above uses angles from horizontal; switch to a vertical reference and the sines and cosines trade places, flipping the sign.
Dropping the velocity-squared terms at low speed only
Fix: Coriolis and centrifugal torques scale with joint rate squared, so they matter at high speed and vanish only at rest; include them in feedforward for fast moves.
Treating the inertia matrix as constant
Fix: M(q) changes by tens of percent on a folded arm, so a fixed equivalent inertia destabilizes a fast controller.
Key Takeaways
- The manipulator equation is M q double dot plus C q dot plus g equals tau, each group derived from the Lagrangian.
- Gravity dominates static demand: 6.37 N m for one 3 kg link at 60 deg and 22.76 N m at the shoulder of the two-link arm.
- M(q) is symmetric positive definite because kinetic energy is positive for any nonzero joint rate.
- Newton-Euler recursion costs order n operations per cycle, while the Lagrangian form is the readable one for analysis.
Frequently Asked Questions
Which method should a controller use at runtime?
Recursive Newton-Euler, because it scales linearly with joint count and needs no symbolic derivatives. The Lagrangian derivation is preferred offline, where its energy structure reveals which terms dominate and which parameters to identify.
Why do Coriolis terms vanish at rest?
They are quadratic in joint rates, so kills the group. Only inertia and gravity remain when holding, which is what a gravity table stores.
How is gravity feedforward different from an integrator?
Feedforward applies the exact model torque at the current pose, so the error never develops, while an integrator must accumulate error first. Correct feedforward leaves only a small integral gain to trim model error.
Interview Questions
Q1: Write the manipulator equation and name each term.
M(q) q double dot plus C(q,q dot) q dot plus g(q) equals tau: configuration-dependent inertia, velocity-squared Coriolis and centrifugal torques, and gravity.
Q2: Why is the inertia matrix symmetric positive definite?
Because kinetic energy equals one half q dot transpose M q dot and is strictly positive for any nonzero joint rate, which forces M to be positive definite and symmetric.