PID compensator formula

Hi everyone,

somebody can help me? I want to modify in pid_v1 library the equation to the compensator formula, P+I*(1/s)+DNs/(s+N), just i don't now how to do it. so please, anyone. Thanks.

I just looked in the library source and didn't see that formula. Does it have something to do with calculating the PID output?

      /*Compute all the working error variables*/
      double input = *myInput;
      double error = *mySetpoint - input;


      ITerm += (ki * error);
      if(ITerm > outMax) ITerm= outMax;
      else if(ITerm < outMin) ITerm= outMin;


      double dInput = (input - lastInput);
 
      /*Compute PID Output*/
      double output = kp * error + ITerm - kd * dInput;

yes, it's calculating the PID output. And i want to change the original equation to that i'm post here (compensator formula), that formula has a filter (N), as you see. And it's in Laplace form, so i don't know, how to write in the library.

Why do you want to do that?

The correct way is to determine your poles and zeroes in the analog domain, pre-warp them,
then Z-transform to the discrete domain and realise as a digital filter. How much warping is
needed depends on where your poles and zeroes are w.r.t. sample frequency.

I think you are asking how to implement a laplace filter in the continuous time domain as a digital filter in the discrete time domain. You can do this by converting the laplace continuous frequency expression (independent variable s) to a discrete frequency expression (independent variable z). This can be done using the function c2d in Matlab or the function ToDiscreteTimeModel in Mathematica. From there, solving for the output of the filter in discrete time is trivial.

DigitalFilter.pdf (109 KB)

      /*Compute all the working error variables*/
      double input = *myInput;
      double error = *mySetpoint - input;


      ITerm += (ki * error);
      if(ITerm > outMax) ITerm= outMax;
      else if(ITerm < outMin) ITerm= outMin;


      double dInput = (input - lastInput);
 
      /*Compute PID Output*/
     double output = kp * error + ITerm - kd * dInput;

the last line here is the origonal library equation, the parallel form without filter (P+I*(1/s)+Ds),
and i want the equation with filter (parallel form with filter, P+I
(1/s)+DNs/(s+N)).
So i don't know how to add a filter to the equation in this code.