I benchmarked 5 ways to auto-tune a robot arm's PID gains. Random search broke the safety limits in 73.8% of trials. Safe BO: 1.8%.
Hand-tuning PID gains is slow, and every payload change means starting over. Letting an optimiser explore on the real machine is tempting — but a "trial" there isn't a wasted data point, it's a torque spike into a joint
Hand-tuning PID gains is slow, and every payload change means starting over. Letting an optimiser explore on the real machine is tempting — but a "trial" there isn't a wasted data point, it's a torque spike into a joint limit. So I built a small testbed to ask a simple question: how much does safety-aware optimisation actually buy you?
Setup: a simulated two-link arm (friction, torque limits, noisy 16-bit encoder, control delay), an industrial-style 500 Hz PID with anti-windup, and six gains to tune. Five methods, same budget, 20 independent runs each:
- Random search — 73.8% of trials unsafe
- Standard BO (EI) — 36.8% unsafe
- CMA-ES — 12.7% unsafe
- Safe BO (GP models of both performance and safety; only confidently-safe gains ever get tested) — 1.8% unsafe, and still ends within 4.1% of the reference optimum after 50 trials
- Contextual Safe BO — for payload changes
Two results I didn't expect:
- The tuned controller halves RMS tracking error vs. commissioning gains (1.12° → 0.60°) without adding torque ripple. Safety didn't cost performance here; it mostly cost patience.
- Payload changes (1.0 → 2.5 → 1.75 → 0.5 → 2.0 kg): re-using past experiments as context gets within 13–17% of optimum with 10 trials per change, vs 18–29% for a cold start. After just 3 trials in later stages it's at 20–25% vs 44–50%. Warm-starting is worth more than a smarter acquisition function, at least here.
Honest limits: this is simulation only. No backlash, no flexible joints, no real hardware. The GP is written from scratch (Matérn-5/2 ARD) and cross-checked against scikit-learn, mostly because I wanted to see the safety logic without a library in between.
If you want to reproduce or poke holes in it: I packaged the full project — code, raw results for every run, tuning handbook, tests — as a curated edition here: https://gridlabnotes.gumroad.com/l/teusxx (full disclosure: that's my shop; it's how I fund spending more time on write-ups like this).
Curious whether anyone running SafeOpt-style methods on real hardware sees the same "warm start > acquisition function" ordering.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.