Skip to content

Commit fc8f8d7

Browse files
committed
improved test coverage, pep8 cleanup, doc clarification, removed compatibility with matplotlib 1 released 10 years ago
1 parent 03cdab7 commit fc8f8d7

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

control/sisotool.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
import matplotlib.pyplot as plt
1111
import warnings
1212

13-
def sisotool(sys, kvect = None, xlim_rlocus = None, ylim_rlocus = None,
14-
plotstr_rlocus = 'b' if int(matplotlib.__version__[0]) == 1 else 'C0',
15-
rlocus_grid = False, omega = None, dB = None, Hz = None,
16-
deg = None, omega_limits = None, omega_num = None,
17-
margins_bode = True, tvect=None):
13+
def sisotool(sys, kvect=None, xlim_rlocus=None, ylim_rlocus=None,
14+
plotstr_rlocus='C0', rlocus_grid=False, omega=None, dB=None,
15+
Hz=None, deg=None, omega_limits=None, omega_num=None,
16+
margins_bode=True, tvect=None):
1817
"""
1918
Sisotool style collection of plots inspired by MATLAB's sisotool.
2019
The left two plots contain the bode magnitude and phase diagrams.
@@ -26,12 +25,15 @@ def sisotool(sys, kvect = None, xlim_rlocus = None, ylim_rlocus = None,
2625
----------
2726
sys : LTI object
2827
Linear input/output systems. If sys is SISO, use the same
29-
system for the root locus and step response. If sys is
30-
two-input, two-output, insert the negative of the selected gain
31-
between the first output and first input and use the second input
32-
and output for computing the step response. This allows you to see
33-
the step responses of more complex systems while using sisotool,
34-
for example, systems with a feedforward path into the plant.
28+
system for the root locus and step response. If it is desired to
29+
see a different step response than feedback(K*loop,1), sys can be
30+
provided as a two-input, two-output system (e.g. by using
31+
:func:`bdgalg.connect' or :func:`iosys.interconnect`). Sisotool
32+
inserts the negative of the selected gain K between the first output
33+
and first input and uses the second input and output for computing
34+
the step response. This allows you to see the step responses of more
35+
complex systems, for example, systems with a feedforward path into the
36+
plant or in which the gain appears in the feedback path.
3537
kvect : list or ndarray, optional
3638
List of gains to use for plotting root locus
3739
xlim_rlocus : tuple or list, optional
@@ -108,12 +110,8 @@ def sisotool(sys, kvect = None, xlim_rlocus = None, ylim_rlocus = None,
108110

109111
def _SisotoolUpdate(sys, fig, K, bode_plot_params, tvect=None):
110112

111-
if int(matplotlib.__version__[0]) == 1:
112-
title_font_size = 12
113-
label_font_size = 10
114-
else:
115-
title_font_size = 10
116-
label_font_size = 8
113+
title_font_size = 10
114+
label_font_size = 8
117115

118116
# Get the subaxes and clear them
119117
ax_mag, ax_rlocus, ax_phase, ax_step = \
@@ -144,7 +142,7 @@ def _SisotoolUpdate(sys, fig, K, bode_plot_params, tvect=None):
144142

145143
ax_step.set_title('Step response',fontsize = title_font_size)
146144
ax_step.set_xlabel('Time (seconds)',fontsize=label_font_size)
147-
ax_step.set_ylabel('Amplitude',fontsize=label_font_size)
145+
ax_step.set_ylabel('Output',fontsize=label_font_size)
148146
ax_step.get_xaxis().set_label_coords(0.5, -0.15)
149147
ax_step.get_yaxis().set_label_coords(-0.15, 0.5)
150148
ax_step.tick_params(axis='both', which='major', labelsize=label_font_size)

control/tests/sisotool_test.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def sys(self):
2121
"""Return a generic SISO transfer function"""
2222
return TransferFunction([1000], [1, 25, 100, 0])
2323

24+
@pytest.fixture
25+
def sysdt(self):
26+
"""Return a generic SISO transfer function"""
27+
return TransferFunction([1000], [1, 25, 100, 0], True)
28+
2429
@pytest.fixture
2530
def sys222(self):
2631
"""2-states square system (2 inputs x 2 outputs)"""
@@ -45,7 +50,7 @@ def sys221(self):
4550
D221 = [[1., -1.]]
4651
return StateSpace(A222, B222, C221, D221)
4752

48-
def test_sisotool(self, sys, sys222, sys221):
53+
def test_sisotool(self, sys, sysdt, sys222, sys221):
4954
sisotool(sys, Hz=False)
5055
fig = plt.gcf()
5156
ax_mag, ax_rlocus, ax_phase, ax_step = fig.axes[:4]
@@ -114,15 +119,21 @@ def test_sisotool(self, sys, sys222, sys221):
114119
step_response_moved = np.array(
115120
[0., 0.0072, 0.0516, 0.1554, 0.3281, 0.5681, 0.8646, 1.1987,
116121
1.5452, 1.875])
117-
# old: array([0., 0.0239, 0.161 , 0.4547, 0.8903, 1.407,
118-
# 1.9121, 2.2989, 2.4686, 2.353])
119122
assert_array_almost_equal(
120123
ax_step.lines[0].get_data()[1][:10], step_response_moved, 4)
121124

125+
# test supply tvect
126+
sisotool(sys, tvect=np.arange(0, 1, .1))
127+
128+
# test discrete-time
129+
sisotool(sysdt, tvect=5)
130+
122131
# test MIMO compatibility
123132
# sys must be siso or 2 input, 2 output
124133
with pytest.raises(ControlMIMONotImplemented):
125134
sisotool(sys221)
126135
# does not raise an error:
127136
sisotool(sys222)
128137

138+
139+

0 commit comments

Comments
 (0)