Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions control/tests/timeresp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,3 +1483,22 @@ def test_timeresp_aliases():

with pytest.raises(TypeError, match="unrecognized keyword"):
ct.step_info(sys, timepts, unknown=True)


def test_step_info_rise_not_reached():
# Response that never reaches 90% of the final value: the rise time
# (and settling min/max) are undefined, but step_info should not fail
timepts = np.linspace(0, 1, 101)
yout = 1 - np.exp(-timepts)
step_info = ct.step_info(yout, timepts, yfinal=1)
assert np.isnan(step_info['RiseTime'])
assert np.isnan(step_info['SettlingMin'])
assert np.isnan(step_info['SettlingMax'])
assert np.isnan(step_info['SettlingTime'])
assert step_info['SteadyStateValue'] == 1

# Large feedthrough: default time vector ends before 90% is reached
sys = ct.tf([2.99, -0.0685], [1, 2.83])
step_info = ct.step_info(sys)
assert isclose(step_info['SteadyStateValue'], sys.dcgain())
assert step_info['Peak'] == pytest.approx(2.99)
24 changes: 14 additions & 10 deletions control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,14 +1698,15 @@ def step_info(
steady_state_value: complex = np.nan

if not np.isnan(InfValue) and not np.isinf(InfValue):
# RiseTime
tr_lower_index = np.nonzero(
sgnInf * (yout - RiseTimeLimits[0] * InfValue) >= 0
)[0][0]
tr_upper_index = np.nonzero(
sgnInf * (yout - RiseTimeLimits[1] * InfValue) >= 0
)[0][0]
rise_time = T[tr_upper_index] - T[tr_lower_index]
# RiseTime (undefined if the response never gets there,
# e.g. if the time vector is too short)
tr_lower = np.nonzero(
sgnInf * (yout - RiseTimeLimits[0] * InfValue) >= 0)[0]
tr_upper = np.nonzero(
sgnInf * (yout - RiseTimeLimits[1] * InfValue) >= 0)[0]
if tr_lower.size and tr_upper.size:
tr_upper_index = tr_upper[0]
rise_time = T[tr_upper_index] - T[tr_lower[0]]

# SettlingTime
outside_threshold = np.nonzero(
Expand All @@ -1717,8 +1718,11 @@ def step_info(
if settled < len(T):
settling_time = T[settled]

settling_min = min((yout[tr_upper_index:]).min(), InfValue)
settling_max = max((yout[tr_upper_index:]).max(), InfValue)
if tr_lower.size and tr_upper.size:
settling_min = min(
(yout[tr_upper_index:]).min(), InfValue)
settling_max = max(
(yout[tr_upper_index:]).max(), InfValue)

# Overshoot
y_os = (sgnInf * yout).max()
Expand Down