Chapter 4. Flight Controller

What Is a Flight Controller?

Basically, the flight controller is the brain of your drone. It measures the performance of your aircraft through an array of various sensors, hundreds of times per second, and then manages all the microadjustments that are needed on each motor to keep your aircraft stable in the air. Think of what happens when you walk down the street. You are not thinking about the variations needed in your gait due to an uneven sidewalk or headwind. You just walk, and your brain comes up with those details and executes them while your only thought is “forward.” The flight controller acts in the same manner. When you give your drone the command to move forward at 10 miles per hour, the flight controller is taking your overall command and breaking it down into hundreds of commands per second for each of the motors in order to achieve said command. If the drone encounters some type of resistance, such as a headwind, the flight controller will attempt to make up the difference needed to still achieve your command without extra input from the pilot.

Sensors

The heart of the flight controller is the inertial measurement unit (IMU); see Figure 4-1. This unit contains a suite of sensors to help the flight controller monitor the activity of the aircraft. The most typical sensors include an accelerometer, gyroscope, and barometer. These measure the acceleration and rate of rotation of the aircraft, and the air pressure (which can often be converted to the aircraft’s altitude). These three sensors provide all the data that the autopilot needs to keep the aircraft stable in the air.

Additional sensors are also used outside of the IMU for advanced functionality. These include GPS receivers, magnetometers, optical flow sensors, and air speed sensors. As time moves forward, we will see even more sensors introduced into flight controllers to help with tasks such as Sense and Avoid, computer vision, and artificial intelligence (AI).

Alt Text
Figure 4-1. This flight controller has a built-in IMU and ports for external sensors.
Here is an overview of the APM and all of the inputs/outputs (I/Os):
Inputs 1–8
These ports will be connected to our radio receiver. This collects our flight instructions from the ground and delivers them to the APM.
GPS
This port will be connected to our GPS sensor.
I2C (inter-integrated circuit, pronounced I-squared-C)
This is a standardized serial computer bus that is used for many types of peripherals. If you have used an Arduino before, you may be familiar with the I2C protocol. We will be using this port for our external compass.
PM
This is our power module port. This allows us to monitor our power supply.
JP1
This is a jumper port used to tell the APM if there should be a power module in use.
Outputs1–8
These will supply the signal we need for our electronic speed controllers. Alternatively, these could send a signal to a set of servos if you used APM for a model airplane or inputs to a gimbal controller if you asked APM to control a camera mount on your drone.
Telem
Our telemetry radio plugs in here.
A0–A11
Just as in an Arduino, these are our user assignable analog pins. These will not be used in this book.

Step-by-Step Build Instructions

For this portion of the build, you will need:

  • One inch of foam double-sided tape
  • Scissors
  • Fine-point paint pen or Sharpie
  • Small zip ties

Step 1: Mount the Flight Controller

The APM flight controller will be mounted on the bottom plate of the clean frame. Use two small pieces of double-sided tape at either end of the flight controller to attach it firmly to the frame (see Figures 4-3 and 4-4). Avoid using one large piece of tape, which can be difficult to remove later. The tape does have some vibration isolation qualities, so generally the thicker tape you can find, the better (up to a degree; there’s no need for 1/2-inch thick tape). Make sure that the forward arrow on the APM flight controller is pointing forward on the UAV, and that the flight controller is positioned directly in the center of the frame before pushing it into place (see Figure 4-5).

Figure 4-3. Cut off about an inch of double-sided tape to use in the mounting of the APM.
Figure 4-4. Cut your tape in half and place each portion at one end of the APM, then peel off the backing.
Figure 4-5. With the adhesive tape exposed, position the APM in the center—making sure it is pointing in the right direction—and firmly press into place.

Step 2: Wire up the Flight Controller Outputs

As we have discussed, the flight controller is nothing more than a microprocessor that takes an array of inputs, runs calculations on those inputs, and then sends out the appropriate signals to keep you airborne. At this point, the only things we have to wire up to the flight controller are our motors and ESCs (outputs). Take a look at the outputs labeled 1–8 on the APM. Notice that each output has three header pins that are vertically stacked under the number that labels it. Those three pins are for the signal, power, and ground found in each servo lead on your ESCs. They are even labeled on the right of the pins (S, +, -); look directly at them from the back of the unit.

Outputs 1 and 2 are for the NE and SW motors, respectively. Identify the speed controller that handles each motor, and plug the servo lead from that ESC into the appropriate output port. Make sure that all ground (black) wires are at the bottom of the servo lead when plugged in. Repeat this step, adding the NW motor to output 3, and SE motor to output 4. This is clearly illustrated in Figure 4-6.

Figure 4-6. Each motor has a dedicated output and rotation direction; the APM unit and the APM diagram are both pointing in the same forward direction.

To properly route these cables, take a small paint pen or Sharpie and label each ESC plug with its corresponding output number. Once they are clearly labeled, align the tips of all the plugs and place a small zip tie or two along the cable length just below the plugs. This will help keep everything neat and organized. Now push that group of cables through one of the four rectangular holes in the back of the clean frame (near the APM output pins). See Figure 4-7 for a detailed photo of this process.

Now, simply plug each of the ESC plugs in to the APM output that you labeled earlier. If you followed these steps correctly, you should have a nice neat connection between your APM and the aircraft’s ESCs, similar to Figure 4-8. Notice the attention we paid to keep the wiring as neat as possible. A clean build is easier to work on.

Figure 4-7. Our ESC leads route nicely from the dirty frame up through a hole in the back of the clean frame, giving them easy access to the output ports on the APM (note that the top clean frame plate was removed so we could get a better photo—it is not required to do this).
Figure 4-8. All of our ESCs are plugged in to the APM outputs (Note: the top clean frame plate was removed so we could get a better photo. It is not required to do this).

Step 3: Attach the Two Subframes to Each Other

Now that we have our ESCs wired into the APM, we can go ahead and attach the two subframes to each other. If you remember, we covered this step at the end of Chapter 2 while we were building out the frame. If you don’t recall this step, refer back to “Step 4: Attach the Two Subframes Together”. As a quick review, you are running four 5-mm mounting screws through the mounting tabs on the clean frame into the short standoffs located on the top of the dirty frame. Figure 4-9 may jog your memory.

Figure 4-9. Finally, we are ready to attach our two subframes to each other!

Wrapping Up

By now we have our flight controller firmly mounted to the clean frame, and have outputs going to the four motors. Double-check all connections and make sure that the appropriate wires are going into the appropriate ports. Double-checking now can save you headaches later.