Skip to content

Commit 92de12d

Browse files
authored
Merge pull request #555 from sawyerbfuller/fix-stepinfo
fixed bug in calculation of percent overshoot
2 parents 75dbe06 + b36d053 commit 92de12d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

control/tests/sisotool_test.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ def test_sisotool(self, sys):
6767
initial_point_2, 4)
6868

6969
# Check the step response before moving the point
70-
# new array needed because change in compute step response default time
7170
step_response_original = np.array(
72-
[0. , 0.0069, 0.0448, 0.124 , 0.2427, 0.3933, 0.5653, 0.7473,
73-
0.928 , 1.0969])
74-
#old: np.array([0., 0.0217, 0.1281, 0.3237, 0.5797, 0.8566, 1.116,
75-
# 1.3261, 1.4659, 1.526])
71+
[0. , 0.021 , 0.124 , 0.3146, 0.5653, 0.8385, 1.0969, 1.3095,
72+
1.4549, 1.5231])
7673
assert_array_almost_equal(
7774
ax_step.lines[0].get_data()[1][:10], step_response_original, 4)
7875

@@ -115,10 +112,9 @@ def test_sisotool(self, sys):
115112
bode_mag_moved, 4)
116113

117114
# Check if the step response has changed
118-
# new array needed because change in compute step response default time
119115
step_response_moved = np.array(
120-
[0., 0.0072, 0.0516, 0.1554, 0.3281, 0.5681, 0.8646, 1.1987,
121-
1.5452, 1.875])
116+
[0. , 0.023 , 0.1554, 0.4401, 0.8646, 1.3722, 1.875 , 2.2709,
117+
2.4633, 2.3827])
122118
assert_array_almost_equal(
123119
ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
124120

control/tests/timeresp_test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ def test_step_pole_cancellation(self, pole_cancellation,
310310
step_info_no_cancellation = step_info(no_pole_cancellation)
311311
step_info_cancellation = step_info(pole_cancellation)
312312
for key in step_info_no_cancellation:
313+
if key == 'Overshoot':
314+
# skip this test because these systems have no overshoot
315+
# => very sensitive to parameters
316+
continue
313317
np.testing.assert_allclose(step_info_no_cancellation[key],
314318
step_info_cancellation[key], rtol=1e-4)
315319

@@ -522,7 +526,7 @@ def test_step_robustness(self):
522526

523527
@pytest.mark.parametrize(
524528
"tfsys, tfinal",
525-
[(TransferFunction(1, [1, .5]), 9.21034), # pole at 0.5
529+
[(TransferFunction(1, [1, .5]), 13.81551), # pole at 0.5
526530
(TransferFunction(1, [1, .5]).sample(.1), 25), # discrete pole at 0.5
527531
(TransferFunction(1, [1, .5, 0]), 25)]) # poles at 0.5 and 0
528532
def test_auto_generated_time_vector_tfinal(self, tfsys, tfinal):

control/timeresp.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def step_info(sys, T=None, T_num=None, SettlingTimeThreshold=0.02,
792792
T, yout = step_response(sys, T)
793793

794794
# Steady state value
795-
InfValue = yout[-1]
795+
InfValue = sys.dcgain()
796796

797797
# RiseTime
798798
tr_lower_index = (np.where(yout >= RiseTimeLimits[0] * InfValue)[0])[0]
@@ -814,7 +814,7 @@ def step_info(sys, T=None, T_num=None, SettlingTimeThreshold=0.02,
814814
'SettlingTime': SettlingTime,
815815
'SettlingMin': yout[tr_upper_index:].min(),
816816
'SettlingMax': yout.max(),
817-
'Overshoot': 100. * (yout.max() - InfValue) / (InfValue - yout[0]),
817+
'Overshoot': 100. * (yout.max() - InfValue) / InfValue,
818818
'Undershoot': yout.min(), # not very confident about this
819819
'Peak': yout[PeakIndex],
820820
'PeakTime': T[PeakIndex],
@@ -1124,7 +1124,7 @@ def _ideal_tfinal_and_dt(sys, is_step=True):
11241124
default_dt = 0.1
11251125
total_cycles = 5 # number of cycles for oscillating modes
11261126
pts_per_cycle = 25 # Number of points divide a period of oscillation
1127-
log_decay_percent = np.log(100) # Factor of reduction for real pole decays
1127+
log_decay_percent = np.log(1000) # Factor of reduction for real pole decays
11281128

11291129
if sys._isstatic():
11301130
tfinal = default_tfinal

0 commit comments

Comments
 (0)