Skip to content

Commit 0137056

Browse files
committed
add legacy processing for root_locus
1 parent 0d23598 commit 0137056

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

control/rlocus.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def root_locus_map(sysdata, gains=None):
7575

7676

7777
def root_locus_plot(
78-
sysdata, kvect=None, grid=None, plot=True, **kwargs):
78+
sysdata, kvect=None, grid=None, plot=None, **kwargs):
7979
"""Root locus plot.
8080
8181
Calculate the root locus by finding the roots of 1 + k * G(s) where G
@@ -131,12 +131,29 @@ def root_locus_plot(
131131
grid = config._get_param('rlocus', 'grid', grid, _rlocus_defaults)
132132

133133
responses = root_locus_map(sysdata, gains=kvect)
134-
# TODO: update to include legacy keyword processing (use pole_zero_plot?)
135-
if plot:
136-
responses.plot(grid=grid, **kwargs)
137134

138-
# TODO: legacy return value; update
139-
return responses.loci, responses.gains
135+
#
136+
# Process `plot` keyword
137+
#
138+
# See bode_plot for a description of how this keyword is handled to
139+
# support legacy implementatoins of root_locus.
140+
#
141+
if plot is not None:
142+
warnings.warn(
143+
"`root_locus` return values of loci, gains is deprecated; "
144+
"use root_locus_map()", DeprecationWarning)
145+
146+
if plot is False:
147+
return responses.loci, responses.gains
148+
149+
# Plot the root loci
150+
out = responses.plot(grid=grid, **kwargs)
151+
152+
# Legacy processing: return locations of poles and zeros as a tuple
153+
if plot is True:
154+
return responses.loci, responses.gains
155+
156+
return out
140157

141158

142159
# TODO: get rid of zoom functionality?

control/tests/rlocus_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def testRootLocus(self, sys):
5555
self.check_cl_poles(sys, roots, klist)
5656

5757
# now check with plotting
58-
roots, k_out = root_locus(sys, klist)
58+
roots, k_out = root_locus(sys, klist, plot=True)
5959
np.testing.assert_equal(len(roots), len(klist))
6060
np.testing.assert_allclose(klist, k_out)
6161
self.check_cl_poles(sys, roots, klist)
@@ -68,7 +68,7 @@ def test_without_gains(self, sys):
6868
@pytest.mark.slow
6969
@pytest.mark.parametrize('grid', [None, True, False])
7070
def test_root_locus_plot_grid(self, sys, grid):
71-
rlist, klist = root_locus(sys, grid=grid)
71+
rlist, klist = root_locus(sys, plot=True, grid=grid)
7272
ax = plt.gca()
7373
n_gridlines = sum([int(line.get_linestyle() in [':', 'dotted',
7474
'--', 'dashed'])
@@ -82,7 +82,7 @@ def test_root_locus_plot_grid(self, sys, grid):
8282
def test_root_locus_neg_false_gain_nonproper(self):
8383
""" Non proper TranferFunction with negative gain: Not implemented"""
8484
with pytest.raises(ValueError, match="with equal order"):
85-
root_locus(TransferFunction([-1, 2], [1, 2]))
85+
root_locus(TransferFunction([-1, 2], [1, 2]), plot=True)
8686

8787
# TODO: cover and validate negative false_gain branch in _default_gains()
8888

@@ -93,7 +93,7 @@ def test_root_locus_zoom(self):
9393
"""Check the zooming functionality of the Root locus plot"""
9494
system = TransferFunction([1000], [1, 25, 100, 0])
9595
plt.figure()
96-
root_locus(system)
96+
root_locus(system, plot=True)
9797
fig = plt.gcf()
9898
ax_rlocus = fig.axes[0]
9999

@@ -135,7 +135,7 @@ def test_rlocus_default_wn(self):
135135
sys = ct.tf(*sp.signal.zpk2tf(
136136
[-1e-2, 1-1e7j, 1+1e7j], [0, -1e7j, 1e7j], 1))
137137

138-
ct.root_locus(sys)
138+
ct.root_locus(sys, plot=True)
139139

140140

141141
# TODO: add additional test cases

0 commit comments

Comments
 (0)