Quadstripped 150226205933 Conversion Gate01
Quadstripped 150226205933 Conversion Gate01
Programming
for
Quadcopters
I’m Ryan Boland
Web Developer
@ Tanooki Labs
Microprocessor &
Inertial measurement Unit (IMU)
My Project - Custom Flight Controller
$55 $5 $20
GY-87
$8
x axis == roll
y axis == pitch
z axis == yaw
Maneuvering
The Code
Control Loop
void loop() {
while(!imu_read());
rc_read_values();
fc_process();
}
Control Loop
void loop() {
while(!imu_read());
rc_read_values();
fc_process();
}
Orientation (IMU)
measures rotational
rate in °/sec
IMU - Gyroscope
0 0 0 0°
5 °/s 2s 10 ° 10 °
-5 °/s 1s -5 ° -15 °
Gyroscope - Angles
void compute_gyro_angles() {
mpu6050_read_gyro(&gyro_rates);
rates.x = gyro_rates.x + GYRO_X_OFFSET;
gyro_last_update = micros();
}
Gyroscope - Angles
void compute_gyro_angles() {
mpu6050_read_gyro(&gyro_rates);
rates.x = gyro_rates.x + GYRO_X_OFFSET;
gyro_last_update = micros();
}
Gyroscope - Angles
void compute_gyro_angles() {
mpu6050_read_gyro(&gyro_rates);
rates.x = gyro_rates.x + GYRO_X_OFFSET;
gyro_last_update = micros();
}
Gyroscope - Angles
void compute_gyro_angles() {
mpu6050_read_gyro(&gyro_rates);
rates.x = gyro_rates.x + GYRO_X_OFFSET;
gyro_last_update = micros();
}
Gyroscope - Angles
http://www.freescale.com/files/sensors/doc/app_note/
AN3461.pdf
IMU - Accelerometer
(x, roll)
(y, pitch)
x = accel_filtered.x;
y = accel_filtered.y;
z = accel_filtered.z;
(median filters)
accel_angles.x = atan2(y, z) * RAD_TO_DEG;
accel_angles.y = atan2(-1 * x, sqrt(y*y + z*z)) * RAD_TO_DEG;
http://www.freescale.com/files/sensors/doc/app_note/
AN3461.pdf
IMU - Accelerometer
(x, roll)
(y, pitch)
x = accel_filtered.x;
y = accel_filtered.y;
z = accel_filtered.z;
http://www.freescale.com/files/sensors/doc/app_note/
AN3461.pdf
IMU - Accelerometer
IMU - Accelerometer
Susceptible to vibrations
Combining Approaches
Complementary Filter!
#define GYRO_PART 0.995
#define ACC_PART 0.005
Complementary Filter!
#define GYRO_PART 0.995
#define ACC_PART 0.005
Complementary Filter!
#define GYRO_PART 0.995
#define ACC_PART 0.005
Complementary Filter!
#define GYRO_PART 0.995
#define ACC_PART 0.005
void loop() {
while(!imu_read());
rc_read_values();
fc_process();
}
Remote Control
Mapped
Channel Function Min/Max
Min/Max
http://rcarduino.blogspot.com/2012/01/how-to-read-rc-
receiver-with.html
Control Loop
void loop() {
while(!imu_read());
rc_read_values();
fc_process();
}
Controlling Motors (ESCs)
3 problems to correct
Flight Controller Code
proportional = KP * error;
integral += KI * error * dt;
proportional = KP * error;
integral += KI * error * dt;
proportional = KP * error;
integral += KI * error * dt;
proportional = KP * error;
integral += KI * error * dt;
3 new PI controllers!
Ready to fly! (??)
Ready to fly! (??)
Tuning is hard!
Tuning
Safety & Handling Failure
Safety & Handling Failure
• Stale IMU values
• Be Safe
• Start small
(balancing robot?)
https://ghowen.me/build-your-own-quadcopter-autopilot/
Similar Projects:
https://github.com/cTn-dev/Phoenix-FlightController
https://github.com/baselsw/BlueCopter
My Code:
https://github.com/bolandrm/rmb_multicopter
https://github.com/bolandrm/arduino-quadcopter (old)
Thanks!
@bolandrm