Arduino-PID-Library icon indicating copy to clipboard operation
Arduino-PID-Library copied to clipboard

Merged two "ifs" into one

Open madacol opened this issue 7 years ago • 0 comments

Merged this two ifs: if(!pOnE) outputSum-= kp * dInput;

if(pOnE) output = kp * error;
else output = 0;

into this one:

if(pOnE) output = kp * error;
else { outputSum -= kp * dInput; output = 0; }

I expect a performance improvement by the if reduction, or am I missing something?

I also separated the derivative computing from the ouputSum merging to add comments to indicate where each parameter is being computed.

Changed this:

      /*Compute Rest of PID Output*/
      output += outputSum - kd * dInput;

into this:

      /*Compute derivative*/
      output -= kd * dInput;
      /*Merge*/
      output += outputSum;

I believe it will compile the same, whether is separated or not. But if you don't like this part I'll remake the PR to remove this.

madacol avatar Oct 17 '18 05:10 madacol