Skip to content

Commit 905056c

Browse files
committed
added display of root_loci within matplotlib and added visual feedback for clicked point
1 parent 601b581 commit 905056c

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

control/rlocus.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
112112
rloc_num += 1
113113
f = pylab.figure(new_figure_name)
114114

115+
ax = pylab.axes()
116+
115117
if PrintGain:
118+
click_point, = ax.plot([0], [0],color='k',markersize = 0,marker='s',zorder=20)
116119
f.canvas.mpl_connect(
117-
'button_release_event', partial(_RLFeedbackClicks, sys=sys))
118-
ax = pylab.axes()
120+
'button_release_event', partial(_RLFeedbackClicks, sys=sys,fig=f,point=click_point))
119121

120122
# plot open loop poles
121123
poles = array(denp.r)
@@ -152,6 +154,7 @@ def _default_gains(num, den, xlim, ylim):
152154
kmax = _k_max(num, den, real_break, k_break)
153155
kvect = np.hstack((np.linspace(0, kmax, 50), np.real(k_break)))
154156
kvect.sort()
157+
155158
mymat = _RLFindRoots(num, den, kvect)
156159
mymat = _RLSortRoots(mymat)
157160
open_loop_poles = den.roots
@@ -341,14 +344,20 @@ def _RLSortRoots(mymat):
341344
return sorted
342345

343346

344-
def _RLFeedbackClicks(event, sys):
347+
def _RLFeedbackClicks(event, sys,fig,point):
345348
"""Print root-locus gain feedback for clicks on the root-locus plot
346349
"""
347350
s = complex(event.xdata, event.ydata)
348351
K = -1./sys.horner(s)
349352
if abs(K.real) > 1e-8 and abs(K.imag/K.real) < 0.04:
350353
print("Clicked at %10.4g%+10.4gj gain %10.4g damp %10.4g" %
351354
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
355+
point.set_ydata(s.imag)
356+
point.set_xdata(s.real)
357+
point.set_markersize(8)
358+
fig.suptitle("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
359+
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
360+
fig.canvas.draw()
352361

353362

354363
def _sgrid_func(fig=None, zeta=None, wn=None):

0 commit comments

Comments
 (0)