Quadcopter Software Design
Before I begin discussing the quadcopter design, here is a diagram that shows the high-level software structure for my design:
All future software design posts will reference to this diagram. Here is a short explanation of the necessity and function of each block:
PWM Decoder Driver:
In order to interpret flight commands from a standard RC Transmitter/Receiver, any multi-rotor design must have some sort of PWM decoder. My decoder will be expecting a single signal containing all PWM channels (details here). The decoder driver will translate the several channels of pulse widths into values to be interpreted by the command translator.
Depending on the flight mode, the PWM values given by the transmitter are interpreted differently. The command translator determines which mode the user is flying in and translates the commands accordingly.
The inertial sensors I’ve chosen to use all run on the I2C protocol. This high-speed protocol will be a great interface to use because of its addressing scheme and its interrupt time efficiency. The I2C protocol is more complicated that most serial protocols but the LPC1768 has built-in hardware to handle the physical layer. The I2C interrupt scheme for this hardware is very efficient with each interrupt needing only a few lines of code.
As mentioned in an earlier post, I will be implementing several sensor fusion algorithms to find out which has the best performance. The first one I will implement is the Extended Kalman Filter (EKF). The EKF algorithm is widely known to be one of the best methods for state (in my case aircraft attitude) estimation. This filter will take the sensor readings from the various sensors and output an estimation of the current aircraft attitude. For my initial design it will be important to measure:
- Roll – Side to side angle relative to the horizon
- Pitch – Front to back angle relative to the horizon
- Roll Rate – Side to side rotational rate relative to the horizon
- Pitch Rate – Front to back rotational rate relative to the horizon
- Yaw Rate – Horizontal rotational rate relative to magnetic heading
- Magnetic Heading – Direction relative to magnetic north
Proportional-Integral-Derivative (PID) Stabilization:
Once the desired aircraft attitude is determined from the transmitter commands and the actual aircraft attitude is determined from the sensor fusion algorithm, PID controllers are used to determine the fastest way to make the desired attitude become the actual attitude. PID controllers are very efficient for control of a system in which an accurate physical model is unknown. Using calculus to determine error slopes and areas, PID controllers compensate for environmental noise and disturbances while overcoming steady state error and oscillations. PID controllers are VERY simple to design and code but are VERY hard to tune and calibrate. (see this post)
Multi-Rotor Throttle Mixing (MRTM):
Standard helicopters use Cyclic Collective Pitch Mixing (CCPM) to adjust the aircraft attitude. It works by adjusting the pitch of the blades depending on their current angular position. I came up with term MRTM, as I haven’t found a term defined for multi-rotor helicopters. MRTM works by adjusting the speed of several propellers in such a way that results in the same aircraft control and a typical helicopter (a post will soon follow that explains this in detail). MRTM can be used to control the attitude of many styles of multi-rotor helicopters.
PWM Encoder Driver:
Once everything has been computed, the PWM Encoder takes the control values and generates a pulse width modulated (PWM) output for each motor. This is the exact opposite process of the PWM Decoder. The LPC1768 has good support for PWM output. I’ll be able to output all channels of PWM without using any interrupts or processing time. Can’t beat that!