PID control of Quadcopter

PaulS: I don't think you do.

may be you are right. well I am still very much new to PID

PaulS: What input are you expecting the PID process to use? What goal is it trying to achieve? How are you planning to use the output value?

Input are Sensor values sensed by it. i.e roll and pitch in deg/sec. the goal is to balance the quad by PID control. output values are added or subtracted to throttle microseconds according to given formula:

front_left=(throttle+(rp_gain*roll)+(rp_gain*pitch)); // front left
front_right=(throttle-(rp_gain*roll)+(rp_gain*pitch));//front right
back_right=(throttle-(rp_gain*roll)-(rp_gain*pitch));//back right
back_left=(throttle+(rp_gain*roll)-(rp_gain*pitch));//back left

while rp_gain is just a float multiplied to increase the pitch and roll values as they are limit to low range (0-50us) after being processed by PID as their addition/subtraction will not cause significance change in speed of all motors if i use them as it is.

even if one of the motor is not working, my quad will balance itself without any difficulties.

Keep dreaming. That is not going to happen. It is possible with a hex or higher number but not a quad.

ahsanraza: Input are Sensor values sensed by it. i.e roll and pitch in deg/sec.

That might be your problem. The Setpoint and the Input must be in the same units. If your Input is degrees per second the Setpoint has to be in degrees per second. You can use a Setpoint of 0 to have the PID try to stop any spinning but you can't use it to make the quadcopter stay upright.

ahsanraza: even if one of the motor is not working, my quad will balance itself without any difficulties.

This will require ESC's that can run the propellers in reverse. For simplicity let's say you have a "+" configuration: one motor is Front, one is Back, one is Left, and one is Right. (This works exactly the same a an "X" configuration but rotated 45 degrees.) If the Right motor suddenly stops it's weight will cause the copter to roll to the right. The normal way to correct for a roll to the right is to increase speed on the Right motor and decrease speed on the Left motor. Since you have no Right motor you will have to cut the Left motor completely just to slow down the roll. To roll back to the Left you would have to run the Left motor BACKWARD to push the left motor down. You have now lost more than half your upward thrust so the Front and Back motors have to be capable of more than double the normal thrust.

Also note that you now have two motors running in one direction and only one motor running in the other direction. And one of the motors has just switched direction because it is running backward. I don't know if it is possible to stop yaw at the same time as stopping roll.

Good luck.

Oops!

johnwasser: That might be your problem. The Setpoint and the Input must be in the same units. If your Input is degrees per second the Setpoint has to be in degrees per second. You can use a Setpoint of 0 to have the PID try to stop any spinning but you can't use it to make the quadcopter stay upright.

well I am using desired picth and desired roll as set points. they are values received by receiver in us. You have suggested to make units same, I am using map function to make units almost same.

if(CH3_delta_rl>1470) { droll=map(CH3_delta_rl,1008,1968,-45,45); droll=constrain(droll,-45,45) }

is that okay?

UKHeliBob: Keep dreaming. That is not going to happen. It is possible with a hex or higher number but not a quad.

Ohh .. I thought it can be done by quad but may be I was wrong.

I thought it can be done by quad but may be I was wrong.

You are, unless as has been pointed out, the single motor on one diagonal axis can go into reverse or the pitch of the prop can go negative to produce the same effect. Now, there are such systems that even allow a quad to fly inverted, but I assume that we are not talking about such a model.

UKHeliBob:
but I assume that we are not talking about such a model.

You got that right. The post is about PID control. And I wonder how can I change my receiver units to deg / sec?