Skip to content

Commit f964170

Browse files
committed
Solve issue #337, #565 and #564
1 parent 1263550 commit f964170

1 file changed

Lines changed: 56 additions & 23 deletions

File tree

control/timeresp.py

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -794,34 +794,67 @@ def step_info(sys, T=None, T_num=None, SettlingTimeThreshold=0.02,
794794
# Steady state value
795795
InfValue = sys.dcgain()
796796

797-
# RiseTime
798-
tr_lower_index = (np.where(yout >= RiseTimeLimits[0] * InfValue)[0])[0]
799-
tr_upper_index = (np.where(yout >= RiseTimeLimits[1] * InfValue)[0])[0]
800-
RiseTime = T[tr_upper_index] - T[tr_lower_index]
801-
802-
# SettlingTime
803-
sup_margin = (1. + SettlingTimeThreshold) * InfValue
804-
inf_margin = (1. - SettlingTimeThreshold) * InfValue
805-
# find Steady State looking for the first point out of specified limits
806-
for i in reversed(range(T.size)):
807-
if((yout[i] <= inf_margin) | (yout[i] >= sup_margin)):
808-
SettlingTime = T[i + 1]
809-
break
797+
# TODO: this could be a function step_info4data(t,y,yfinal)
798+
rise_time: float = np.NaN
799+
settling_time: float = np.NaN
800+
settling_min: float = np.NaN
801+
settling_max: float = np.NaN
802+
peak_value: float = np.Inf
803+
peak_time: float = np.Inf
804+
undershoot: float = np.NaN
805+
overshoot: float = np.NaN
806+
807+
if not np.isnan(InfValue) and not np.isinf(InfValue):
808+
# Peak
809+
peak_index = np.abs(yout).argmax()
810+
peak_value = np.abs(yout[peak_index])
811+
peak_time = T[peak_index]
812+
813+
sup_margin = (1. + SettlingTimeThreshold) * InfValue
814+
inf_margin = (1. - SettlingTimeThreshold) * InfValue
815+
816+
if InfValue < 0.0:
817+
# RiseTime
818+
tr_lower_index = (np.where(yout <= RiseTimeLimits[0] * InfValue)[0])[0]
819+
tr_upper_index = (np.where(yout <= RiseTimeLimits[1] * InfValue)[0])[0]
820+
# SettlingTime
821+
for i in reversed(range(T.size - 1)):
822+
if (-yout[i] <= np.abs(inf_margin)) | (-yout[i] >= np.abs(sup_margin)):
823+
settling_time = T[i + 1]
824+
break
825+
# Overshoot and Undershoot
826+
overshoot = np.abs(100. * ((-yout).max() - np.abs(InfValue)) / np.abs(InfValue))
827+
undershoot = np.abs(100. * (-yout).min() / np.abs(InfValue))
828+
else:
829+
tr_lower_index = (np.where(yout >= RiseTimeLimits[0] * InfValue)[0])[0]
830+
tr_upper_index = (np.where(yout >= RiseTimeLimits[1] * InfValue)[0])[0]
831+
# SettlingTime
832+
for i in reversed(range(T.size - 1)):
833+
if (yout[i] <= inf_margin) | (yout[i] >= sup_margin):
834+
settling_time = T[i + 1]
835+
break
836+
# Overshoot and Undershoot
837+
overshoot = np.abs(100. * (yout.max() - InfValue) / InfValue)
838+
undershoot = np.abs(100. * yout.min() / InfValue)
839+
840+
# RiseTime
841+
rise_time = T[tr_upper_index] - T[tr_lower_index]
842+
843+
settling_max = (yout[tr_upper_index:]).max()
844+
settling_min = (yout[tr_upper_index:]).min()
810845

811-
PeakIndex = np.abs(yout).argmax()
812846
return {
813-
'RiseTime': RiseTime,
814-
'SettlingTime': SettlingTime,
815-
'SettlingMin': yout[tr_upper_index:].min(),
816-
'SettlingMax': yout.max(),
817-
'Overshoot': 100. * (yout.max() - InfValue) / InfValue,
818-
'Undershoot': yout.min(), # not very confident about this
819-
'Peak': yout[PeakIndex],
820-
'PeakTime': T[PeakIndex],
847+
'RiseTime': rise_time,
848+
'SettlingTime': settling_time,
849+
'SettlingMin': settling_min,
850+
'SettlingMax': settling_max,
851+
'Overshoot': overshoot,
852+
'Undershoot': undershoot,
853+
'Peak': peak_value,
854+
'PeakTime': peak_time,
821855
'SteadyStateValue': InfValue
822856
}
823857

824-
825858
def initial_response(sys, T=None, X0=0., input=0, output=None, T_num=None,
826859
transpose=False, return_x=False, squeeze=None):
827860
# pylint: disable=W0622

0 commit comments

Comments
 (0)