GO DRONE PROGRAMMING · FLIGHT SIMULATOR · 7 LESSONS
Flight control: PID, cascades, filters and loops
PID altitude control and anti-windup, cascaded position and velocity loops, complementary and Kalman filters, fixed-rate loops in Go, quad X motor mixing and flight modes as a state machine.
PID altitude control: P, I and D on the collective thrust
Close an altitude loop through SetThrust with a PID controller that takes its derivative from the measurement, clamps its integral and saturates its output, and judge each variant by rise time, overshoot, settling time and steady-state error.
5 min · Worked lesson
Cascaded control: a position loop on top of a velocity loop
Build an outer position loop that sends velocity setpoints through SetVelocity, explain why inner loops must be faster and where the integrator belongs, and compare P, PI and velocity feedforward when holding a point in wind and following a moving target.
6 min · Worked lesson
Complementary filter: fusing a fast drifting signal with a slow noisy one
Estimate altitude by integrating a biased vertical velocity at 50 Hz and correcting it with the 5 Hz barometer, choose the time constant tau and alpha = tau / (tau + dt), and measure the result as RMSE against the true altitude.
5 min · Worked lesson
A Kalman filter for altitude and climb rate
Write a 1-D constant-velocity Kalman filter that fuses GPS altitude, barometer and a climb-rate measurement, follow its state, covariance, predict and update steps, tune process and measurement noise, and reject outliers with an innovation gate that cannot lock out the truth.
6 min · Worked lesson
Fixed-rate loops in Go: tickers, jitter, GC and allocations
Run a supervisory control loop at a fixed rate with time.Ticker, understand dropped ticks, jitter and the monotonic clock, keep allocations out of the loop body and prove it with testing.AllocsPerRun, and decide what belongs in firmware instead.
5 min · Worked lesson
Motor mixing for a quad X: thrust and torques to four motors
Map collective thrust and roll, pitch and yaw torque commands to four motor outputs with PX4's Quadrotor X numbering and spin directions, and handle saturation by giving up thrust and yaw before roll and pitch.
5 min · Worked lesson
Flight modes as an explicit state machine
Model flight modes as states, events and guarded transitions in a table, reject invalid requests with reasons, run pre-arm checks for battery, GPS fix and geofence, map the states onto the simulator's modes and log every transition.
5 min · Worked lesson