PID rules can be changed!

adelphysi:
so i thought that why error = gyro value- setpoint value ??

Because, for a closed loop negative feedback system, the signal at the output of the differencer is called an 'error' signal of some sort. And that 'error' signal is the difference between set point and feedback value.

The software code is attempting to get "approximations" of the derivative of the error signal values and the integral of the error signal values. PID control involves these sorts of terms.

Also, your comment about "error = gyro value - setpoint value" is incorrect when it comes to discussions about conventional feedback system theory.

It's really the other way around.... ie. error = setpoint minus feedback value.
So..... error = setpoint - gyro value is what you should have written. Not gyro minus setpoint.

adelphysi:
I_controller += I_gain * error

The above could be wrong as well. The integral would be something like: existing accumulated error value PLUS (Kd times an approximate area under the error curve for some relatively small duration of time). So, a crude approximation could be something like:
new accumulated error = current accumulated error + Kd*(current error * T), with 'T' being a duration of time, such as sampling period.

adelphysi:
is what i did a method of PID i dont know?

It's probably a case of needing to basically understand what "PID" involves (to begin with), and understand basics of closed loop negative feedback systems and controllers.