Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

building & programming a

QUADCOPTER
FLIGHT CONTROLLER
from scratch
I’m Ryan Boland

Web Developer

@ Tanooki Labs

@bolandrm (github, twitter)


1. Components
2. Quadcopter Physics
3. The Flight Loop
FRAME
Electronic Speed Controllers (ESCs)
& Motors
Lithium Polymer (LiPo) Battery
Remote Control Transmitter & Receiver
Flight Controller
Microprocessor &
Inertial measurement Unit (IMU)
My Project - Custom Flight Controller

$55 $5 $20

Arduino Mega 2560 Arduino Nano Clone Teensy 3.1


& Prototyping Shield 8-bit AVR 32-bit ARM
8-bit AVR 16 MHz clock 96 MHz clock
16 MHz clock 32K Flash 256K Flash
256K Flash 2K Ram 64K Ram
8K Ram
Custom
PCB
Inertial Measurement Unit

GY-87
$8

MPU6050 - 3 axis gyroscope, 3 axis accelerometer


HMC5883L - 3 axis magnetometer
BMP180 - Barometer
Flight
Configuration: + vs X
Orientation

x axis <-> roll


y axis <-> pitch
z axis <-> yaw
Maneuvering
Stabilization
Rate mode - gyroscopes only
Remote control determines the rate at which the
quadcopter is rotating on any given axis.
Also known as Acro or Manual.

Attitude mode - accelerometers & gyros


Remote control determines the desired angle of the
quadcopter.
Also known as self-level or auto-level.
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Gyroscope data
Actual rotational rate in °/sec

Remote control data


Pilot’s desired rotation rate in °/sec

Error
Difference between actual and desired rotational rate
e = gyro_rate - rc_rate
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
3 errors to correct
PID Controllers
(proportional, integral, derivative)

For each axis (yaw, pitch, roll):

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot

RC
error

input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot
RC error

input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot

RC
error
input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot

RC
error

input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot

RC
error

input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot

RC
error

input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
PID Controllers
(proportional, integral, derivative)

Pilot

RC
error

input e(t)
Motor Output

Rotational rate (from gyro)

3 constants - Kp, Ki, Kd

PID for dummies:

http://www.csimn.com/CSI_pages/PIDforDummies.html
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Maneuvering
Flight Controller Code

motor1 = rc_throttle - roll_adjust - pitch_adjust - yaw_adjust;

motor2 = rc_throttle + roll_adjust + pitch_adjust - yaw_adjust;

motor3 = rc_throttle - roll_adjust + pitch_adjust + yaw_adjust;

motor4 = rc_throttle + roll_adjust - pitch_adjust + yaw_adjust;

correcting roll, pitch, yaw


Flight Controller Code

motor1 = rc_throttle - roll_adjust - pitch_adjust - yaw_adjust;

motor2 = rc_throttle + roll_adjust + pitch_adjust - yaw_adjust;

motor3 = rc_throttle - roll_adjust + pitch_adjust + yaw_adjust;

motor4 = rc_throttle + roll_adjust - pitch_adjust + yaw_adjust;

correcting roll, pitch, yaw


Flight Controller Code

motor1 = rc_throttle - roll_adjust - pitch_adjust - yaw_adjust;

motor2 = rc_throttle + roll_adjust + pitch_adjust - yaw_adjust;

motor3 = rc_throttle - roll_adjust + pitch_adjust + yaw_adjust;

motor4 = rc_throttle + roll_adjust - pitch_adjust + yaw_adjust;

correcting roll, pitch, yaw


Flight Controller Code

motor1 = rc_throttle - roll_adjust - pitch_adjust - yaw_adjust;

motor2 = rc_throttle + roll_adjust + pitch_adjust - yaw_adjust;

motor3 = rc_throttle - roll_adjust + pitch_adjust + yaw_adjust;

motor4 = rc_throttle + roll_adjust - pitch_adjust + yaw_adjust;

correcting roll, pitch, yaw


Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Safety & Handling Failure
Stale IMU values

Stale remote control values

Angles too high?

Motor outputs too high? (indoor safe mode)

Watchdog
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Flight Loop (1000 Hz)
Wait for data ready interrupt

Read & filter gyroscope data

Read remote control data (user input)

Use PID (proportional, integral, derivative) algorithm


to compute required adjustment for each axis

Map adjustment for each axis to motors (Mixer)

Safety checks

Output to motors
Some Takeaways

Be Safe

Start small (mini quad


or balancing robot?)

Break things down


into subcomponents
Thanks!

@bolandrm

You might also like