current_pid = calculatePID(measured_current);
if (current_pid>0)
{
}
else if (current_pid<0)
{
}
else if (current_pid==0)
{
}
The PID control:
#include <stdint.h>
// Variables del control PID
double kp = 1.0; // Ganancia proporcional
double ki = 0.5; // Ganancia integral
double kd = 0.2; // Ganancia derivada
double setPoint = 0; // Valor deseado
double error = 0.0;
double prevError = 0.0;
double integral = 0.0;
double derivative = 0.0;
double calculatePID(double inputValue) {
error = setPoint - inputValue;
double proportional = kp * error;
integral += ki * error;
derivative = kd * (error - prevError);
prevError = error;
double output = proportional + integral + derivative;
return output;
}