PID rules can be changed!

adelphysi:
i have been working on my cuad and i have always wondering why error = gyrovalue-setpoint

It is good that your quadcopter flies. Although, keep in mind that when you ask this particular question "why is error = gyrovalue-setpoint?", it immediately shows that you haven't properly studied enough automatic control text books. In unity gain negative feedback systems, the 'error' is difference between 'setpoint' and 'output', which means error = setpoint MINUS output. So, for a start, you should have written 'setpoint - gyrovalue'. Let's assume what you mean by 'gyrovalue'. I will assume it means a reading from the gyroscope that is measuring a CHANGE in angle over some given duration of time.

So....what you need to do is to show some kind of basic system diagram to convey to everybody here --- where you introduced your control signal? Show exactly where in the system diagram the input control signal is being fed (inserted). Don't get people to decipher your software code.....that's just time wasting. What you need to do is to show your method by means of some basic control system block diagram - which allows everyone to see where you apply your control input. And the diagram should show what signals are operated on (by your P and I and D components). Or, if the PID block operates on one particular (error) signal only....then just show it. The point is ..... show your method clearly ---- and clearly does not mean someone needs to decipher or reverse-engineer or read through your computer code. Your block diagram should also show what measurement devices are used (eg. gyro only, or gyro and accelerometer, etc.). An alternative to system diagram is to explain very concisely your processing method --- eg. setting the set point to zero, subtracting this zero setpoint with the output (eg. an angle for pitch, or roll etc), and adding a control input at (where-ever you add it), and proceed to explain where (and TO what) you apply your P plus I plus D. Right now, having incomplete code and unclear/incomplete pieces of information means unable to have some kind of logical discussion.

Happy and safe flying. All the best with your project.