From cf7885c2a1a707f74959bbd120add5822c0031d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 17 Apr 2019 00:25:03 -0300 Subject: [PATCH 1/6] Fixing a minor error with some discrete-time systems --- control/timeresp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/control/timeresp.py b/control/timeresp.py index 059e42061..6e836ed97 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -482,6 +482,7 @@ def step_info(sys, T=None, SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1,0.9)) T = range(int(np.ceil(max(tvec)))) T, yout = step_response(sys, T) + yout = yout.flatten() # Steady state value InfValue = yout[-1] From 5538d96e8426a0415195d4dc835eb0889915aa65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 17 Apr 2019 00:26:54 -0300 Subject: [PATCH 2/6] Removing unneeded code. --- control/timeresp.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/control/timeresp.py b/control/timeresp.py index 6e836ed97..c62df9168 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -473,13 +473,6 @@ 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() From 712b16faa9ab1bc0f7995bf8bc6a9a19b6a0225b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 17 Apr 2019 01:00:48 -0300 Subject: [PATCH 3/6] Resolution added for discrete-time systems. --- control/timeresp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/timeresp.py b/control/timeresp.py index c62df9168..eb910a974 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -420,7 +420,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) From 90374b62030839a78561723017b0f67adbd5ff04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 17 Apr 2019 01:51:45 -0300 Subject: [PATCH 4/6] Fixing a possible mistake --- control/timeresp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/control/timeresp.py b/control/timeresp.py index eb910a974..c2b1909ec 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -490,8 +490,10 @@ def step_info(sys, T=None, SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1,0.9)) inf_margin = (1. - SettlingTimeThreshold) * InfValue # 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 From d5e7895e6b16ac1e3bb81f2677a2b0ff0a4b1771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 17 Apr 2019 01:53:02 -0300 Subject: [PATCH 5/6] Treating systems with negative step responses --- control/timeresp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/control/timeresp.py b/control/timeresp.py index c2b1909ec..9fca4d6a9 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -481,8 +481,12 @@ def step_info(sys, T=None, SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1,0.9)) 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 From e47ba8d1dacca5436b9c163d8d15faffced5922b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 17 Apr 2019 01:55:13 -0300 Subject: [PATCH 6/6] Treating systems with negative step responses --- control/timeresp.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/control/timeresp.py b/control/timeresp.py index 9fca4d6a9..af180f981 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -490,8 +490,9 @@ def step_info(sys, T=None, SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1,0.9)) 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): @@ -502,13 +503,13 @@ def step_info(sys, T=None, SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1,0.9)) # 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 = {