3535 'sim_time' : 25.0 ,
3636}
3737SETTLING_TOLERANCE = 0.02
38+ MIN_SETTLING_TOLERANCE = 1e-3
39+ NUM_DOMINANT_POLES = 2
3840
3941
4042def create_governor_system (params ):
@@ -46,6 +48,12 @@ def create_governor_system(params):
4648 kt = params ['kt' ]
4749 inertia = params ['j' ]
4850 damping = params ['b' ]
51+ for name , value in (
52+ ('ti' , ti ), ('tg' , tg ), ('ts' , ts ), ('kt' , kt ), ('j' , inertia )):
53+ if value <= 0 :
54+ raise ValueError (f'{ name } must be positive' )
55+ if damping < 0 :
56+ raise ValueError ('b must be nonnegative' )
4957 ki = kp / ti
5058
5159 a_matrix = np .array ([
@@ -110,7 +118,9 @@ def summarize_response(system, time, outputs, target):
110118 final_speed = speed [- 1 ]
111119 peak_speed = np .max (speed )
112120 minimum_speed = np .min (speed )
113- tolerance = max (SETTLING_TOLERANCE * max (abs (target ), abs (final_speed )), 1e-3 )
121+ tolerance = max (
122+ SETTLING_TOLERANCE * max (abs (target ), abs (final_speed )),
123+ MIN_SETTLING_TOLERANCE )
114124 if abs (target ) < 1e-9 :
115125 overshoot = 0.0
116126 elif target > 0 :
@@ -120,7 +130,8 @@ def summarize_response(system, time, outputs, target):
120130 steady_state_error = target - final_speed
121131 poles = list (ct .poles (system ))
122132 # Use the least stable (rightmost) poles as the dominant dynamics.
123- dominant_poles = sorted (poles , key = lambda pole : pole .real )[- min (2 , len (poles )):]
133+ dominant_poles = sorted (
134+ poles , key = lambda pole : pole .real )[- min (NUM_DOMINANT_POLES , len (poles )):]
124135 damping_ratios = []
125136 for pole in dominant_poles :
126137 magnitude = abs (pole )
0 commit comments