PID negative output

Thread Starter

Zek_De

Joined Apr 26, 2017
3
Hi friends,
I have a problem with my quadcopter working ,my pid output is not giving a negative value and this is why if quadcopter bias negative side ,because of my PID didn't generate negative output ,other propeller doesn't have spin.

C codes

initial values
S->Kd=2.1F; S->Ki=0.4F; S->Kp=0.6F; S->derivative=0; S->error=0;
S->integral=0; S->previousError=0; S->samplingInterval=0.00125F;
S->integralLimitMax=100;
S->integralLimitMin=-100;
S->maxOut=1000;
S->minOut=-1000;

Function

S->error = target - current;

S->integral = (float)Constrain((S->integral + S->error*S->samplingInterval),
S->integralLimitMin,S->integralLimitMax);
S->derivative = (S->error - S->previousError) / S->samplingInterval;

S->previousError = S->error;

S->temp = S->Kp*S->error + S->Ki*S->integral + S->Kd*S->derivative;
//if(current < 0) S->temp = -S->temp;
S->temp1 = value + S->temp;

S->out = Constrain(S->temp1 ,S->minOut,S->maxOut);
return S->out;


Wikipedia code

previous_error = 0
integral = 0
loop:
error = setpoint - measured_value
integral = integral + error*dt
derivative = (error - previous_error)/dt
output = Kp*error + Ki*integral + Kd*derivative
previous_error = error
wait(dt)
goto loop
 
Top