Skip to content

Rework at step_info #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
35 changes: 18 additions & 17 deletions control/timeresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def step_response(sys, T=None, X0=0., input=None, output=None,
else:
# For discrete time, use integers
tvec = _default_response_times(sys.A, 100)
T = range(int(np.ceil(max(tvec))))
T = np.arange(tvec.max() / sys.dt) * sys.dt

U = np.ones_like(T)

Expand Down Expand Up @@ -509,42 +509,43 @@ def step_info(sys, T=None, SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1,0.9))
>>> info = step_info(sys, T)
'''
sys = _get_ss_simo(sys)
if T is None:
if isctime(sys):
T = _default_response_times(sys.A, 1000)
else:
# For discrete time, use integers
tvec = _default_response_times(sys.A, 1000)
T = range(int(np.ceil(max(tvec))))

T, yout = step_response(sys, T)
yout = yout.flatten()

# Steady state value
InfValue = yout[-1]

# RiseTime
tr_lower_index = (np.where(yout >= RiseTimeLimits[0] * InfValue)[0])[0]
tr_upper_index = (np.where(yout >= RiseTimeLimits[1] * InfValue)[0])[0]
if InfValue >= 0:
tr_lower_index = (np.where(yout >= RiseTimeLimits[0] * InfValue)[0])[0]
tr_upper_index = (np.where(yout >= RiseTimeLimits[1] * InfValue)[0])[0]
else:
tr_lower_index = (np.where(yout <= RiseTimeLimits[0] * InfValue)[0])[0]
tr_upper_index = (np.where(yout <= RiseTimeLimits[1] * InfValue)[0])[0]
RiseTime = T[tr_upper_index] - T[tr_lower_index]

# SettlingTime
sup_margin = (1. + SettlingTimeThreshold) * InfValue
inf_margin = (1. - SettlingTimeThreshold) * InfValue
sup_margin = (1. + SettlingTimeThreshold * np.sign(InfValue)) * InfValue
inf_margin = (1. - SettlingTimeThreshold * np.sign(InfValue)) * InfValue
SettlingTime = 0
# find Steady State looking for the first point out of specified limits
for i in reversed(range(T.size)):
if((yout[i] <= inf_margin) | (yout[i] >= sup_margin)):
SettlingTime = T[i + 1]
if (yout[i] <= inf_margin) | (yout[i] >= sup_margin):
if T.size > i + 1:
i = i + 1
SettlingTime = T[i]
break

# Peak
PeakIndex = np.abs(yout).argmax()
PeakValue = yout[PeakIndex]
PeakValue = np.abs(yout[PeakIndex])
PeakTime = T[PeakIndex]
SettlingMax = (yout).max()
SettlingMax = (yout[tr_upper_index:]).max()
SettlingMin = (yout[tr_upper_index:]).min()
# I'm really not very confident about UnderShoot:
UnderShoot = yout.min()
OverShoot = 100. * (yout.max() - InfValue) / (InfValue - yout[0])
OverShoot = 100. * (np.sign(InfValue) * PeakValue - InfValue) / (InfValue - yout[0])

# Return as a dictionary
S = {
Expand Down