@@ -19,46 +19,68 @@ def __init__(
19
19
disturbance : float ,
20
20
acceleration : float ,
21
21
target : float = 0.0 ,
22
- ):
22
+ ) -> None :
23
23
"""
24
24
Initialize the ADRC controller.
25
25
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)
30
35
"""
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
35
40
36
41
self .system_output = 0.0 # Estimated system output
37
42
self .system_velocity = 0.0 # Estimated system velocity
38
43
self .total_disturbance = 0.0 # Estimated total disturbance
39
44
40
- def compute (self , measured_value : float , dt : float ) -> float :
45
+ def calculate_control_output (self , measured_value : float , dt : float ) -> float :
41
46
"""
42
47
Compute the control signal based on error estimation and disturbance rejection.
43
48
44
49
:param measured_value: The current process variable
45
50
:param dt: Time difference since the last update
46
51
: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
47
57
"""
48
-
49
58
# 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
53
65
54
66
# 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.
56
73
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
62
84
63
85
64
86
if __name__ == "__main__" :
0 commit comments