loading...
Step test: simulates the current settings. Damping sweep: measures the settling time against zeta for an ideal loop and compares it with the closed form.
running...
How to use
Three linked views. Side view: the rig with its Blender-rendered parts; click the beam to move the setpoint. Phase plane (position against velocity): the trajectory spirals into the setpoint line; the dashed curve is the ideal second-order prediction from the current state; the red lines are the beam ends; click or drag in it to place the ball. Pole map: the poles of the closed loop (crosses) move as you change gains, servo speed or delay; the loop is stable only if all lie left of the vertical axis; the ring is the ideal pair set by wn and zeta.
Try: (1) raise zeta from 0 to 1.5 and watch the poles run from the imaginary axis down and apart; (2) Lazy servo: a pair of poles crosses to the right; (3) Delay 150 ms; (4) the Damping sweep button measures the settling time for 31 values of zeta against the closed form; (5) place the ball with large speed and see where the saturating servo cannot catch it. Space pauses, R resets.
The side view uses sprites rendered with Cycles in Blender from the same rig as the 3D companion (base, beam, horn, ball, backdrop); everything else is drawn live on the canvas.
The science
The ball-and-beam is the textbook feedback problem. A ball rolls freely on a beam; a servo tilts the beam; a distance sensor reports where the ball is. With the beam level the ball stays wherever it is, with the beam tilted it accelerates downhill. Position is therefore the double integral of the tilt: the plant has two poles at zero, it is not stable on its own, and without feedback the ball always runs off the end. The same structure appears in a rocket's attitude loop, a balancing robot or a quadcopter's position hold.
The plant. A ball of mass m and radius R rolling without slipping on rails tilted by the angle θ, at distance r from the pivot, obeys (Lagrange, kinetic energy of translation plus rotation):
(1 + k) r'' = r θ'2 + g sinθ − c (1 + k) r' k = J / (m ρ2)
Mass and radius cancel. Only the shape of the mass distribution enters through k: 2/5 for a solid sphere, 2/3 for a thin shell, about 0.47 for a thick hollow ball (inner radius 0.6 R), 0 for a frictionless slider. If the ball rides on two thin rods a distance s apart it rolls on a smaller effective radius ρ = √(R2 − s2/4), so k grows by R2/ρ2: a wide rail gap slows the ball. The term rθ'2 is the centrifugal force of the rotating beam; c is an optional viscous rolling drag. For small angles r'' = aθ with a = g/(1+k): a solid sphere on a flat rail accelerates at only 5/7 g sinθ, the well-known 71 % of a sliding block.
Servo. The beam angle follows the command through a second-order lag, θ'' = ωs2(θc − θ) − 2 ζs ωs θ' with ζs = 0.7, plus a rate limit and an angle limit. The servo is treated as an ideal motion source: the small torque of the ball does not disturb it.
Controller. The sensor sample (every 5 ms, with noise and delay) gives r̂. The command is
θc = Kp (rsp − r̂) − Kd v̂ + Ki ∫(rsp − r̂) dt, Kp = ωn2/a, Kd = 2 ζ ωn/a
The sliders set the closed-loop natural frequency ωn and damping ζ; the gains follow from a, so changing the ball or gravity re-tunes the controller. The derivative acts on the measurement (no kick at a setpoint step) through a first-order filter. For an ideal servo the loop is r'' + 2ζωn r' + ωn2 r = ωn2 rsp, with overshoot e−πζ/√(1−ζ2). ζ = 0 (P only) never decays: the ball swings forever at ωn and the servo lag actually feeds the swing, so the amplitude creeps up. The fastest 2 % settling is near ζ = 0.76.
Why real loops misbehave. The pole map includes the full loop: the servo (second order), the derivative filter, drag, the integral term and the delay (sample hold, derivative difference and the sensor delay, as a second-order Padé approximation), solved with the Durand-Kerner root finder. A servo that is slow compared with ωn or a delay of the order 1/ωn pushes the poles into the right half plane. Noise is amplified by differentiation: a difference quotient of noise σ has standard deviation σ√2/Ts; with the first-order filter (α = Ts/(Tf+Ts)) it is σ√2 α/(Ts√(2−α)) (checked by Monte Carlo below). That is the reason for the velocity filter, at the price of phase lag.
Numerical checks run in the page (fresh objects, independent of what you see): (1) rolling time over 30 cm at 10° against √(2d(1+k)/(g sinθ)), for each ball and rail gap; (2) the centrifugal term against the cosh/sinh closed form with g = 0 and a Jacobi constant; (3) energy conservation at constant tilt; (4) the P-only period against 2π/ωn; (5) PD step overshoot against the damping formula; (6) the damped frequency and decay rate of a loop with servo lag from the roots of its characteristic polynomial against the time-domain simulation; (7) a 400,000-sample Monte Carlo of the velocity-estimate noise against the closed form.
Simplifications. Rolling without slipping (the page flags when the needed friction k/(1+k)·tanθ exceeds the value you set, but it does not model the slip); the ball centre sits above the beam but this offset and the Coriolis coupling are ignored; the beam, servo and sensor are ideal apart from the stated lag, limits, noise and delay; no backlash or friction in the servo; the linear pole analysis ignores saturation and sampling beyond the delay approximation, so a loop reported stable can still limit-cycle when it saturates, and the Padé delay is approximate for delays longer than about 0.3/ωn. Typical hobby servo numbers (bandwidth, rate) and the sensor noise are illustrative.