|
1 | 1 | """timeresp_test.py - test time response functions"""
|
2 | 2 |
|
3 | 3 | from copy import copy
|
| 4 | +from math import isclose |
4 | 5 |
|
5 | 6 | import numpy as np
|
6 | 7 | import pytest
|
7 | 8 | import scipy as sp
|
8 | 9 |
|
9 | 10 | import control as ct
|
10 | 11 | from control import StateSpace, TransferFunction, c2d, isctime, ss2tf, tf2ss
|
11 |
| -from control.exception import slycot_check, pandas_check |
| 12 | +from control.exception import pandas_check, slycot_check |
12 | 13 | from control.tests.conftest import slycotonly
|
13 |
| -from control.timeresp import (_default_time_vector, _ideal_tfinal_and_dt, |
14 |
| - forced_response, impulse_response, |
15 |
| - initial_response, step_info, step_response) |
| 14 | +from control.timeresp import _default_time_vector, _ideal_tfinal_and_dt, \ |
| 15 | + forced_response, impulse_response, initial_response, step_info, \ |
| 16 | + step_response |
16 | 17 |
|
17 | 18 |
|
18 | 19 | class TSys:
|
@@ -1275,3 +1276,45 @@ def test_no_pandas():
|
1275 | 1276 | # Convert to pandas
|
1276 | 1277 | with pytest.raises(ImportError, match="pandas"):
|
1277 | 1278 | df = resp.to_pandas()
|
| 1279 | + |
| 1280 | + |
| 1281 | +# https://github.com/python-control/python-control/issues/1014 |
| 1282 | +def test_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 | + assert step_info['RiseTime'] == 0 |
| 1290 | + assert step_info['SettlingTime'] == 0 |
| 1291 | + assert step_info['SettlingMin'] == 1 |
| 1292 | + assert step_info['SettlingMax'] == 1 |
| 1293 | + assert step_info['Overshoot'] == 0 |
| 1294 | + assert step_info['Undershoot'] == 0 |
| 1295 | + assert step_info['Peak'] == 1 |
| 1296 | + assert step_info['PeakTime'] == 0 |
| 1297 | + assert step_info['SteadyStateValue'] == 1 |
| 1298 | + |
| 1299 | + # Constant value of -1 |
| 1300 | + step_info = ct.step_info(-y_const, timepts) |
| 1301 | + assert step_info['RiseTime'] == 0 |
| 1302 | + assert step_info['SettlingTime'] == 0 |
| 1303 | + assert step_info['SettlingMin'] == -1 |
| 1304 | + assert step_info['SettlingMax'] == -1 |
| 1305 | + assert step_info['Overshoot'] == 0 |
| 1306 | + assert step_info['Undershoot'] == 0 |
| 1307 | + assert step_info['Peak'] == 1 |
| 1308 | + assert step_info['PeakTime'] == 0 |
| 1309 | + assert step_info['SteadyStateValue'] == -1 |
| 1310 | + |
| 1311 | + # Ramp from -1 to 1 |
| 1312 | + step_info = ct.step_info(-1 + 2 * timepts/10, timepts) |
| 1313 | + assert step_info['RiseTime'] == 3.8 |
| 1314 | + assert step_info['SettlingTime'] == 9.8 |
| 1315 | + assert isclose(step_info['SettlingMin'], 0.88) |
| 1316 | + assert isclose(step_info['SettlingMax'], 0.96) |
| 1317 | + assert step_info['Overshoot'] == 0 |
| 1318 | + assert step_info['Peak'] == 1 |
| 1319 | + assert step_info['PeakTime'] == 0 |
| 1320 | + assert isclose(step_info['SteadyStateValue'], 0.96) |
0 commit comments