Quadcopter Maths
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.
Motor 1
- Aileron: -83
- Elevator 56
Motor 2
- Aileron: 83
- Elevator: 56
Motor 3
- Aileron: 74
- Elevator: -67
Motor 4
- Aileron: -74
- Elevator: -67
please after finding the sine of the angle which gives decimal value, how do i enter it the mixer editor
Hi Falola Adekunle, thanks very much for pointing out that this tutorial was missing information on how to actually enter the sine values into the KK2.1 Mixer Editor. I added another section to this page that covers the procedure.
Basically, each motor will have two sine values, one for the angle from the Aileron axis and one for the angle from the Elevator axis. In the Mixer Editor these values are the Aileron and Elevator values respectively. For each motor, enter the sine values ignoring the decimal point. 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.
I hope you find this information helpful. Thanks very much for reading!
I am programming my less than a week old kk2.1 board (steveis) for my simplecopter (full size) from Matt Hall. This is a v-tail design and I have entered the v-tail config. I was wondering if you can see any problem with using your method (entering the sine of respective angles in the mixer editor) all as explained by your (very excellent and easy to understand) description under your dead cat quad posting when applied to a v-tail configuration. The web site for a simplecopter is found by googling it or goto utube and enter simplecopter for Matt’s videos. Thanks and by the way did I say your description of how to enter the sines in the mixer was as good as it can be. I still have to figure out the rudder setting on motors 3 & 4 but for the moment am going to try -100 on no. 4 and +100 on no 3 and see what happens. 0 on front motors 1&2 as they are not needed for yaw? My best guess anyway.
Good luck, Tom O’Farrell
Hi Tom O’Farrell, first of all thanks very much for reading. I have never tried building a v-tail quad, although I certainly plan to try eventually, but I’ve been doing some research into the steveis KK2.1 firmware for v-tail quads and I think the answer to your question is yes, you should be able to use the same approach for determining your Mixer Editor settings as described in this post. You are correct that you will also need to play around with the rudder settings since the rear motors on a v-tail quad obviously have more command over yaw than the front two. Unfortunately, I have yet to determine a good way of calculating the rudder settings other than setting some initial values, going for a test flight, and adjusting those values based on how your quad flies. Anyway, thanks again for reading, and I wish you the best of luck with your simplecopter.
Hi Toglefritz. I was interested in this write up, but I think something is wrong with your example here. This quad is not a symetrical X. However, motors 1 and 2 would be symetric (and should have the same angles about the X and Y axis), and motors 3 and 4 would be symetric (and also have the same angles about the X and Y axis). You appear to have the wrong values on your diagram for your angles, given this particular quadcopter. The angles for motors 1 and 2 should be 56degrees from the aileron and 34degrees from the elevator. In your diagram for motor 1 you have 48 and 34 shown, (=82) which does not add up to be 90degrees for that quadrant, and motors 3 and 4 should be 48degrees from the aileron and 42degrees from the elevator. You have number 3 motor shown as 56 and 42 (=98) again, not 90 degrees. Therefore your sin values are off for motors 1 and 3 and should be Motor 1 Aileron = -83, Elevator = 56, and Motor 3 Aileron = 74, Elevator = -67. Given this quad and your example, I believe this is correct.
Hi Monty, thank you very much for that excellent catch. It turns out the photo I took of the measurements I did for my actual quadcopter was accurate, but I messed up a bit when I translated the photograph into a diagram. You are absolutely right, the front two arms are symmetric about the Y axis, as are the back two arms. Therefore, as you pointed out, the angles between the front two arms and the Y-axis should be equal, and the angles between the back two arms and the Y-axis should be equal. Likewise, the angles between the front two arms and the X-axis should be equal, and the angles between the back two arms and the X-axis should also be equal. And, of course, the angles in each quadrant should sum to 90 degrees.
Thanks again for noticing that error. I’ve updated the diagram so it shows the correct angles. I also updated the corresponding sine values used for programming the KK2.1 flight controller.
Hi Scott, I figured it was something simple like that. Would you happen to know where to enter these values for the Naze32 FC? Thanks again for your excellent presentation.