Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb82883

Browse files
murrayrmslivingston
authored andcommitted
fix step_info settling time calculation for constant signals
1 parent6406868 commitbb82883

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

‎control/tests/timeresp_test.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""timeresp_test.py - test time response functions"""
22

33
fromcopyimportcopy
4+
frommathimportisclose
45

56
importnumpyasnp
67
importpytest
78
importscipyassp
89

910
importcontrolasct
1011
fromcontrolimportStateSpace,TransferFunction,c2d,isctime,ss2tf,tf2ss
11-
fromcontrol.exceptionimportslycot_check,pandas_check
12+
fromcontrol.exceptionimportpandas_check,slycot_check
1213
fromcontrol.tests.conftestimportslycotonly
13-
fromcontrol.timerespimport(_default_time_vector,_ideal_tfinal_and_dt,
14-
forced_response,impulse_response,
15-
initial_response,step_info,step_response)
14+
fromcontrol.timerespimport_default_time_vector,_ideal_tfinal_and_dt, \
15+
forced_response,impulse_response,initial_response,step_info, \
16+
step_response
1617

1718

1819
classTSys:
@@ -1275,3 +1276,45 @@ def test_no_pandas():
12751276
# Convert to pandas
12761277
withpytest.raises(ImportError,match="pandas"):
12771278
df=resp.to_pandas()
1279+
1280+
1281+
# https://github.com/python-control/python-control/issues/1014
1282+
deftest_step_info_nonstep():
1283+
# Pass a constant input
1284+
timepts=np.linspace(0,10,endpoint=False)
1285+
y_const=np.ones_like(timepts)
1286+
1287+
# Constant value of 1
1288+
step_info=ct.step_info(y_const,timepts)
1289+
assertstep_info['RiseTime']==0
1290+
assertstep_info['SettlingTime']==0
1291+
assertstep_info['SettlingMin']==1
1292+
assertstep_info['SettlingMax']==1
1293+
assertstep_info['Overshoot']==0
1294+
assertstep_info['Undershoot']==0
1295+
assertstep_info['Peak']==1
1296+
assertstep_info['PeakTime']==0
1297+
assertstep_info['SteadyStateValue']==1
1298+
1299+
# Constant value of -1
1300+
step_info=ct.step_info(-y_const,timepts)
1301+
assertstep_info['RiseTime']==0
1302+
assertstep_info['SettlingTime']==0
1303+
assertstep_info['SettlingMin']==-1
1304+
assertstep_info['SettlingMax']==-1
1305+
assertstep_info['Overshoot']==0
1306+
assertstep_info['Undershoot']==0
1307+
assertstep_info['Peak']==1
1308+
assertstep_info['PeakTime']==0
1309+
assertstep_info['SteadyStateValue']==-1
1310+
1311+
# Ramp from -1 to 1
1312+
step_info=ct.step_info(-1+2*timepts/10,timepts)
1313+
assertstep_info['RiseTime']==3.8
1314+
assertstep_info['SettlingTime']==9.8
1315+
assertisclose(step_info['SettlingMin'],0.88)
1316+
assertisclose(step_info['SettlingMax'],0.96)
1317+
assertstep_info['Overshoot']==0
1318+
assertstep_info['Peak']==1
1319+
assertstep_info['PeakTime']==0
1320+
assertisclose(step_info['SteadyStateValue'],0.96)

‎control/timeresp.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,17 +1674,19 @@ def step_info(sysdata, T=None, T_num=None, yfinal=None, params=None,
16741674

16751675
ifnotnp.isnan(InfValue)andnotnp.isinf(InfValue):
16761676
# RiseTime
1677-
tr_lower_index=np.where(
1677+
tr_lower_index=np.nonzero(
16781678
sgnInf* (yout-RiseTimeLimits[0]*InfValue)>=0
16791679
)[0][0]
1680-
tr_upper_index=np.where(
1680+
tr_upper_index=np.nonzero(
16811681
sgnInf* (yout-RiseTimeLimits[1]*InfValue)>=0
16821682
)[0][0]
16831683
rise_time=T[tr_upper_index]-T[tr_lower_index]
16841684

16851685
# SettlingTime
1686-
settled=np.where(
1687-
np.abs(yout/InfValue-1)>=SettlingTimeThreshold)[0][-1]+1
1686+
outside_threshold=np.nonzero(
1687+
np.abs(yout/InfValue-1)>=SettlingTimeThreshold)[0]
1688+
settled=0ifoutside_threshold.size==0 \
1689+
elseoutside_threshold[-1]+1
16881690
# MIMO systems can have unsettled channels without infinite
16891691
# InfValue
16901692
ifsettled<len(T):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp