Pendulum physics
One rigid body on one hinge. Everything later in the stack, from the arm's dynamics to the controller's gains and the simulator's sanity checks, rests on a few numbers about this body: its inertia about the pivot, where its centre of mass sits, and how fast gravity makes it swing. This module derives each of them for the running example and checks every one against MuJoCo.
12 formulas · 13/13 checks pass · 17 sources · fact-checked and reviewed
Key ideas
The dynamics see inertia about the pivot, and nothing else
A rigid body has a different moment of inertia about every axis. For a hinge, the one that matters is the axis through the pivot. Build it from parts: each part's inertia about its own centre of mass, plus to carry it to the pivot (F6.02). In the running example the bob's is 97.0 % of the total, the rod's length term 2.58 %, and the sphere's spin about its own centre 0.45 %.[1][2]
Frequency is stiffness over inertia, under a square root
(F6.07). Scale every mass by the same factor and and scale together, so the period is unchanged; what sets it is how the mass is distributed, captured by the equivalent length (F6.08). Here = 165.8 mm, a little shorter than the 168 mm to the bob's centre, because the rod's mass sits higher up.[3]
Bigger swings are slower
The linear model assumes the restoring torque grows in proportion to the angle. In fact grows more slowly, so a large swing takes longer: 0.048 % longer at 5°, 1.74 % at 30° and 18.0 % from horizontal (F6.09). Inertia is computed from the period squared, so a swing timed at 5° and treated as small biases by twice that.[4][5]
Energy is the first thing to check
Without friction or drive, is constant (F6.10). A hand calculation that disagrees with the simulator's own energy tells you something is wrong before any controller exists. Where potential energy is zero is a choice: MuJoCo puts it at the world origin, here the pivot, so its value differs from this one by the constant = 0.3443 J.[6][7]
Radians, and hertz versus radians per second
Every formula here takes angles in radians: the in F6.09 comes out about 3300 times too large if you feed it degrees. Angular frequency and frequency differ by : = 7.691 rad/s is = 1.224 Hz. Mixing them is a factor of 6.28 that can look plausible on a plot.[8][9]
Formulas
The same entries as the formula sheet. Open an entry's details for its symbols and the checks behind it.
Solid cylinder about a transverse axis through its centre
Symbols and checks
Symbol Meaning Unit mass kg radius m length m - ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
Parallel-axis theorem
The two axes must be parallel, and one must pass through the centre of mass.
Symbols and checks
Symbol Meaning Unit inertia about the parallel axis through the centre of mass kg·m² distance between the axes m - ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
Rod hanging from one end, about the pivot
Solid cylinder, pivot on the end face's centre, axis perpendicular to the rod.
Symbols and checks
Symbol Meaning Unit rod mass kg rod length m rod radius m - ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
Solid sphere about a pivot at distance D
Symbols and checks
Symbol Meaning Unit sphere mass kg sphere radius m pivot to sphere centre m - ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
Centre-of-mass distance from the pivot
Symbols and checks
Symbol Meaning Unit part mass kg pivot to part's centre of mass m - ✓ centre-of-mass depth vs MuJoCo xiposexpected 0.159545 · got 0.159545 · relative error 0
Equation of motion, compound pendulum
Rigid body, frictionless pivot, no drive torque.
Symbols and checks
Symbol Meaning Unit inertia about the pivot kg·m² total mass kg gravity m/s² pivot to centre of mass m angle from hanging rad - ✓ T0 vs MuJoCo RK4 period at 0.5 degexpected 0.816927 · got 0.816931 · relative error 4.8×10⁻⁶0.5 deg amplitude adds about 5e-6 to the period
Natural frequency and small-angle period
Small angles (sin θ ≈ θ). At 5° the true period is 0.05 % longer.
Symbols and checks
Symbol Meaning Unit natural angular frequency rad/s small-angle period s - ✓ T0 vs MuJoCo RK4 period at 0.5 degexpected 0.816927 · got 0.816931 · relative error 4.8×10⁻⁶0.5 deg amplitude adds about 5e-6 to the period
- ✓ period excess at 5 deg (fraction)expected 4.75965×10⁻⁴ · got 4.76172×10⁻⁴ · relative error 4.4×10⁻⁴the '0.05 % at 5 deg' claim
Equivalent simple-pendulum length
Symbols and checks
Symbol Meaning Unit length of the simple pendulum with the same period m - ✓ simple pendulum at ell gives T0expected 0.816927 · got 0.816927 · relative error 0
Period at large amplitude
Undamped. The series converges slowly past about 60°; use the elliptic form there.
Symbols and checks
Symbol Meaning Unit release amplitude rad complete elliptic integral of the first kind, at modulus sin(θ₀/2) dimensionless - ✓ elliptic period at 90 deg vs MuJoCo RK4expected 0.964252 · got 0.964252 · relative error 9.2×10⁻¹⁵
- ✓ two-term series at 90 deg vs ellipticexpected 0.964252 · got 0.960716 · relative error 0.0037series truncation error at 90 deg is about 0.4 %
- ✓ period excess at 5 deg (fraction)expected 4.75965×10⁻⁴ · got 4.76172×10⁻⁴ · relative error 4.4×10⁻⁴the '0.05 % at 5 deg' claim
Total mechanical energy
Potential energy is zero at the bottom of the swing; MuJoCo's is zero at the pivot height, so the two differ by the constant m·g·d.
Symbols and checks
Symbol Meaning Unit energy J angular velocity rad/s - ✓ MuJoCo PE + m g d vs hand PE (worst, J)expected 0 · got 7.63278×10⁻¹⁷ · absolute error 7.6×10⁻¹⁷MuJoCo's zero height is the pivot; the constant offset is m g d
- ✓ MuJoCo KE vs 1/2 I thetadot^2 (worst, J)expected 0 · got 5.55112×10⁻¹⁷ · absolute error 5.6×10⁻¹⁷
Peak angular speed from release angle
Undamped, released from rest.
Symbols and checks
Symbol Meaning Unit angular speed at the bottom rad/s - ✓ peak speed from 90 deg vs MuJoCo RK4expected 10.8771 · got 10.8771 · relative error 3.6×10⁻¹¹
Where added mass slows the swing
A point mass added below the pivot, on the vertical through the pivot and the centre of mass. Farther down than ℓ it slows the swing, higher up it speeds it up, and exactly at ℓ (the centre of oscillation) it changes nothing, whatever its size. Above the pivot (s < 0) the rule does not hold.
Symbols and checks
Symbol Meaning Unit added point mass kg depth of the added mass below the pivot (s > 0) m - ✓ 5 g added at s = ell: period change (fraction)expected 0 · got 1.67833×10⁻⁷ · absolute error 1.7×10⁻⁷nonzero only through the 1 mm sphere's own inertia
- ✓ 5 g at s = ell/2 shortens the periodobserved as stated
- ✓ 5 g at s = 1.5 ell lengthens the periodobserved as stated
Worked example: from parts to period
The running example: a 20 g solid rod, 150 mm long and 4 mm in radius, hanging from the hinge, with a 200 g solid sphere of 18 mm radius centred 168 mm below the pivot, under MuJoCo's default gravity of 9.81 m/s². Every number is computed by tools/robotics/verify.py, and the checks it names are listed under each formula.
The rod
A solid cylinder pivoted at the centre of one end face, axis across the rod (F6.03). The length term dominates; the thickness term is tiny but costs nothing to keep.
Add the parts, then ask MuJoCo
The parts add because they share the axis. MuJoCo's mass matrix for the same model (
mj_fullM) agrees to a relative 1.5×10⁻¹⁶, which is round-off.Centre of mass and gravity stiffness
The mass-weighted average of the part centres, rod at 75 mm and bob at 168 mm (F6.05), then . MuJoCo's own centre of mass agrees to the last digit.
Natural frequency and period
From F6.07. MuJoCo, integrating with RK4 from a 0.5° release, gives a period within a relative 4.8×10⁻⁶ of , most of which is the 0.5° itself.
Equivalent length
= 165.8 mm (F6.08). It sits between the rod alone ( = 100 mm) and the bob alone ( = 168.8 mm), weighted towards the bob, which carries most of the mass.
What each simplification costs
Is the full calculation worth it? Remove one detail at a time and recompute the period. Whether an error matters depends on what you will measure later; the damping and inertia work in modules 08 and 09 needs about 0.1 %.
Period error from each simplification (negative means too short) Model Period error Point mass at the bob centre on a massless rod: 0.65 % Sphere only, rod ignored 0.88 % Bob as a point (drop ) −0.22 % Rod as a line (drop ) −7×10⁻⁴ % Large swings
From the complete elliptic integral (F6.09). Released from horizontal, MuJoCo with RK4 matches the elliptic period to a relative 9.2×10⁻¹⁵, and the pendulum passes the bottom at 10.88 rad/s (F6.11).
How much longer the period is than T₀ Release angle Period longer by 5° 0.048 % 15° 0.43 % 30° 1.74 % 60° 7.32 % 90° 18.0 %
Two numbers set the whole motion: the gravity stiffness and the inertia about the pivot. Everything else on this page follows from them, and both can be measured on the bench without trusting the geometry (F9.01, F9.02).
Best practice
Build the inertia from parts, then check it against the simulator's mass matrix.
The two should agree to round-off; here the relative gap is 1.5×10⁻¹⁶. A larger gap means your hand calculation and your model disagree about a mass, a length or an axis, which is far cheaper to find now than after a controller has been tuned on the wrong number.[10]
Give every geom an explicit
mass.Without one, MuJoCo computes the mass from the geom's volume and a default density of 1000 kg/m³, the density of water. Your parts are not made of water.[14]
Keep angles in radians inside the code, and convert only at the edges.
The formulas and the standard library's trigonometric functions all take radians. Convert once, where values enter or leave (logs, plots, user input), and put the unit in the name of any variable that is not SI.[9]
Time the period at small amplitude, or correct for the amplitude.
At 5° the period is 0.048 % long. Above that, apply F6.09 with the amplitude you actually released from.[4]
Say whether a frequency is in rad/s or Hz.
They differ by , and both are called "frequency" in conversation.[8]
Check energy before anything else in a new simulation.
Compute yourself from the state and compare it with the simulator's own figure, allowing for where each puts zero. Then watch how it behaves over time with no friction and no drive: module 07 is about what the integrator does to it.[7][14]
Questions
- Why not just use ?
- That is a point mass on a massless string. Applied to the running example with = 168 mm, it gives a period 0.65 % too long, which would swamp the damping and inertia measurements later. For a real body, use in place of (F6.08).[3]
- Does the mass matter?
- Not its total. Scale every mass by the same factor and the period does not change. Adding mass is another matter, and it depends where. Below the pivot, a mass added farther down than slows the swing, one added higher up speeds it up, and one added exactly at (the centre of oscillation) changes nothing (F6.12). For example, 5 g at changes the period by −0.29 %, and 5 g at by 0.85 %.[13]
- Can I ignore the bob's size and the rod's thickness?
- Depends on the tolerance. Dropping the sphere's own changes the period by −0.22 %; dropping the rod's thickness by −7×10⁻⁴ %. For work at 0.1 %, keep the sphere term; the thickness term you may drop.
- Why is MuJoCo's potential energy negative?
- MuJoCo measures height from the world origin, and here the pendulum hangs below it. Only differences in energy matter physically. MuJoCo's value and F6.10 differ by the constant at every instant, which the check confirms to 8×10⁻¹⁷ J.[7][14]
- Where does the inertia of the hinge itself go?
- Anything that turns with the pendulum adds to : the hub, the screws, and a motor's rotor if one is attached. In MuJoCo, rotor inertia belongs in the joint's
armature, multiplied by the square of the gear ratio (which is 1 for direct drive). Module 09 measures the total rather than adding it up.[12][14] - Is the small-angle period ever exact?
- Only in the limit of zero amplitude. Even at 5° the true period is 0.048 % longer, and at 15° 0.43 %. Whether that matters depends, again, on the tolerance of what you do with it.[4]
Watch
- listed
Differential equations, studying the unsolvable (DE1) (opens in a new tab)[15]
Grant Sanderson · 3Blue1Brown, 31 March 2019
An animated introduction to differential equations built around the pendulum equation. Watch it before the formulas.
- listed
Physical Pendulum: Period Derivation and Demonstration using Calculus (opens in a new tab)[16]
Flipping Physics (video, 14:52)
Derives the period of a physical pendulum with calculus, then tests the prediction on a real one: the same route as F6.06 and F6.07, at a gentler pace.
- listed
Lecture 11: Mass Moment of Inertia of Rigid Bodies (opens in a new tab)[17]
J. Kim Vandiver · MIT OpenCourseWare, 2.003SC Engineering Dynamics, Fall 2011
A full MIT lecture on moment of inertia, including the parallel-axis theorem. Longer and more formal: the reference version of idea 01.
Read
- read
University Physics Volume 1, §10.5 Calculating Moments of Inertia (opens in a new tab)[1]
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax, 2016. CC BY 4.0
The parallel-axis theorem and the rod examples, free and well illustrated.
- read
University Physics Volume 1, §15.4 Pendulums (opens in a new tab)[3]
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax, 2016. CC BY 4.0
Simple and physical pendulums, and the small-angle approximation.
- read
The AGM Simple Pendulum (opens in a new tab)[4]
Mark B. Villarino · arXiv:1202.2782v2 [math.CA], 2014
The exact large-amplitude period through the arithmetic-geometric mean, a fast way to evaluate F6.09 without special functions.
- listed
Modern Robotics — Mechanics, Planning, and Control (opens in a new tab)[12]
Kevin M. Lynch, Frank C. Park · Cambridge University Press, 2017. Free preprint for personal use at the book site.
Chapter 8 extends this single hinge to a chain of links. The mass matrix there is this page's , grown up.
Sources
Numbered in order of first use on this page. read: checked against the claim. listed: exists and covers the topic, wording not checked. derived: worked out here and checked numerically.
- [1]read
University Physics Volume 1, §10.5 Calculating Moments of Inertia (opens in a new tab)
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax, 2016. CC BY 4.0
Eq. 10.20 (parallel-axis theorem); Figs. 10.25 and 10.26 (thin rod about centre, about end)
Parallel-axis theorem; thin rod about its centre (mL²/12) and end (mL²/3).
- [2]read
List of moments of inertia (opens in a new tab)
Wikipedia
Solid sphere 2/5 mr²; solid cylinder about a transverse central axis m(3r²+h²)/12. Secondary source, cross-checked against MuJoCo's own inertia code and numerically.
- [3]read
University Physics Volume 1, §15.4 Pendulums (opens in a new tab)
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax, 2016. CC BY 4.0
Eq. 15.21 (physical pendulum, T = 2π√(I/mgL)); small-angle note (under 15°, sin θ and θ differ by under 1 %)
Physical (compound) pendulum period and the small-angle assumption.
- [4]read
The AGM Simple Pendulum (opens in a new tab)
Mark B. Villarino · arXiv:1202.2782v2 [math.CA], 2014
exact period T = 4√(l/g)·K(k), k = sin(α/2); series 1 + α²/16 + 11α⁴/3072 + 173α⁶/737280 + …
Large-amplitude period, exact and as a series. Applies to the compound pendulum with l replaced by the equivalent length ℓ = I/(md).
- [5]read
scipy.special.ellipk (opens in a new tab)
SciPy documentation (1.9.1)
SciPy's K takes the parameter m = k², not the modulus k. A common source of wrong large-amplitude periods.
- [6]read
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax (Rice University), 2016. CC BY 4.0
Eq. 10.18 (K = ½Iω²); Fig. 10.20 (table of common shapes, an image)
Rotational kinetic energy. The shape table is an image, so the sphere and cylinder values are also cited from other sources on this page.
- [7]read
mj_energyPos, src/engine/engine_sensor.c (MuJoCo 3.17.0) (opens in a new tab)
Google DeepMind, GitHub
Potential energy = −Σ m_b g·x_b (body centres of mass), so zero height is the world origin.
- [8]read
University Physics Volume 1, §15.1 Simple Harmonic Motion (opens in a new tab)
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax, 2016. CC BY 4.0
Eq. 15.1 (f = 1/T); angular frequency ω = 2π/T = 2πf (unnumbered)
Frequency in hertz versus angular frequency in inverse seconds (radians per second), and the factor 2π between them.
- [9]read
std::sin, std::sinf, std::sinl (opens in a new tab)
cppreference.com (2024-06-10), as packaged in the stdman manual pages
The C++ standard library's sine takes its argument in radians.
- [10]read
mjCGeom::SetInertia, src/user/user_objects.cc (MuJoCo 3.17.0) (opens in a new tab)
Google DeepMind, GitHub
MuJoCo computes a solid sphere as 2mr²/5 and a solid cylinder as m(3r²+h²)/12 with h the full length (size[1] is the half-length).
- [11]read
University Physics Volume 1, §9.6 Center of Mass (opens in a new tab)
William Moebs, Samuel J. Ling, Jeff Sanny · OpenStax, 2016. CC BY 4.0
Eq. 9.29 (r_CM = Σ m_j r_j / M)
Centre of mass of a system of parts.
- [12]listed
Modern Robotics — Mechanics, Planning, and Control (opens in a new tab)
Kevin M. Lynch, Frank C. Park · Cambridge University Press, 2017. Free preprint for personal use at the book site.
§8.1.2 General Formulation (p. 275), §8.1.3 Understanding the Mass Matrix (p. 277), §8.9.2 Apparent Inertia (p. 311), §8.9.4 Friction (p. 315)
Manipulator dynamics M(θ)θ̈ + c(θ,θ̇) + g(θ) = τ, kinetic energy ½θ̇ᵀMθ̇, apparent (reflected) inertia through gearing, friction models. Section titles and pages confirmed from the preprint's table of contents.
- [13]derived
Effect of a small added mass on the equivalent length (centre of oscillation)
F6.12, checked by letting MuJoCo compose the inertia and centre of mass with the added part.
- [14]read
MuJoCo XML Reference (3.17.0) (opens in a new tab)
Google DeepMind
option-timestep (default 0.002 s; RK4 costs about four times per step); option-gravity (default 0 0 −9.81); option-integrator; option-flag-energy; option-flag-eulerdamp (implicit joint damping in Euler, on by default); body-joint-armature (reflected inertia, gear ratio squared; positive armature improves stability); actuator-general-armature (rotor inertia, scaled by gear squared); body-joint-damping (Euler treats joint damping implicitly); body-joint-frictionloss; compiler-inertiafromgeom; body-geom-density (default 1000 kg/m³, used only when mass is not given)
MuJoCo defaults, energy definitions, armature, damping and friction-loss behaviour. Read from the 3.17.0 source of the docs (doc/XMLreference.rst).
- [15]listed
Differential equations, studying the unsolvable (DE1) (opens in a new tab)
Grant Sanderson · 3Blue1Brown, 31 March 2019
An animated introduction to differential equations built around the pendulum equation.
- [16]listed
Physical Pendulum: Period Derivation and Demonstration using Calculus (opens in a new tab)
Flipping Physics (video, 14:52)
Derives the angular frequency and period of a physical pendulum, then checks the prediction with a demonstration.
- [17]listed
Lecture 11: Mass Moment of Inertia of Rigid Bodies (opens in a new tab)
J. Kim Vandiver · MIT OpenCourseWare, 2.003SC Engineering Dynamics, Fall 2011
Lecture video covering the inertia matrix, principal axes, a disk example and the parallel-axis theorem (topics confirmed from the course page).