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

  1. 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 ms2m s^2 to carry it to the pivot (F6.02). In the running example the bob's mbD2m_b D^2 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]

  2. Gravity is a torsional spring of stiffness mgd

    Gravity pulls on the centre of mass, a distance dd below the pivot, so the restoring torque is mgdsin⁡θmgd\sin\theta (F6.06). For small angles sin⁡θ≈θ\sin\theta \approx \theta, and the pendulum behaves like an inertia on a spring of stiffness k=mgdk = mgd, in N·m/rad. Here kk = 0.3443 N·m/rad.[3]

  3. Frequency is stiffness over inertia, under a square root

    ωn=k/I\omega_n = \sqrt{k/I} (F6.07). Scale every mass by the same factor and kk and II scale together, so the period is unchanged; what sets it is how the mass is distributed, captured by the equivalent length ℓ=I/(md)\ell = I/(md) (F6.08). Here ℓ\ell = 165.8 mm, a little shorter than the 168 mm to the bob's centre, because the rod's mass sits higher up.[3]

  4. Bigger swings are slower

    The linear model assumes the restoring torque grows in proportion to the angle. In fact sin⁡θ\sin\theta 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 II by twice that.[4][5]

  5. Energy is the first thing to check

    Without friction or drive, E=12Iθ˙2+mgd(1−cos⁡θ)E = \tfrac12 I\dot\theta^2 + mgd(1-\cos\theta) 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 mgdmgd = 0.3443 J.[6][7]

  6. Radians, and hertz versus radians per second

    Every formula here takes angles in radians: the θ02/16\theta_0^2/16 in F6.09 comes out about 3300 times too large if you feed it degrees. Angular frequency ω\omega and frequency ff differ by 2π2\pi: ωn\omega_n = 7.691 rad/s is fnf_n = 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.

  1. Solid cylinder about a transverse axis through its centre

    Ic=112 m (3r2+L2)I_c = \tfrac{1}{12}\, m\,(3r^2 + L^2)
    F6.01✓ 1/1 checked[2][10]
    Symbols and checks
    SymbolMeaningUnit
    mmmasskg
    rrradiusm
    LLlengthm
    • ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
  2. Parallel-axis theorem

    The two axes must be parallel, and one must pass through the centre of mass.

    I=Icm+m s2I = I_{\text{cm}} + m\,s^2
    F6.02✓ 1/1 checked[1]
    Symbols and checks
    SymbolMeaningUnit
    IcmI_{\text{cm}}inertia about the parallel axis through the centre of masskg·m²
    ssdistance between the axesm
    • ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
  3. Rod hanging from one end, about the pivot

    Solid cylinder, pivot on the end face's centre, axis perpendicular to the rod.

    Irod=mr(L23+r24)I_{\text{rod}} = m_r\Big(\dfrac{L^2}{3} + \dfrac{r^2}{4}\Big)
    F6.03✓ 1/1 checked[1][2]
    Symbols and checks
    SymbolMeaningUnit
    mrm_{r}rod masskg
    LLrod lengthm
    rrrod radiusm
    • ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
  4. Solid sphere about a pivot at distance D

    Ibob=25 mbR2+mbD2I_{\text{bob}} = \tfrac25\, m_b R^2 + m_b D^2
    F6.04✓ 1/1 checked[1][2][10]
    Symbols and checks
    SymbolMeaningUnit
    mbm_{b}sphere masskg
    RRsphere radiusm
    DDpivot to sphere centrem
    • ✓ I about pivot: hand formulas vs MuJoCo mass matrixexpected 0.0058208 · got 0.0058208 · relative error 1.5×10⁻¹⁶
  5. Centre-of-mass distance from the pivot

    d=∑imisi∑imid = \dfrac{\sum_i m_i s_i}{\sum_i m_i}
    F6.05✓ 1/1 checked[11]
    Symbols and checks
    SymbolMeaningUnit
    mim_{i}part masskg
    sis_{i}pivot to part's centre of massm
    • ✓ centre-of-mass depth vs MuJoCo xiposexpected 0.159545 · got 0.159545 · relative error 0
  6. Equation of motion, compound pendulum

    Rigid body, frictionless pivot, no drive torque.

    I θ¨+mgdsin⁡θ=0I\,\ddot\theta + m g d \sin\theta = 0
    F6.06✓ 1/1 checked[3][12]
    Symbols and checks
    SymbolMeaningUnit
    IIinertia about the pivotkg·m²
    mmtotal masskg
    gggravitym/s²
    ddpivot to centre of massm
    θθangle from hangingrad
    • ✓ 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
  7. Natural frequency and small-angle period

    Small angles (sin θ ≈ θ). At 5° the true period is 0.05 % longer.

    ωn=mgdI,T0=2πImgd\omega_n = \sqrt{\dfrac{m g d}{I}},\qquad T_0 = 2\pi\sqrt{\dfrac{I}{m g d}}
    F6.07✓ 2/2 checked[3]
    Symbols and checks
    SymbolMeaningUnit
    ωnω_{n}natural angular frequencyrad/s
    T0T_{0}small-angle periods
    • ✓ 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
  8. Equivalent simple-pendulum length

    ℓ=Imd\ell = \dfrac{I}{m d}
    F6.08✓ 1/1 checked[3]
    Symbols and checks
    SymbolMeaningUnit
    ℓℓlength of the simple pendulum with the same periodm
    • ✓ simple pendulum at ell gives T0expected 0.816927 · got 0.816927 · relative error 0
  9. Period at large amplitude

    Undamped. The series converges slowly past about 60°; use the elliptic form there.

    T=2π T0 K ⁣(sin⁡θ02)≈T0(1+θ0216+11 θ043072+⋯)T = \dfrac{2}{\pi}\,T_0\,K\!\big(\sin\tfrac{\theta_0}{2}\big) \approx T_0\Big(1 + \dfrac{\theta_0^2}{16} + \dfrac{11\,\theta_0^4}{3072} + \cdots\Big)
    F6.09✓ 3/3 checked[4][5]
    Symbols and checks
    SymbolMeaningUnit
    θ0θ_{0}release amplituderad
    KKcomplete 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
  10. 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.

    E=12Iθ˙2+mgd (1−cos⁡θ)E = \tfrac12 I\dot\theta^2 + m g d\,(1-\cos\theta)
    F6.10✓ 2/2 checked[3][6][7]
    Symbols and checks
    SymbolMeaningUnit
    EEenergyJ
    θ˙θ̇angular velocityrad/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⁻¹⁷
  11. Peak angular speed from release angle

    Undamped, released from rest.

    θ˙max⁡=2mgd (1−cos⁡θ0)I\dot\theta_{\max} = \sqrt{\dfrac{2 m g d\,(1-\cos\theta_0)}{I}}
    F6.11✓ 1/1 checked[3]
    Symbols and checks
    SymbolMeaningUnit
    θ˙maxθ̇_{\text{max}}angular speed at the bottomrad/s
    • ✓ peak speed from 90 deg vs MuJoCo RK4expected 10.8771 · got 10.8771 · relative error 3.6×10⁻¹¹
  12. 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.

    ℓ′=I+δm s2md+δm s,ℓ′>ℓ  ⟺  s>ℓ\ell' = \dfrac{I + \delta m\, s^2}{m d + \delta m\, s},\qquad \ell' > \ell \iff s > \ell
    F6.12✓ 3/3 checked[3][13]
    Symbols and checks
    SymbolMeaningUnit
    δmδmadded point masskg
    ssdepth 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.

  1. 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.

    Irod=mr(L23+r24)=1.500×10−4+8.0×10−8=1.5008×10−4 kg m2I_{\text{rod}} = m_r\Big(\dfrac{L^2}{3} + \dfrac{r^2}{4}\Big) = 1.500\times 10^{-4} + 8.0\times 10^{-8} = 1.5008\times 10^{-4}\ \text{kg m}^2
  2. The bob

    A solid sphere about its own centre, 25mbR2\tfrac25 m_b R^2, carried to the pivot with the parallel-axis theorem (F6.04, F6.02).

    Ibob=25 mbR2+mbD2=2.592×10−5+0.0056448=0.0056707 kg m2I_{\text{bob}} = \tfrac25\, m_b R^2 + m_b D^2 = 2.592\times 10^{-5} + 0.0056448 = 0.0056707\ \text{kg m}^2
  3. 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.

    I=Irod+Ibob=0.0058208 kg m2I = I_{\text{rod}} + I_{\text{bob}} = 0.0058208\ \text{kg m}^2
  4. 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 k=mgdk = mgd. MuJoCo's own centre of mass agrees to the last digit.

    d=mrL/2+mbDmr+mb=0.03510.220=0.15955 m,k=mgd=0.34433 N m/radd = \dfrac{m_r L/2 + m_b D}{m_r + m_b} = \dfrac{ 0.0351 }{ 0.220 } = 0.15955\ \text{m},\qquad k = m g d = 0.34433\ \text{N m/rad}
  5. 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 T0T_0, most of which is the 0.5° itself.

    ωn=k/I=7.6912 rad/s,T0=2πωn=0.81693 s,fn=1.224 Hz\omega_n = \sqrt{k/I} = 7.6912\ \text{rad/s},\qquad T_0 = \dfrac{2\pi}{\omega_n} = 0.81693\ \text{s},\qquad f_n = 1.224\ \text{Hz}
  6. Equivalent length

    ℓ=I/(md)\ell = I/(md) = 165.8 mm (F6.08). It sits between the rod alone (2L/32L/3 = 100 mm) and the bob alone (D+2R2/(5D)D + 2R^2/(5D) = 168.8 mm), weighted towards the bob, which carries most of the mass.

  7. 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)
    ModelPeriod error
    Point mass at the bob centre on a massless rod: 2πD/g2\pi\sqrt{D/g}0.65 %
    Sphere only, rod ignored0.88 %
    Bob as a point (drop 25mbR2\tfrac25 m_b R^2)−0.22 %
    Rod as a line (drop mrr2/4m_r r^2/4)−7×10⁻⁴ %
  8. 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 anglePeriod 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 k=mgdk = mgd and the inertia II 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

Questions

Why not just use T=2πL/gT = 2\pi\sqrt{L/g}?
That is a point mass on a massless string. Applied to the running example with LL = 168 mm, it gives a period 0.65 % too long, which would swamp the damping and inertia measurements later. For a real body, use ℓ=I/(md)\ell = I/(md) in place of LL (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 ℓ\ell slows the swing, one added higher up speeds it up, and one added exactly at ℓ\ell (the centre of oscillation) changes nothing (F6.12). For example, 5 g at ℓ/2\ell/2 changes the period by −0.29 %, and 5 g at 1.5 ℓ1.5\,\ell 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 25mbR2\tfrac25 m_b R^2 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 mgdmgd 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 II: 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

Read

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. [1]

    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).

    read
  2. [2]

    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.

    read
  3. [3]

    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.

    read
  4. [4]

    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).

    read
  5. [5]

    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.

    read
  6. [6]

    University Physics Volume 1, §10.4 Moment of Inertia and Rotational Kinetic Energy (opens in a new tab)

    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.

    read
  7. [7]

    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.

    read
  8. [8]

    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.

    read
  9. [9]

    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.

    read
  10. [10]

    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).

    read
  11. [11]

    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.

    read
  12. [12]

    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.

    listed
  13. [13]

    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.

    derived
  14. [14]

    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).

    read
  15. [15]

    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.

    listed
  16. [16]

    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.

    listed
  17. [17]

    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).

    listed