Control Systems · PID

Ball and Beam Control Simulator

The classic PID teaching plant — balance a rolling ball by tilting the beam it sits on.
x″ = (5/7)g·sinθ · RK4
PD · setpoint 0.30 m

PID gains

Setup

Ball

Same 3cm size throughout — only density/mass changes. Doesn't affect rolling on the beam (mass cancels out of that physics), but a light ball visibly curves off a clean parabola once airborne, from real air drag.
0 = clay (no bounce), 0.95 = superball. Each bounce keeps this fraction of speed, so energy drops by elasticity² per bounce.

Try it

Live simulation

— t = 0.0 s
speed
Result
Detail
How it works

A double integrator in disguise

A solid ball on a beam

Rolling without slipping: x″ = (5/7)·g·sin θ. The 5/7 is a solid sphere’s rotational inertia sharing the load. Mass cancels out.

No damping at all

Nothing in that equation opposes the ball’s motion. Any damping the closed loop shows has to come entirely from the controller.

A lagging servo

The beam angle follows the PID command through a first-order servo, τ ≈ 0.15 s, clamped to ±28°. The lag is what tips P-only into instability.

Off the beam, a projectile

If it separates or rolls off the end it falls under gravity and quadratic air drag (RK4) and bounces off a floor 0.35 m below the pivot.

Worked example. Set every gain to zero except Kp = 6 and the ball does not oscillate gently: it rolls off the end at t = 0.67 s, becomes a projectile and hits the floor bouncing. At the default 50% elasticity each bounce keeps about a quarter of the last one’s height, a ratio of about 0.247, matching restitution² as the physics predicts, before coming to rest around t = 1.5 s. Add Kd = 4 and the identical proportional gain settles smoothly: nothing about the ball changed, only the controller’s ability to react to its velocity.
Field notes

Why this system is a control-theory classic

A double integrator

Angle drives acceleration, acceleration integrates to velocity, velocity to position: two integrations between the input and what you are controlling, a classic hard case. A Segway, a rocket balancing on its thrust, magnetic levitation and the inverted pendulum are the same family.

Why P-only is famous for failing here

Proportional-only feedback on a double integrator is only marginally stable even in the ideal case; real actuator lag, like the simulated servo, tips marginal into unstable. That is what the “P only” preset shows, and the derivative term supplies the damping the physics never had. Raise Kd too far and the ball settles smoothly but slowly (overdamped); too little and it oscillates: the usual second-order trade-off in a physical position. Integral mops up small offsets but too much reintroduces oscillation.

mass cancels

Mass matters in the air, not on the beam

For a ball rolling without slipping, mass drops out of the acceleration equation, the same reason a bowling ball and a marble roll down a ramp together. Once airborne, drag scales with 1/mass: a light ball curves off a clean parabola while a heavy one barely notices the air, which is why the mass slider only matters after the ball leaves the beam.

Why the ball can leave the beam entirely

A fast enough beam movement can accelerate away from the ball faster than gravity pulls it back: the contact force the beam would need goes negative, which is impossible, so the ball separates and becomes a free projectile. It bounces if it lands back on the beam, and keeps falling to the floor if it clears the span. Try “Bounce demo”.

e²of the height

Restitution, not a fixed bounce height

The elasticity slider sets what fraction of speed survives each bounce, so the height kept is that fraction squared (kinetic energy goes with velocity squared). A 0.5 elasticity keeps 50% of speed but only 25% of the previous height, which is why bounces decay so fast at seemingly generous settings.

Questions

What people ask

Why does pure P control actively fail here, not just oscillate?

The plant is a pure double integrator (position needs two integrations from angle, with zero natural damping) — under proportional-only feedback that combination is only marginally stable in the idealised case, and the small extra lag from the simulated servo tips it into genuine instability. It's one of the cleanest classroom demonstrations of why "just add more P" doesn't always work.

Why does derivative gain fix it?

Since nothing in the physical system opposes the ball's motion, the controller has to supply that damping itself. The derivative term reacts to how fast the error is changing, which is exactly the missing velocity feedback the system needs to settle instead of overshoot forever.

What does the integral term add here?

With a well-tuned P and D, the ball already settles very close to the setpoint — integral action mops up any small remaining steady-state offset, but too much of it (relative to P and D) can reintroduce oscillation, the same trade-off as any PID loop.

What real systems does this represent?

Any balancing problem built on a double integrator with no natural damping: a Segway or self-balancing robot, a rocket balancing on its thrust, magnetic levitation, or the classic inverted pendulum. Ball-and-beam rigs are a staple of university control labs precisely because they're a physical, visible version of this family of problems.

Why doesn't the mass slider change how the ball rolls on the beam?

Because it genuinely shouldn't — for rolling without slipping, mass cancels out of the acceleration equation, the same reason a bowling ball and a marble roll down a ramp at the same rate. Making mass affect the on-beam physics would mean faking a result real mechanics doesn't produce. It matters once airborne instead, through air drag, which is real and mass-dependent.

What happens when the ball leaves the beam?

It becomes a genuine projectile — real gravity, real air drag, no scripted fallback. If it re-lands within the beam's span it bounces there with the same restitution physics; if it clears the beam entirely or rolls off the end, it keeps falling until it hits the floor below, bouncing and losing energy each time until it settles.

A real, notoriously tricky control problem. Try P-only control first — this system is famous in control courses specifically because it fails without derivative action.
Version history · site-wide passes only

This page has changed in 192 archived releases, but each of those was a site-wide pass, so none is attributable to this tool on its own and none is listed here. That is not a claim that the tool never changed — a release that reworked many pages at once may well have altered this one too. The changelog has them.

Rules of thumb are approximations, offered to get you to the right order of magnitude fast. Check anything load-bearing against its source or the exact tool. Privacy · Terms

© 2026 Rules of Thumb · Runs entirely in your browser