Episode 01 / Written companion

Free recording track

I wrote a robot arm simulator from scratch

Rigid-body dynamics, a servo whose firmware stays closed and a shared 12 V supply, with four checks to run before trusting any of it.

Read the companion now. The recording is forthcoming; “Free” identifies its planned release track.

An arm simulator is two models stacked. Below sits rigid-body dynamics, M(q)·q̈ + C(q, q̇)·q̇ + g(q) = τ, for base rotation, shoulder, elbow and wrist pitch, integrated with RK4 at 1 kHz. Above sits the servo: a DC motor whose torque scales with supply voltage and falls with speed, a 345:1 gearbox whose reflected rotor inertia can outweigh a link’s own, friction and 12-bit encoders. One shared 12 V supply feeds them all and cuts every servo when the summed current stays above 5 A for more than 10 ms. On top runs a position loop whose firmware Feetech doesn’t publish, so how a gain register turns into torque stays a parameter.

Each check tests one layer with the others switched off. In a stretched horizontal pose, the holding torque at the shoulder, elbow and wrist must equal the summed m·g·r of everything outboard within 1%. With friction and servos off, a passive swing must conserve energy within 0.1% over 10 s. The course’s torque-step excitation on each joint must track MuJoCo within 0.5° over 0.5 s, with friction and servo terms off in both. MuJoCo loads an MJCF generated from the same Params, so agreement validates the dynamics code, not the servo model. The servo model must reproduce the datasheet’s stall torque and no-load speed at 12 V within 5%.

None of these checks touches the closed position loop, which stays unvalidated until Module 8. It starts from Rhoban’s BAM model, not MuJoCo Menagerie’s gains, which are 60–130 times stiffer: with them, 150 g at the hold pose sags the gripper by about a tenth of a millimeter, with BAM’s 7.4 V fit by 6–12 mm, and the payload tasks are built on millimeters of sag. Keep each check’s plot with the Params file, commit, config and seed. Then wave hello with open-loop sines on the elbow and wrist, and plot how the servo model shrinks and delays the wave as the frequency rises. Module 8 overlays the real arm’s traces on that plot.

Take this into your next build

Check each layer against a number you can compute or an independent solver, and name the layer you couldn’t check yet.

Put the idea to work

Write your own arm sim

Build a four-joint arm simulator from the manipulator equation up, with a motor, a shared supply and a firmware position loop behind every joint. Check the rigid body and the motor against numbers you can derive by hand before any closed loop runs.

Build module 01