Playground · research instrument
On-device AIPID & MPC Flight Arena
A 3-D rigid-body quadrotor simulated with unit quaternions and RK4 in your browser. Tune Kₚ,Kᵢ,K_d and MPC Q/R weights live, throw wind gusts, watch force arrows and coordinate paths, feel crash shake, and hear motor whine pitch-tracked to thrust commands.
Independent research instrument — not claimed as MakerPortal shipped product code. Methods, equations, assumptions, and limitations are disclosed so you can inspect what the page does and does not establish.
Controller Tuning
Altitude PID — z error → collective
Attitude — roll/pitch rate
MPC Weights — J = xᵀQx + uᵀRu
Setpoint
3D flight viewport — top-down + side, force vectors
Anatomy of the arena
Quaternion rigid body & PID/MPC
- State: p,v ∈ ℝ³, q∈ℍ unit, ω∈ℝ³ body rates. Mass m=1.02 kg, I=diag(0.01,0.012,0.02).
- Dynamics: m·ṗ = v, m·ṽ = R(q)·[0,0,T]ᵀ - mg + F_gust, q̇=½ q⊗[0,ω], I·ω̇=τ - ω×Iω.
- PID altitude: e_z = z_sp−z, T = m(g+Kp e + Ki∫e + Kd ė). Clamped to [0.2mg, 2.2mg].
- Attitude: outer x/y PID → desired roll/pitch, inner P-D tracks via τ.
- MPC LQR: Q=diag(Qpos), R=R_thrust, K_lqr from DARE for hover double integrator.
Quaternion derivative
Gimbal-lock-free attitude propagated by RK4 then renormalized.
Visual-audio coupling
- Canvas shows quad X frame: 4 rotors, shadow, force arrows: green thrust, red gravity, cyan PID correction.
- Trajectory trail: 400-point buffer fading alpha, blue = normal, red when |v| impact high.
- Crash shake: CSS translate random proportional to kinetic energy, cuts thrust 0.8s.
- Audio: 4 motor oscillators at f_i = 80 + 350·(ω_i/ω_max). Master gain = thrust/hover. Stereo panning L/R maps roll.
- MPC readouts: J cost adds position and control penalty, displayed live.
MPC Cost
Gear behind this build
Flight simulator stack · 8 picks
Flight controller & drone gear8
$39.13SensorAdafruit 9-DOF Absolute Orientation IMU Fusion Breakout - BNO055
Bosch BNO055 fusion IMU breakout — quaternion/Euler output for flight, SLAM, and head-tracking labs. Closest verified Amazon listing to BNO085 workflows.
$185.99InterfaceRadioMaster Boxer 2.4GHz 16CH Hall Gimbals Radio Controller with Carrying Case, Mode 2 (ELRS)
EdgeTX Boxer with hall gimbals — ELRS-ready transmitter for PID Flight Arena bench flying.
$20.95SensorSparkFun 9DoF IMU Breakout - ICM-20948 (Qwiic)
SparkFun Original Qwiic ICM-20948 — 9-DoF for PID Flight Arena and SLAM IMU fusion. 10% Originals commission.
$23.80MicrocontrollerTeensy 4.0
600 MHz Cortex-M7 — high-rate control loops and DSP on the RTOS / FOC benches. Carried by SparkFun (third-party PJRC; tracked referral).
$29.95MicrocontrollerSparkFun Thing Plus - ESP32 WROOM (USB-C)
SparkFun Original ESP32 Thing Plus — Wi-Fi/BLE flight-firmware and RTOS target. 10% Originals commission.
$119.95KitExperiential Robotics Platform (XRP) Kit
SparkFun Original XRP robot kit — mechanical + control lab hardware when you outgrow FEA fixtures. 10% Originals. (No 3D printers in SparkFun catalog as of 2026-07.)
ApparatusSpeedyBee F405 V3 Flight Controller - 30x30-1
30×30 Betaflight F405 FC with wireless config — PID bench companion for the Flight Arena (verified ASIN).
KitSpeedyBee F405 V4 Flight Controller Stack:30x30 Bluetooth Stack with 4in1 55A ESC Board,Wireless Betaflight Configuration,Blackbox,Barometer for DJI Air Unit FPV
Bluetooth Betaflight stack (FC + 4-in-1 ESC) — full power stage for taking PID gains to a quad.
Prices shown were retrieved from the Amazon Product Advertising API on 19 July 2026 and are indicative only — the price and availability on Amazon at the time of purchase apply.
More gear across every app: the full Gear list →
Hardware Kit Builder
Build the physical hardware platform. Select your components below to generate a live, real-time bill of materials and build instructions.
Build this lab
Hover-ready flight stack
Betaflight stack + ELRS radio + SparkFun ICM-20948 IMU — take PID gains from the arena to a real quad bench. IMU earns SparkFun Originals commission.
- —
- $186
- $21
- $30
- $39
Prices shown were retrieved from the Amazon Product Advertising API on 19 July 2026 and are indicative only — the price and availability on Amazon at the time of purchase apply.
Estimated total
—
Prices from Amazon catalog cache · may change
Equations of motion
Force balance
Collective thrust rotated to world via R(q).
Moment & gyro
PID
Core solver — TypeScript
// Quadrotor state: pos, vel, quat q=(w,x,y,z), omega
type State = { p: Vec3; v: Vec3; q: Quat; w: Vec3; };
type Quat = { w:number; x:number; y:number; z:number; };
type Vec3 = { x:number; y:number; z:number; };
function quatMul(a:Quat,b:Quat):Quat{
return { w:a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z,
x:a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y,
y:a.w*b.y - a.x*b.z + a.y*b.w + a.z*b.x,
z:a.w*b.z + a.x*b.y - a.y*b.x + a.z*b.w };
}
function quatNorm(q:Quat){ const n=Math.hypot(q.w,q.x,q.y,q.z)||1; return {w:q.w/n,x:q.x/n,y:q.y/n,z:q.z/n}; }
function quatDeriv(q:Quat, w:Vec3):Quat{
const omega:Quat={w:0,x:w.x,y:w.y,z:w.z};
const qd=quatMul(q, omega);
return {w:qd.w*0.5,x:qd.x*0.5,y:qd.y*0.5,z:qd.z*0.5};
}
function rk4(f:(s:State)=>StateDeriv, s:State, dt:number):State {
const k1=f(s), s2=add(s,scale(k1,dt/2));
const k2=f(s2), s3=add(s,scale(k2,dt/2));
const k3=f(s3), s4=add(s,scale(k3,dt));
const k4=f(s4);
return add(s, scale(combine(k1,k2,k3,k4), dt/6));
}Export · Soft gate
Export PID gains + Betaflight snippet
Tuned Kp/Ki/Kd for roll/pitch/yaw/thr from the arena as JSON + Betaflight CLI snippet — free watermarked, clean after email unlock. Includes hover stack BOM link.
File · pid-gains.json
pid-gains.jsonapplication/json+ watermark line on free pathFree download adds a small footer:
/* Export from makerportal.ai — free watermarked build. Unlock …Clean export removes footer. Both are generated fresh from your current sim tuning.
Privacy: email stays in your browser localStorage (mp_export_email_pid-flight-arena) + unlock flag (mp_export_unlock_pid-flight-arena). If Buttondown username is configured, we also POST to Buttondown (privacy-first mode, no tracking pixels per D-014). See privacy → affiliates & email.
Unlock clean export
Soft gate — no hard paywall, no Clerk. Email stays local unless you explicitly check the newsletter box. Unsubscribe anytime. RSS at /rss.xml.
✓ Lab Pro — clean export on every lab
Your licence unlocks this and every other gated simulator, so there is nothing to enter here. Manage or sign out on the shop page.
✓ Unlocked — clean exports enabled
Stored in mp_export_unlock_pid-flight-arena. Clean file omits watermark. Re-lock via browser devtools → localStorage.
Frequently asked questions
Why quaternions and not Euler angles?
Euler angles suffer gimbal lock when pitch approaches ±90° and their composition depends on order. Quaternions are unit 4-vectors q=(w,x,y,z) that rotate via q⊗[0,ω]⊗q* without singularities. The flight dynamics integrate q̇ = 0.5 q ⊗ [0, ω_body] and renormalize |q|=1 every step to prevent drift. Roll/pitch/yaw readouts are derived from q only for the pilot display.
How is the MPC blending with PID?
For hover-linearized dynamics ẋ=Ax+Bu, MPC minimizes J=∑ xᵀQx + uᵀRu over horizon N. With diagonal Q_pos, R_thrust, the unconstrained solution collapses to LQR gain K = (R+BᵀPB)^-1 BᵀPA from DARE. We pre-solve K analytically for the 1D altitude subsystem and blend K·x with PID output proportionally to MPC authority slider. Increasing Q/R weight ratio makes MPC more aggressive on position error.
What does crash detection do numerically?
Collision when z ≤ 0.05 m. Velocity decay uses restitution e=0.2, so v_z⁺ = -e·v_z⁻, v_xy⁺ = (1-0.4)·v_xy⁻. Integrated shaking energy E = m·|v|² triggers viewport CSS shake amplitude A = clamp(E/40,0,8) px and cuts motor commands to zero for 0.8s, forcing integral unwind.
How accurate is RK4 here?
RK4 is 4th-order accurate with global error O(dt⁴). At dt=0.004s (250 Hz control loop) energy drift over 30s hover is <0.2%. Euler would artificially dampen high-Q roll oscillations and destabilize Ki buildup. Quaternion integration additionally normalizes after each RK4 stage.
How to tune without instability?
Start with Ki=0, Kd=0. Increase Kp until 10-15% overshoot. Add Kd ≈ Kp·0.15 to damp overshoot. Finally add Ki ≈ Kp/8 but clamp integrator to thrust margin to avoid windup. For MPC, increase Q_pos slowly - too high causes aggressive collective that saturates motors, heard as maximum motor whine pitch.
Shareable still
The instrument, captured—not illustrated.
This 16:9 frame is rendered from the real browser instrument above. It is the page's canonical preview for image search, link unfurls, and posts that need to show what the tool actually does.
Download 1280 × 720 JPEG
Continue the experiment