Skip to content

Commit 94a0ea1

Browse files
committed
removed bug where a pole or zero would be deleted if only 1 of them was present
1 parent 1e3a925 commit 94a0ea1

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

control/rlocus.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
131131
'button_release_event', partial(_RLFeedbackClicksPoint,sys=sys,fig=f))
132132

133133
elif sisotool == True:
134-
f.axes[1].plot([root.real for root in start_mat], [root.imag for root in start_mat], 'm.', marker='s', markersize=8,zorder=20)
134+
f.axes[1].plot([root.real for root in start_mat], [root.imag for root in start_mat], 'm.', marker='s', markersize=8,zorder=20,label='gain_point')
135135
f.suptitle("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" % (start_mat[0][0].real, start_mat[0][0].imag, 1, -1 * start_mat[0][0].real / abs(start_mat[0][0])),fontsize = 12 if int(matplotlib.__version__[0]) == 1 else 10)
136136
f.canvas.mpl_connect(
137137
'button_release_event',partial(_RLFeedbackClicksSisotool,sys=sys, fig=f, bode_plot_params=kwargs['bode_plot_params'],tvect=kwargs['tvect']))
@@ -380,7 +380,6 @@ def _RLFeedbackClicksSisotool(event,sys,fig,bode_plot_params,tvect):
380380
def _RLFeedbackClicksPoint(event,sys,fig,ax_rlocus=None,sisotool=False):
381381
"""Display root-locus gain feedback point for clicks on the root-locus plot
382382
"""
383-
print(event)
384383
if sisotool == False:
385384
ax_rlocus = fig.axes[0]
386385

@@ -397,17 +396,17 @@ def _RLFeedbackClicksPoint(event,sys,fig,ax_rlocus=None,sisotool=False):
397396

398397
# Remove the previous points
399398
for line in reversed(ax_rlocus.lines):
400-
if len(line.get_xdata()) == 1:
399+
if len(line.get_xdata()) == 1 and line.get_label()=='gain_point':
401400
line.remove()
402401
del line
403402

404403
# Visualise clicked point, display all roots for sisotool mode
405404
if sisotool:
406405
mymat = _RLFindRoots(nump, denp, K.real)
407406
ax_rlocus.plot([root.real for root in mymat], [root.imag for root in mymat], 'm.', marker='s', markersize=8,
408-
zorder=20)
407+
zorder=20,label='gain_point')
409408
else:
410-
ax_rlocus.plot(s.real, s.imag, 'k.', marker='s', markersize=8, zorder=20)
409+
ax_rlocus.plot(s.real, s.imag, 'k.', marker='s', markersize=8, zorder=20,label='gain_point')
411410

412411
# Update the canvas
413412
fig.canvas.draw()

control/tests/sisotool_test.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ class TestSisotool(unittest.TestCase):
1010
"""These are tests for the sisotool in sisotool.py."""
1111

1212
def setUp(self):
13-
"""This contains some random LTI systems and scalars for testing."""
14-
15-
# Two random SISO systems.
16-
sys1 = TransferFunction([1000],[1,25,100,0])
17-
sys2 = TransferFunction([1,1,1],[1,1])
18-
self.systems = (sys1, sys2)
13+
# One random SISO system.
14+
self.system = TransferFunction([1000],[1,25,100,0])
1915

2016
def test_sisotool(self):
21-
sisotool(self.systems[0])
17+
sisotool(self.system)
2218
fig = plt.gcf()
2319
ax_mag,ax_rlocus,ax_phase,ax_step = fig.axes[0],fig.axes[1],fig.axes[2],fig.axes[3]
2420

@@ -53,7 +49,7 @@ def test_sisotool(self):
5349

5450
# Move the rootlocus to another point
5551
event = type('test', (object,), {'xdata': 2.31206868287,'ydata':15.5983051046, 'inaxes':ax_rlocus.axes})()
56-
_RLFeedbackClicksSisotool(event=event, sys=self.systems[0], fig=fig, bode_plot_params=bode_plot_params, tvect=None)
52+
_RLFeedbackClicksSisotool(event=event, sys=self.system, fig=fig, bode_plot_params=bode_plot_params, tvect=None)
5753

5854
# Check the moved root locus plot points
5955
moved_point_0 = (np.array([-29.91742755]), np.array([0.]))

0 commit comments

Comments
 (0)