FERSAT-ZAD6-Modes/main/pid_reg.cpp
float PID_Regulate(PID_Handle_t *hpid, float error) {
    float derivative;

    /* error := setpoint − measured_value */
    hpid->e0 = error;
    /* integral := integral + error * dt */
    hpid->integral = hpid->integral + hpid->e0 * hpid->Ts;
    /* derivative := (error − previous_error) / dt */
    derivative = (hpid->e0 - hpid->e1) / hpid->Ts;
    /* output := Kp × error + Ki * integral + Kd * derivative */
    hpid->u0 =  hpid->Kp * hpid->e0 + 
                hpid->Ki * hpid->integral + 
                hpid->Kd * derivative;
    /* previous_error := error */
    hpid->e1 = hpid->e0;

    return hpid->u0;    /* Return regulator output value */
}
/**
 * Function for the PID regulator output.
 * 
 * PID_Handle_t *hpid - PID regulator handle
 * float error - defined as Set_point_value minus Measured_value
 * 
 * return float - Output of the PID regulator
 * 
 * */
Function for the PID regulator output.

PID_Handle_t *hpid - PID regulator handle
float error - defined as Set_point_value minus Measured_value

return float - Output of the PID regulator
Function for the PID regulator output . PID_Handle_t * hpid - PID regulator handle float error - defined as Set_point_value minus Measured_value return float - Output of the PID regulator
float PID_Regulate(PID_Handle_t *hpid, float error) {
    float derivative;
    hpid->e0 = error;
    hpid->integral = hpid->integral + hpid->e0 * hpid->Ts;
    derivative = (hpid->e0 - hpid->e1) / hpid->Ts;
    hpid->u0 =  hpid->Kp * hpid->e0 + 
                hpid->Ki * hpid->integral + 
                hpid->Kd * derivative;
    hpid->e1 = hpid->e0;
    return hpid->u0;    
}
float PID_Regulate ( PID_Handle_t * hpid , float error ) { float derivative ; hpid -> e0 = error ; hpid -> integral = hpid -> integral + hpid -> e0 * hpid -> Ts ; derivative = ( hpid -> e0 - hpid -> e1 ) / hpid -> Ts ; hpid -> u0 = hpid -> Kp * hpid -> e0 + hpid -> Ki * hpid -> integral + hpid -> Kd * derivative ; hpid -> e1 = hpid -> e0 ; return hpid -> u0 ; }
Function for the PID regulator output.
Function for the PID regulator output .
/* error := setpoint − measured_value */ /* integral := integral + error * dt */ /* derivative := (error − previous_error) / dt */ /* output := Kp × error + Ki * integral + Kd * derivative */ /* previous_error := error */ /* Return regulator output value */