Skip to content

Commit ece5f92

Browse files
committed
initial implementation
1 parent a8658e4 commit ece5f92

5 files changed

Lines changed: 510 additions & 10 deletions

File tree

control/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
from .xferfcn import *
7878
from .frdata import *
7979

80+
# Time responses and plotting
81+
from .timeresp import *
82+
from .timeplot import *
83+
8084
from .bdalg import *
8185
from .delay import *
8286
from .descfcn import *
@@ -91,7 +95,6 @@
9195
from .rlocus import *
9296
from .statefbk import *
9397
from .stochsys import *
94-
from .timeresp import *
9598
from .ctrlutil import *
9699
from .canonical import *
97100
from .robust import *

control/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def reset_defaults():
135135
from .optimal import _optimal_defaults
136136
defaults.update(_optimal_defaults)
137137

138+
from .timeplot import _timeplot_defaults
139+
defaults.update(_timeplot_defaults)
140+
138141

139142
def _get_param(module, param, argval=None, defval=None, pop=False, last=False):
140143
"""Return the default value for a configuration option.

control/tests/timeplot_test.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# timeplot_test.py - test out time response plots
2+
# RMM, 23 Jun 2023
3+
4+
import pytest
5+
import control as ct
6+
import matplotlib as mpl
7+
import matplotlib.pyplot as plt
8+
9+
# Step responses
10+
@pytest.mark.parametrize("nin, nout", [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)])
11+
@pytest.mark.parametrize("transpose", [True, False])
12+
@pytest.mark.parametrize("plot_inputs", [None, True, False])
13+
def test_simple_response(nout, nin, transpose, plot_inputs):
14+
sys = ct.rss(4, nout, nin)
15+
stepresp = ct.step_response(sys)
16+
stepresp.plot(plot_inputs=plot_inputs, transpose=transpose)
17+
18+
# Add additional data (and provide infon in the title)
19+
ct.step_response(ct.rss(4, nout, nin), stepresp.time[-1]).plot(
20+
plot_inputs=plot_inputs, transpose=transpose,
21+
title=stepresp.title + f" [{plot_inputs=}, {transpose=}]")
22+
23+
24+
@pytest.mark.parametrize("transpose", [True, False])
25+
def test_combine_signals(transpose):
26+
sys = ct.rss(4, 2, 3)
27+
stepresp = ct.step_response(sys)
28+
stepresp.plot(
29+
combine_signals=True, transpose=transpose,
30+
title=f"Step response: combine_signals = True; transpose={transpose}")
31+
32+
33+
@pytest.mark.parametrize("transpose", [True, False])
34+
def test_combine_traces(transpose):
35+
sys = ct.rss(4, 2, 3)
36+
stepresp = ct.step_response(sys)
37+
stepresp.plot(
38+
combine_traces=True, transpose=transpose,
39+
title=f"Step response: combine_traces = True; transpose={transpose}")
40+
41+
42+
@pytest.mark.parametrize("transpose", [True, False])
43+
def test_combine_signals_traces(transpose):
44+
sys = ct.rss(4, 5, 3)
45+
stepresp = ct.step_response(sys)
46+
stepresp.plot(
47+
combine_signals=True, combine_traces=True, transpose=transpose,
48+
title=f"Step response: combine_signals/traces = True;" +
49+
f"transpose={transpose}")
50+
51+
52+
if __name__ == "__main__":
53+
#
54+
# Interactive mode: generate plots for manual viewing
55+
#
56+
# Running this script in python (or better ipython) will show a
57+
# collection of figures that should all look OK on the screeen.
58+
#
59+
60+
# In interactive mode, turn on ipython interactive graphics
61+
plt.ion()
62+
63+
# Start by clearing existing figures
64+
plt.close('all')
65+
66+
print ("Simple step responses")
67+
for size in [(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)]:
68+
for transpose in [False, True]:
69+
for plot_inputs in [None, True, False]:
70+
plt.figure()
71+
test_simple_response(
72+
*size, transpose=transpose, plot_inputs=plot_inputs)
73+
74+
print ("Combine signals")
75+
for transpose in [False, True]:
76+
plt.figure()
77+
test_combine_signals(transpose)
78+
79+
print ("Combine traces")
80+
for transpose in [False, True]:
81+
plt.figure()
82+
test_combine_traces(transpose)
83+
84+
print ("Combine signals and traces")
85+
for transpose in [False, True]:
86+
plt.figure()
87+
test_combine_signals_traces(transpose)
88+

0 commit comments

Comments
 (0)