From a95f75fc4c60f5c09c0727d094a1cede129c6dd3 Mon Sep 17 00:00:00 2001 From: jpp Date: Wed, 24 Mar 2021 14:01:23 -0300 Subject: [PATCH 1/5] Solved undershoot value calculus problem. Improper systems with negative respose, if do not have inverse respons, the undershoot must be 0. This ocurr in the MIMO system used in the step_info test. I think, the rise time and setting minimun and maximun computed by this funtion are right in. --- control/tests/timeresp_test.py | 4 ++-- control/timeresp.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/control/tests/timeresp_test.py b/control/tests/timeresp_test.py index a576d0903..424467e2e 100644 --- a/control/tests/timeresp_test.py +++ b/control/tests/timeresp_test.py @@ -301,10 +301,10 @@ def mimo_ss_step_matlab(self): 'SteadyStateValue': -0.5394}, {'RiseTime': 0.0000, # (*) 'SettlingTime': 3.4000, - 'SettlingMin': -0.1034, + 'SettlingMin': -0.4350,# -0.1935 in MATLAB. (is wrong) 'SettlingMax': -0.1485, 'Overshoot': 132.0170, - 'Undershoot': 79.222, # 0. in MATLAB + 'Undershoot': 0, # 0. in MATLAB (is correct) 'Peak': 0.4350, 'PeakTime': .2, 'SteadyStateValue': -0.1875}]] diff --git a/control/timeresp.py b/control/timeresp.py index eafe10992..2c39038f6 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -882,6 +882,7 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, # Steady state value InfValue = InfValues[i, j] + InfValue_sign = np.sign(InfValue) sgnInf = np.sign(InfValue.real) rise_time: float = np.NaN @@ -923,11 +924,11 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, else: overshoot = 0 - # Undershoot - y_us = (sgnInf * yout).min() - dy_us = np.abs(y_us) - if dy_us > 0: - undershoot = np.abs(100. * dy_us / InfValue) + # Undershoot + y_us = (InfValue_sign*yout).min() + y_us_index = (InfValue_sign*yout).argmin() + if (InfValue_sign * yout[y_us_index]) < 0: # must have oposite sign + undershoot = np.abs(100. * np.abs(y_us) / InfValue) else: undershoot = 0 From 95ca297192e4b89313600ee710c633be07595a7e Mon Sep 17 00:00:00 2001 From: Juan Pablo Pierini Date: Wed, 24 Mar 2021 20:20:51 -0300 Subject: [PATCH 2/5] Update timeresp.py --- control/timeresp.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/control/timeresp.py b/control/timeresp.py index 2c39038f6..382727d97 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -882,7 +882,6 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, # Steady state value InfValue = InfValues[i, j] - InfValue_sign = np.sign(InfValue) sgnInf = np.sign(InfValue.real) rise_time: float = np.NaN @@ -925,9 +924,9 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, overshoot = 0 # Undershoot - y_us = (InfValue_sign*yout).min() - y_us_index = (InfValue_sign*yout).argmin() - if (InfValue_sign * yout[y_us_index]) < 0: # must have oposite sign + y_us = (sgnInf*yout).min() + y_us_index = (sgnInf*yout).argmin() + if (sgnInf * yout[y_us_index]) < 0: # must have oposite sign undershoot = np.abs(100. * np.abs(y_us) / InfValue) else: undershoot = 0 From 1e3109fcf574fcf3ff5ecd0419d9eda02bef939d Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Thu, 25 Mar 2021 01:06:23 +0100 Subject: [PATCH 3/5] Style cleanup --- control/tests/timeresp_test.py | 4 ++-- control/timeresp.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/control/tests/timeresp_test.py b/control/tests/timeresp_test.py index 424467e2e..410765c90 100644 --- a/control/tests/timeresp_test.py +++ b/control/tests/timeresp_test.py @@ -301,10 +301,10 @@ def mimo_ss_step_matlab(self): 'SteadyStateValue': -0.5394}, {'RiseTime': 0.0000, # (*) 'SettlingTime': 3.4000, - 'SettlingMin': -0.4350,# -0.1935 in MATLAB. (is wrong) + 'SettlingMin': -0.4350, # (*) 'SettlingMax': -0.1485, 'Overshoot': 132.0170, - 'Undershoot': 0, # 0. in MATLAB (is correct) + 'Undershoot': 0, 'Peak': 0.4350, 'PeakTime': .2, 'SteadyStateValue': -0.1875}]] diff --git a/control/timeresp.py b/control/timeresp.py index 382727d97..ea1ee2a12 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -926,7 +926,7 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, # Undershoot y_us = (sgnInf*yout).min() y_us_index = (sgnInf*yout).argmin() - if (sgnInf * yout[y_us_index]) < 0: # must have oposite sign + if (sgnInf * yout[y_us_index]) < 0: # InfValue and undershoot must have opposite sign undershoot = np.abs(100. * np.abs(y_us) / InfValue) else: undershoot = 0 From 11d89b36c6e51e89f078b7a4fcf4ac64b00ea8d5 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Thu, 25 Mar 2021 01:11:04 +0100 Subject: [PATCH 4/5] Update comment for MATLAB reference --- control/tests/timeresp_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/control/tests/timeresp_test.py b/control/tests/timeresp_test.py index 410765c90..54b9bc95b 100644 --- a/control/tests/timeresp_test.py +++ b/control/tests/timeresp_test.py @@ -304,14 +304,14 @@ def mimo_ss_step_matlab(self): 'SettlingMin': -0.4350, # (*) 'SettlingMax': -0.1485, 'Overshoot': 132.0170, - 'Undershoot': 0, + 'Undershoot': 0., 'Peak': 0.4350, 'PeakTime': .2, 'SteadyStateValue': -0.1875}]] - # (*): MATLAB gives 0.4 here, but it is unclear what - # 10% and 90% of the steady state response mean, when - # the step for this channel does not start a 0 for - # 0 initial conditions + # (*): MATLAB gives 0.4 for RiseTime and -0.1034 for + # SettlingMin, but it is unclear what 10% and 90% of + # the steady state response mean, when the step for + # this channel does not start a 0. return T @pytest.fixture From 14a92febc2366036064c018ad6d4360e7e733cc5 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Thu, 25 Mar 2021 01:25:16 +0100 Subject: [PATCH 5/5] simplify undershoot calculation --- control/timeresp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/control/timeresp.py b/control/timeresp.py index ea1ee2a12..f0c130eb0 100644 --- a/control/timeresp.py +++ b/control/timeresp.py @@ -923,11 +923,11 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, else: overshoot = 0 - # Undershoot - y_us = (sgnInf*yout).min() - y_us_index = (sgnInf*yout).argmin() - if (sgnInf * yout[y_us_index]) < 0: # InfValue and undershoot must have opposite sign - undershoot = np.abs(100. * np.abs(y_us) / InfValue) + # Undershoot : InfValue and undershoot must have opposite sign + y_us_index = (sgnInf * yout).argmin() + y_us = yout[y_us_index] + if (sgnInf * y_us) < 0: + undershoot = (-100. * y_us / InfValue) else: undershoot = 0