I need a PID Controller reversed

70 Views Asked by At

I need a pid controller that has to be larger at a lower setpoint than the input and then at a higher setpoint exactly the other way around

double pidEEVOverheating(double setpoint, double input)
{
  static double integral = 0.5;
  static double prev_error = 0.5;

  // Calculate the error
  double error = setpoint - input;

  // Calculate the integral term (accumulation of errors)
  integral += error;

  // Calculate the derivative term (rate of change of the error)
  double derivative = error - prev_error;
  prev_error = error;
  // Calculate the PID output
  double output = Kp * error + Ki * integral + Kd * derivative;

  test5 = output;


  // Limit the output to the allowed range (0 to 540)
  if (output < 0.0)
  {
    output = 0.0;
  }
  else if (output > 100.0)
  {
    output = 100.0;
  }

  return output;
}

Normal: If the setpoint is higher than the input, the output becomes larger What I need: If the setpoint is higher than the input, the output becomes lower

0

There are 0 best solutions below