#include "PIDAlgo.h" float PIDAlgorithmCalculation(float _setPoint,float _mesuredParam , PID_Config_Params *params, float *_pre_error, float *_integral) { float error; float derivative; float output; //Calculate P,I,D error = _setPoint - _mesuredParam; //In case of error too small then stop integration if(abs(error) > params->epsilon) { *_integral = *_integral + error*params->dt; } derivative = (error - *_pre_error)/params->dt; output = params->Kp*error + params->Ki**_integral + params->Kd*derivative; //Saturation Filter if(output > params->MAX) { output = params->MAX; } else if(output < params->MIN) { output = params->MIN; } //Update error *_pre_error = error; return output; }