@@ -19,46 +19,68 @@ def __init__(
1919 disturbance : float ,
2020 acceleration : float ,
2121 target : float = 0.0 ,
22- ):
22+ ) -> None :
2323 """
2424 Initialize the ADRC controller.
2525
26- :param beta1: Gain for error correction in ESO
27- :param beta2: Gain for disturbance estimation in ESO
28- :param beta3: Gain for acceleration estimation in ESO
29- :param setpoint: Desired target value
26+ :param error_correction: Gain for error correction in ESO
27+ :param disturbance: Gain for disturbance estimation in ESO
28+ :param acceleration: Gain for acceleration estimation in ESO
29+ :param target: Desired target value (default: 0.0)
30+ >>> adrc = ADRC(1.0, 2.0, 3.0, 5.0)
31+ >>> adrc.error_correction, adrc.disturbance, adrc.acceleration, adrc.target
32+ (1.0, 2.0, 3.0, 5.0)
33+ >>> adrc.system_output, adrc.system_velocity, adrc.total_disturbance
34+ (0.0, 0.0, 0.0)
3035 """
31- self .beta1 = beta1
32- self .beta2 = beta2
33- self .beta3 = beta3
34- self .setpoint = setpoint
36+ self .error_correction = error_correction
37+ self .disturbance = disturbance
38+ self .acceleration = acceleration
39+ self .target = target
3540
3641 self .system_output = 0.0 # Estimated system output
3742 self .system_velocity = 0.0 # Estimated system velocity
3843 self .total_disturbance = 0.0 # Estimated total disturbance
3944
40- def compute (self , measured_value : float , dt : float ) -> float :
45+ def calculate_control_output (self , measured_value : float , dt : float ) -> float :
4146 """
4247 Compute the control signal based on error estimation and disturbance rejection.
4348
4449 :param measured_value: The current process variable
4550 :param dt: Time difference since the last update
4651 :return: Control output
52+ >>> adrc = ADRC(10.0, 5.0, 2.0)
53+ >>> (adrc.system_output, adrc.system_velocity,
54+ ... adrc.total_disturbance) = (1.0, 2.0, 3.0)
55+ >>> adrc.calculate_control_output(0.5, 0.1) # Simple test with dt=0.1
56+ 0.8
4757 """
48-
4958 # Extended State Observer (ESO) Update
50- self .z1 += dt * (self .z2 - self .beta1 * (self .z1 - measured_value ))
51- self .z2 += dt * (self .z3 - self .beta2 * (self .z1 - measured_value ))
52- self .z3 -= self .beta3 * (self .z1 - measured_value )
59+ error = self .system_output - measured_value
60+ self .system_output += dt * (
61+ self .system_velocity - self .error_correction * error
62+ )
63+ self .system_velocity += dt * (self .total_disturbance - self .disturbance * error )
64+ self .total_disturbance -= self .acceleration * error
5365
5466 # Control Law (Nonlinear State Error Feedback - NLSEF)
55- return self .z2 - self .z3
67+ control_output = self .system_velocity - self .total_disturbance
68+ return control_output
69+
70+ def reset (self ) -> None :
71+ """
72+ Reset the estimated states to zero.
5673
57- def reset (self ):
58- """Reset the estimated states."""
59- self .z1 = 0.0
60- self .z2 = 0.0
61- self .z3 = 0.0
74+ >>> adrc = ADRC(1.0, 2.0, 3.0)
75+ >>> (adrc.system_output, adrc.system_velocity,
76+ ... adrc.total_disturbance) = (1.1, 2.2, 3.3)
77+ >>> adrc.reset()
78+ >>> adrc.system_output, adrc.system_velocity, adrc.total_disturbance
79+ (0.0, 0.0, 0.0)
80+ """
81+ self .system_output = 0.0
82+ self .system_velocity = 0.0
83+ self .total_disturbance = 0.0
6284
6385
6486if __name__ == "__main__" :
0 commit comments