As discussed in the previous guide, a multirotor flight controller is able to ascertain the position and orientation of the craft based on data from its onboard sensors. In order to make the multirotor change its position and/or orientation, the flight controller adjusts the rotational speed of the motors, which in turn adjusts the lift and torque produced by the motors. Doing this involves a lot of math.
In order to calculate the lift required by each motor correctly, a flight controller must know the exact position of each of the multirotor’s motors relative to itself. By knowing these positions, flight controllers can calculate the leverage each arm has over the orientation of the quadcopter. Using this information, the flight controller can calculate how to adjust the lift produced by each motor and move the craft.
Now, different flight control systems are programmed in different ways. This page covers how to program the HobbyKing KK2.1 flight controller with the locations of the motors since this is the flight controller used for the tutorials on this site.
Let’s start with the end goal in mind, although it might not make too much sense right now, it at least gives us a finish line for which to aim. Soon we will start doing a bunch of trigonometry, the ultimate goal of which will be go come up with the sine of the angles between the roll and pitch axes and the quadcopter’s four arms. These sine values are then numbers we put into the KK2.1 Mixer Editor which tells the flight controller the geometry of the quadcopter.
Measuring the Quadcopter
Since it would be quite difficult and unreliable to try to measure the arm angles directly on the quadcopter, so we will start by creating a diagram of the craft which will make taking measurements much, much easier and more accurate. First, we will need a nice big surface to write on. There are, of course, any number of surfaces you can use, so feel free to find the one that works best for you. Some people draw directly on their workbenches, others use large dry-erase boards, still others use plywood sheets; you can use any surface as long as it is easy to write on and it is larger than the quadcopter. I bought a roll of plain brown wrapping paper (which feels like the material paper grocery bags are made from) and then taped it down securely to a table.
Once you have your drawing area set up, use a straightedge to make one horizontal and one vertical tine in the middle of the area like crosshairs. These lines will be the x and y axes for our diagram.
Now place the quadcopter onto the drawing area so that the center of the flight control board is positioned at the intersection of our x- and y-axis lines. Note that the quadcopter frame itself will not necessarily be centered on the axes. The goal here is to find the angles from each motor to the center of the flight controller. We are not trying to find the angles of the arms with respect to the quadcopter body.
With the quadcopter positioned, put a dot directly underneath each motor. Then, remove the quadcopter from the drawing area. Using the straightedge again, draw a line from each of the motor dots to the origin of the axes. Now we know the positions of the motors relative to the center of the flight controller.
Using a protractor, measure the angles from each axis to the quadcopter lines in all four quadrants. This should yield a total of eight angles. Note that since the quadcopter is symmetrical, the angles you measured should be the same for the front two arms and the back to arms. If you get slightly different angles, just average the two values.
We are almost done. We just need to find the sine of each of the angles we just measured. So break out your favorite scientific calculator, or your phone, and find the sine of each of the angles. These sine values are are numbers we will input into the KK2.1 Mixer Editor.
Programming Your KK2.1 Flight Controller’s Mixer Editor
Let’s quickly recap the work we’ve done so far:
First we made a little empirical chart of our quadcopter. On a piece of paper we made two orthogonal axes kind of like x- and y-axis, but we call them the roll- and pitch- axes in the context of multirotors. We then marked the location of the KK2.1 and the locations of each of the four motors.
Second, on our chart we determined the angles between the pitch- and roll-axis and each of the quadcopter’s four arms.
Third, we calculated the sine of each of these angles.
Now we are on to the final step in the process of programming the KK2.1’s Mixer Editor; we just need to input the sine values we calculated. Let’s examine a quadcopter chart of the type described above so we can discuss the Mixer Editor programming in more concrete terms.
The picture looks a bit confusing but it isn’t. All I did was sketch out the quadcopter’s shape, measure the angles, and calculate the sine values.
The KK2.1 Mixer Editor has four channels, one for each motor (you can tell what page your are on by looking in the upper-right corner of the screen). We will input the Aileron and Elevator values for each channel. The Aileron value is the sine of the angle between the motor arm and the aileron (roll) axis. The Elevator value is the sine of the angle between the motor arm and the elevator (pitch) axis.
For each value, simply input the value into the KK2.1 by ignoring the decimal point in the front. The KK2.1 just assumes there is a decimal point in the front of your inputs since all of the sine values will be decimals.
The last bit of information you need is to know when the values you input are positive or negative. This is easy to figure out. The Aileron values are negative or motors on the left of the aileron axis, and positive for those on the right. The Elevator values are positive for motors above the elevator axis and negative for those below.
Let’s get back to our example. For motor 1, the aileron value is negative and the elevator value is positive:
- Aileron: -sin(48) = .74, so input 74 into the Mixer Editor
- Elevator: sin(34) = .56, so input 56 into the Mixer Editor
So in this example, we would input the following values into the Mixer Editor for each of the four motors in our example.
- Aileron: -83
- Elevator 56
- Aileron: 83
- Elevator: 56
- Aileron: 74
- Elevator: -67
- Aileron: -74
- Elevator: -67