28 def __init__(self, K_p, K_i, K_d, err_sat, eff_sat):
41 self.reference = reference
52 return self.summed_errors
57 error = self.reference - measure
58 cntrl_val = error * self.K_p
62 elif cntrl_val < -100:
75 error = self.reference - measure
77 self.summed_errors += error * (dt/1000000)
78 self.summed_errors = self.error_sat(self.summed_errors)
79 cntrl_val = ((error * self.K_p)+(self.summed_errors * self.K_i))
80 return self.effort_sat(cntrl_val)
85 if err >= self.err_sat:
87 elif err <= -self.err_sat:
95 if eff >= self.effort_saturation:
96 return self.effort_saturation
97 elif eff <= -self.effort_saturation:
98 return -self.effort_saturation
This file contains a class to create a PID Controller object.
__init__(self, K_p, K_i, K_d, err_sat, eff_sat)
effort_sat(self, eff)
effort_sat is a function which returns the saturated effort of the controller based on this instance ...
change_Ref(self, reference)
change_Ref changes the set point of the controller.
error_sat(self, err)
error_sat is a function which returns the saturated integral of the error based on this instance of t...
proportional_Control(self, measure)
proportional_Control returns a saturated effort value based on the error of the system from the set p...
pi_Control(self, measure, dt)
pi_Control returns a saturated effort value based on the error of the system from the set point using...
change_Gains(self, k_p, k_i, k_d)
change_Gains changes this instance's gain values.
get_Ref(self)
get_Ref returns the current set point of the controller.
get_Error(self)
get_Error returns the current Riemann Sum integral of the errors of the controller.