Arduino-PID-Library
Arduino-PID-Library copied to clipboard
Add deadband
Create a dual-sided deadband around the desired setpoint to prevent noisy feedback from producing control jitters This is disabled by setting deadband to zero, something like:
if (Math.Abs(error) <= DEADBAND)
{
error = 0;
if (target == 0)
output = 0;
}
else
output = ((Kp * error) + (Ki * integral))/Ko;
could be inserted somewhere here
bool PID::Compute()
{
const bool outofDeadband = (error > deadband) || (error < -deadband);
if(!inAuto || !outDeadband) return false;
Other solutions are that you could filter the noise out of your sensor, tune your parameters to be less sensitive to noise, or you could even apply this procedure in user space before your compute step:
if (Math.Abs(SetPoint - Input) <= DEADBAND){
Input = Setpoint;
}
myPID.Compute();
... and then it wouldn't add the compute costs into the calculations for others.
I do think this filter would interfere with the ability of the integral term being able to adjust the process to within DEADBAND of the Setpoint.