Skip to content

Commit 6587f69

Browse files
committed
add yfinal parameter to step_info
1 parent 43d73f0 commit 6587f69

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

control/tests/timeresp_test.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,15 @@ def assert_step_info_match(self, sys, info, info_ref):
451451
# local min/max peak well after signal has risen
452452
np.testing.assert_allclose(info[k], info_ref[k], rtol=1e-3)
453453

454+
@pytest.mark.parametrize(
455+
"yfinal", [True, False], ids=["yfinal", "no yfinal"])
456+
@pytest.mark.parametrize(
457+
"systype, time_2d",
458+
[("ltisys", False),
459+
("time response", False),
460+
("time response", True),
461+
],
462+
ids=["ltisys", "time response (n,)", "time response (1,n)"])
454463
@pytest.mark.parametrize(
455464
"tsystem",
456465
["siso_tf_step_matlab",
@@ -459,16 +468,10 @@ def assert_step_info_match(self, sys, info, info_ref):
459468
"siso_tf_kneg",
460469
"siso_tf_type1"],
461470
indirect=["tsystem"])
462-
@pytest.mark.parametrize(
463-
"systype, time_2d",
464-
[("lti", False),
465-
("time response data", False),
466-
("time response data", True),
467-
])
468-
def test_step_info(self, tsystem, systype, time_2d):
471+
def test_step_info(self, tsystem, systype, time_2d, yfinal):
469472
"""Test step info for SISO systems."""
470473
step_info_kwargs = tsystem.kwargs.get('step_info', {})
471-
if systype == "time response data":
474+
if systype == "time response":
472475
# simulate long enough for steady state value
473476
tfinal = 3 * tsystem.step_info['SettlingTime']
474477
if np.isnan(tfinal):
@@ -478,29 +481,37 @@ def test_step_info(self, tsystem, systype, time_2d):
478481
step_info_kwargs['T'] = t[np.newaxis, :] if time_2d else t
479482
else:
480483
sysdata = tsystem.sys
484+
if yfinal:
485+
step_info_kwargs['yfinal'] = tsystem.step_info['SteadyStateValue']
481486

482487
info = step_info(sysdata, **step_info_kwargs)
483488

484489
self.assert_step_info_match(tsystem.sys, info, tsystem.step_info)
485490

491+
@pytest.mark.parametrize(
492+
"yfinal", [True, False], ids=["yfinal", "no_yfinal"])
493+
@pytest.mark.parametrize(
494+
"systype", ["ltisys", "time response"])
486495
@pytest.mark.parametrize(
487496
"tsystem",
488497
['mimo_ss_step_matlab',
489498
pytest.param('mimo_tf_step', marks=slycotonly)],
490499
indirect=["tsystem"])
491-
@pytest.mark.parametrize(
492-
"systype", ["lti", "time response data"])
493-
def test_step_info_mimo(self, tsystem, systype):
500+
def test_step_info_mimo(self, tsystem, systype, yfinal):
494501
"""Test step info for MIMO systems."""
495502
step_info_kwargs = tsystem.kwargs.get('step_info', {})
496-
if systype == "time response data":
503+
if systype == "time response":
497504
tfinal = 3 * max([S['SettlingTime']
498505
for Srow in tsystem.step_info for S in Srow])
499506
t, y = step_response(tsystem.sys, T=tfinal, T_num=5000)
500507
sysdata = y
501508
step_info_kwargs['T'] = t
502509
else:
503510
sysdata = tsystem.sys
511+
if yfinal:
512+
step_info_kwargs['yfinal'] = [[S['SteadyStateValue']
513+
for S in Srow]
514+
for Srow in tsystem.step_info]
504515

505516
info_dict = step_info(sysdata, **step_info_kwargs)
506517

control/timeresp.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ def step_response(sys, T=None, X0=0., input=None, output=None, T_num=None,
734734
squeeze=squeeze, input=input, output=output)
735735

736736

737-
def step_info(sysdata, T=None, T_num=None, SettlingTimeThreshold=0.02,
738-
RiseTimeLimits=(0.1, 0.9)):
737+
def step_info(sysdata, T=None, T_num=None, yfinal=None,
738+
SettlingTimeThreshold=0.02, RiseTimeLimits=(0.1, 0.9)):
739739
"""
740740
Step response characteristics (Rise time, Settling Time, Peak and others).
741741
@@ -752,6 +752,11 @@ def step_info(sysdata, T=None, T_num=None, SettlingTimeThreshold=0.02,
752752
Number of time steps to use in simulation if T is not provided as an
753753
array; autocomputed if not given; ignored if sysdata is a
754754
discrete-time system or a time series or response data.
755+
yfinal: scalar or array_like, optional
756+
Steady-state response. If not given, sysdata.dcgain() is used for
757+
systems to simulate and the last value of the the response data is
758+
used for a given time series of response data. Scalar for SISO,
759+
(noutputs, ninputs) array_like for MIMO systems.
755760
SettlingTimeThreshold : float value, optional
756761
Defines the error to compute settling time (default = 0.02)
757762
RiseTimeLimits : tuple (lower_threshold, upper_theshold)
@@ -838,7 +843,10 @@ def step_info(sysdata, T=None, T_num=None, SettlingTimeThreshold=0.02,
838843
if T is None or np.asarray(T).size == 1:
839844
T = _default_time_vector(sysdata, N=T_num, tfinal=T, is_step=True)
840845
T, Yout = step_response(sysdata, T, squeeze=False)
841-
InfValues = np.atleast_2d(sysdata.dcgain())
846+
if yfinal:
847+
InfValues = np.atleast_2d(yfinal)
848+
else:
849+
InfValues = np.atleast_2d(sysdata.dcgain())
842850
retsiso = sysdata.issiso()
843851
noutputs = sysdata.noutputs
844852
ninputs = sysdata.ninputs
@@ -864,7 +872,7 @@ def step_info(sysdata, T=None, T_num=None, SettlingTimeThreshold=0.02,
864872
T = np.squeeze(T)
865873
noutputs = Yout.shape[0]
866874
ninputs = Yout.shape[1]
867-
InfValues = Yout[:, :, -1]
875+
InfValues = np.atleast_2d(yfinal) if yfinal else Yout[:, :, -1]
868876

869877
ret = []
870878
for i in range(noutputs):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy