Throttle
Controls altitude by motor speed
How it flies
Nine lessons taken from a real build, each with goals, an activity and a quiz. Use them to teach a class, or work through them on your own.
Controls altitude by motor speed
Rotates drone nose in place
Tilts forward or backward direction
Moves sideways by motor speed
A quadcopter has no moving control surfaces. It steers only by changing motor speeds. Our drone uses an X layout, where the two diagonal pairs spin in the same direction.
The F450's symmetry keeps the mixing maths simple, since every motor is the same distance from the centre.
Using the mixing explorer, predict which motors speed up for right roll, then check. Then draw the X layout and label each motor's direction from memory.
Students often think yaw comes from tilting. Have them hold a spinning fan or motor to feel reaction torque.
Why do diagonal motor pairs spin the same direction?
Two CW and two CCW motors cancel torque. Changing the balance between them creates yaw.
To pitch forward, which motors need more thrust?
More rear thrust raises the tail and tips the nose down, so the drone moves forward.
The motor, propeller, ESC and battery form one system. High-KV motors suit speed. Our 980 KV motors with 10-inch propellers suit stable lifting.
Here are the sums from our build:
Motor peak current ≈ 15 A → 4 motors ≈ 60 A
ESC margin = 30 A / 15 A = 2×
Battery output = 5.2 Ah × 60C = 312 A available
Battery voltage = 3 cells × 3.7 V = 11.1 V nominal, 12.6 V full
We rejected a 4S battery because it would over-volt this motor and propeller pairing, and 20 A ESCs because of the risk of overheating.
Give students a different motor with a 25 A peak. Have them choose an ESC and work out the battery C rating needed for 4 motors using a 4000 mAh pack.
Ask for the reasoning, not just the answer. Point out that peak current and hover current differ, and that margin costs weight.
A 3S 5200 mAh 60C battery can supply about:
Capacity in Ah times C: 5.2 × 60 = 312 A.
Why not just use the highest-KV motors?
High KV favours speed. A slow lifting drone wants more torque and larger propellers.
The drone has two very different power needs: huge current pulses for motors and a clean, steady rail for logic. They should be kept apart.
When motors spin up, the rail dips and rings. On our drone that froze the I2C bus. Capacitors placed right at each sensor supplied local current and absorbed the noise.
With an oscilloscope, view a 3.3 V sensor rail while a noisy load switches. Add a ceramic and an electrolytic capacitor at the sensor and compare. No propellers are needed.
If no scope is available, show a captured trace and have students explain it. Discuss why position matters as much as capacitor value.
A linear regulator from 11.1 V to 5 V at 1 A wastes about:
(11.1 − 5) V × 1 A ≈ 6 W of heat.
Why place a capacitor right at the sensor?
Long wires add inductance, so a capacitor works best very close to the load.
| Bus | Wires | Typical speed here | On our drone |
|---|---|---|---|
| SPI | 4, with one select per chip | Up to 20 MHz on the MPU6500 | IMU, barometer, radio |
| I2C | 2, shared by address | Up to 400 kHz | Magnetometer |
| UART | 2, point to point | 115200 baud | GPS, ESP32 |
Reading the IMU over I2C limited our control loop, so we moved it to SPI. The magnetometer stayed on I2C because it updates more slowly. But I2C can lock up, so the firmware has a recovery routine: it toggles the clock 9 times to release the bus.
Work out how long a 14-byte IMU read takes at 400 kHz I2C and at 10 MHz SPI, ignoring overhead. Then compare both with the 4000 µs loop period.
Answers: about 315 µs for I2C at 9 bits per byte and about 11 µs for SPI at 8 bits per byte. Discuss what else the loop must fit in.
Why did we move the IMU from I2C to SPI?
The control loop was limited by the time spent waiting for I2C data.
What does a magnetometer measure?
That gives both a compass heading and magnetic anomaly detection.
A gyroscope is smooth but drifts over time. An accelerometer knows where gravity points but is badly affected by vibration. Sensor fusion uses each to correct the other.
Orientation is stored as a quaternion, which avoids the gimbal lock of Euler angles.
Log roll angle from the dashboard while tilting the board by hand. Then tap the frame and watch how little the filtered value reacts.
Keep the maths light for beginners. The cross-product idea can be shown with two pens pointing in slightly different directions.
Why not just integrate the gyroscope?
Integrating a small bias produces a growing angle error.
Why does yaw need a magnetometer?
Rotating around the vertical doesn't change the gravity vector.
PID turns an error into a correction. The firmware runs it 250 times a second.
Starts at 15° tilt and tries to reach level. Simplified teaching model. Do not copy these gains to a real drone.
Our firmware adds refinements to the textbook version:
On the simulator, set I and D to 0 and raise P until it oscillates. Add D until it settles. Turn on the steady push, see the offset, then add I. Later, repeat on a rig with a real axis.
The simulator is simplified. Stress that real tuning is done on a rig and that its values do not transfer. Tuning order: P, then D, then I.
The drone oscillates rapidly. First try:
Fast oscillation usually means too much P.
The drone holds a steady angle offset in a constant wind. Which term fixes it?
I builds up until a constant error is cancelled.
What is derivative kick?
Computing D on the measurement removes it.
A flight controller must run on time, every time. Our main loop is driven by a hardware timer:
TIM4 interrupt every 4000 µs → sets pid_loop_flag
while (1):
if pid_loop_flag:
read IMU → fusion → PID → motor mix → set PWM (250 Hz)
every 5th loop: barometer + magnetometer (50 Hz)
every 50th loop: send telemetry JSON (5 Hz)
Nothing here should block. UARTs use interrupts with lock flags, the radio is polled once per loop, and hardware timers generate PWM in the background. Gains are stored in internal flash, with a magic number that detects blank memory on first boot.
Failsafes cover radio loss, dashboard loss, geofence breach, crashes and I2C faults. They need testing, and they can be wrong: our low-battery failsafe is currently inactive because the battery reading is hardcoded. See the status list.
With propellers off and the drone armed, switch off the transmitter and record how long it takes to react. It should be about 500 ms. Discuss why a failsafe needs testing. As an extension, propose a fix for the battery reading.
A good discussion question: is it better to disarm or descend when the radio is lost? Why might it depend on altitude?
Why not use HAL_Delay() to time the control loop?
I and D rely on a known, consistent time step.
Why was the ESP32 replaced as flight controller?
It now does telemetry, where this matters less.
The drone has two separate links:
Control: Joysticks → ADS1115 → ESP32 → nRF24 ))) nRF24 → STM32 50 Hz, 8 bytes
Telemetry: STM32 → UART → ESP32 ))) Wi-Fi → Node.js → Socket.IO → browser 5 Hz, JSON
The control packet has four 16-bit values, packed with #pragma pack so both chips agree on its exact layout. A low 250 kbps data rate gives better receiver sensitivity and more range, and 8 bytes needs very little bandwidth.
The dashboard limits its heavy chart updates to 1 Hz, so the page stays responsive.
Pick one value, such as roll angle. In the source code, follow it from main.c to ESP32_Telemetry.ino, server.js and script.js. Draw the path.
Good for students with web experience. Pair them with embedded-focused classmates so they see both ends of the link.
Why use 250 kbps instead of 2 Mbps?
Only 8 bytes at 50 Hz need to be sent, so speed can be traded for range.
Why use #pragma pack on the control packet?
The packet stays exactly 8 bytes on both chips.
Earth's magnetic field is fairly uniform locally. Ferrous objects distort it. Fly a magnetometer over an area and tag each reading with GPS, and those distortions appear on a map.
The dashboard's survey view cleans the data. It rejects poor GPS and readings taken while turning, corrects for altitude and slow drift, and draws heatmaps.
Limits: the sensor is a consumer compass chip and GPS error is 2 to 5 m. It can find a zone, but not an exact point, depth or shape. A signal can also come from the drone itself, which is why mounting and calibration matter.
Lay out a 1 m grid on the floor. Move a magnetometer board by hand over a hidden steel object and record the reading at each point. Plot it and locate the object. Repeat at twice the height.
Non-ferrous metals like aluminium barely register. Try one as a test. The grid exercise needs no drone at all, making it a safe and low-cost lab.
Which object is easiest for this method to detect?
The method senses disturbances to the magnetic field, which ferrous metals cause most strongly.
Why does the signal fall quickly with height?
The survey code uses an inverse-cube correction, which is why low flights matter.
The lessons suit university or advanced school students with basic programming and circuits. In total they take about ten hours, plus hands-on rig work if you have a drone. Most activities need no flight at all.
| Session | Topic | Time |
|---|---|---|
| 1 | How a quadcopter flies | 45 min |
| 2 | Choosing parts that work together | 60 min |
| 3 | Power and electrical noise | 60 min |
| 4 | Sensors and buses | 60 min |
| 5 | Sensor fusion | 75 min |
| 6 | PID control | 90 min |
| 7 | Real-time firmware and failsafes | 75 min |
| 8 | Radio, telemetry and dashboard | 60 min |
| 9 | A magnetometer as a metal detector | 60 min |
| Area | Developing | Competent | Excellent |
|---|---|---|---|
| Concepts | Can define terms | Explains why each design choice was made | Applies ideas to a new drone design |
| Calculations | Follows the worked example | Solves with changed values | Checks a parts list unaided |
| Practical | Completes lab with guidance | Completes lab and records results | Diagnoses a fault by measuring |
| Safety | Follows the rules when reminded | Follows the rules unprompted | Identifies new risks and controls them |
Run indoor labs with propellers removed. Only run powered propeller tests on a secured rig, with safety glasses and a named person ready to disarm. Charge LiPos under supervision.