AMD Labs

How it flies

Teach it, learn it

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.

Start lesson 1For instructors

Throttle

Controls altitude by motor speed

Yaw

Rotates drone nose in place

Pitch

Tilts forward or backward direction

Roll

Moves sideways by motor speed

Lesson 01 · 45 min

How a quadcopter flies

By the end, you can:
  • Explain how four motors produce throttle, roll, pitch and yaw
  • Explain why two motors spin each way

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.

  • Throttle: all motors speed up or slow down together.
  • Roll and pitch: motors on one side speed up while the other side slows down, tilting the drone.
  • Yaw: each motor's reaction torque twists the frame the opposite way. Speeding up one diagonal pair and slowing the other turns the drone.

The F450's symmetry keeps the mixing maths simple, since every motor is the same distance from the centre.

Activity

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.

Instructor notes

Students often think yaw comes from tilting. Have them hold a spinning fan or motor to feel reaction torque.

Check your understanding

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.

Lesson 02 · 60 min

Choosing parts that work together

By the end, you can:
  • Read KV, propeller and C ratings
  • Check current and battery headroom

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.

Activity

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.

Instructor notes

Ask for the reasoning, not just the answer. Point out that peak current and hover current differ, and that margin costs weight.

Check your understanding

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.

Lesson 03 · 60 min

Power and electrical noise

By the end, you can:
  • Explain why switching regulators beat linear ones here
  • Explain what decoupling capacitors do

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.

  • Battery to ESCs: thick wires through the power board.
  • Battery to 5 V: a switching buck converter, which wastes far less heat than a linear regulator.
  • 5 V to 3.3 V: small onboard regulators.

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.

Read the full story.

Activity

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.

Instructor notes

If no scope is available, show a captured trace and have students explain it. Discuss why position matters as much as capacitor value.

Check your understanding

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.

Lesson 04 · 60 min

Sensors and buses

By the end, you can:
  • Compare I2C, SPI and UART
  • Say what each drone sensor measures
BusWiresTypical speed hereOn our drone
SPI4, with one select per chipUp to 20 MHz on the MPU6500IMU, barometer, radio
I2C2, shared by addressUp to 400 kHzMagnetometer
UART2, point to point115200 baudGPS, 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.

Activity

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.

Instructor notes

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.

Check your understanding

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.

Lesson 05 · 75 min

Sensor fusion

By the end, you can:
  • Explain why neither gyro nor accelerometer is enough
  • Describe what the Mahony filter does

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.

  1. Filter: a hardware filter of about 41 Hz, then a software filter.
  2. Correct: remove false acceleration when the IMU sits away from the centre of rotation.
  3. Compare: the Mahony filter compares gravity as predicted from the gyro with gravity as measured, using a cross product.
  4. Adjust: a small PI loop nudges the gyro to remove the error and learn its drift.
  5. Yaw: gravity cannot sense heading, so yaw blends 98% gyro with 2% magnetometer.

Orientation is stored as a quaternion, which avoids the gimbal lock of Euler angles.

Activity

Log roll angle from the dashboard while tilting the board by hand. Then tap the frame and watch how little the filtered value reacts.

Instructor notes

Keep the maths light for beginners. The cross-product idea can be shown with two pens pointing in slightly different directions.

Check your understanding

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.

Lesson 06 · 90 min

PID control

By the end, you can:
  • Describe what P, I and D each do
  • Tune a simple system in the right order

PID turns an error into a correction. The firmware runs it 250 times a second.

  • P pushes in proportion to the error now. Too much makes fast oscillation.
  • I adds up small errors over time. It removes steady offsets, but too much makes slow rocking.
  • D resists fast change, like a shock absorber. Too much amplifies noise and heats motors.

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:

  • D on the measurement, to prevent a kick when sticks move suddenly.
  • A low-pass filter on the D term.
  • Feedforward for a sharper stick response.
  • Pausing the I term when outputs are saturated, to prevent windup.
  • Shortest-path yaw error, so 350° to 10° is a 20° turn.
  • TPA, which reduces P and D at high throttle.

Activity

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.

Instructor notes

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.

Check your understanding

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.

Lesson 07 · 75 min

Real-time firmware and failsafes

By the end, you can:
  • Explain why timing must be deterministic
  • Describe the main failsafes

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.

Activity

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.

Instructor notes

A good discussion question: is it better to disarm or descend when the radio is lost? Why might it depend on altitude?

Check your understanding

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.

Lesson 08 · 60 min

Radio, telemetry and dashboard

By the end, you can:
  • Trace data from sensor to browser
  • Explain why data rate affects range

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.

Activity

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.

Instructor notes

Good for students with web experience. Pair them with embedded-focused classmates so they see both ends of the link.

Check your understanding

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.

Lesson 09 · 60 min

A magnetometer as a metal detector

By the end, you can:
  • Explain how ferrous metal shows up in magnetic data
  • State the method's limits honestly

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.

Activity

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.

Instructor notes

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.

Check your understanding

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.

For instructors

Running this as a course

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.

Suggested schedule

SessionTopicTime
1How a quadcopter flies45 min
2Choosing parts that work together60 min
3Power and electrical noise60 min
4Sensors and buses60 min
5Sensor fusion75 min
6PID control90 min
7Real-time firmware and failsafes75 min
8Radio, telemetry and dashboard60 min
9A magnetometer as a metal detector60 min

Marking rubric

AreaDevelopingCompetentExcellent
ConceptsCan define termsExplains why each design choice was madeApplies ideas to a new drone design
CalculationsFollows the worked exampleSolves with changed valuesChecks a parts list unaided
PracticalCompletes lab with guidanceCompletes lab and records resultsDiagnoses a fault by measuring
SafetyFollows the rules when remindedFollows the rules unpromptedIdentifies new risks and controls them
Safety in class

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.