# Quadrocopter PID

I am building a quadcopter for my school project. I am trying to program my own flight controller using PID algorithm.

I'll try to make my question simple using as an example below only two motors

                       1-----------2


Let's say I am trying to stabilize my two motor system using gyro from the diagram below to one above

                       1--
-----
----2


Using the formula Output = (gyro - 0) * Pgain

Do I need to increase the output only on the motor 2 or would I have to do both: increase the output on the 2nd motor while decreasing the output on the first motor? Thank you

## 2 Answers

Technically, you can do it either way, but consider the following scenario: You are flying with a heavy load, and there is a wind gust. Each rotor is operating at almost 100% capacity due to the heavy load. Now the wind gust has gotten you un-level. Say you need 20% of full speed to make the correction. What happens?

Well, if you are trying to control level only by increasing motor 2, then it's already essentially at full speed, so it cannot go any faster. The craft never levels because there is no "overhead" available - the actuator (fan) is operating at 100% so there is nothing left over for it to do when you ask for more.

If you try to control by splitting the 20% between motor 1 and motor 2, then motor 2 still can't do anything, but motor 1 can lower its speed by 10%. The vehicle will now level. Not as fast as if you weren't operating at near-capacity, again because the lack of overhead hinders performance, but it still responds.

This is typically how the quadrotor would be programmed. Each motor contributes to 1/4 of the thrust requested for altitude control, and then the attitude controller adds or removes from each motor in pairs.

So say you had motors:

AB

CD

If you wanted roll, you could speed up AC and slow down BD - this would cause roll with little change in altitude because A+B+C+D is still the same. Similarly, you could speed up AB and slow down CD to pitch. Again, A+B+C+D is the same. Finally, you can yaw by speeding up AD and slowing down BC.

When you split the power request from all positive on one motor (side) to half positive on one and half negative on another, you gain a lot of advantages when it comes to stability and control. I would point out that it is possible to roll, pitch, and yaw, simultaneously, and maintain altitude by doing this.

• Nice answer @Chuck. – SteveO Mar 22 '16 at 2:26

There's no need of different P gains in each rotor. Just calculate the needed gyro in each of them. Good luck.