Skip to content

Rlocus visual display of clicked point #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions control/rlocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
ax, f = nogrid()
pylab.title(new_figure_name)

ax = pylab.axes()

if PrintGain:
click_point, = ax.plot([0], [0],color='k',markersize = 0,marker='s',zorder=20)
f.canvas.mpl_connect(
'button_release_event', partial(_RLFeedbackClicks, sys=sys))
'button_release_event', partial(_RLFeedbackClicks, sys=sys,fig=f,point=click_point))

# plot open loop poles
poles = array(denp.r)
Expand Down Expand Up @@ -157,6 +160,7 @@ def _default_gains(num, den, xlim, ylim):
kmax = _k_max(num, den, real_break, k_break)
kvect = np.hstack((np.linspace(0, kmax, 50), np.real(k_break)))
kvect.sort()

mymat = _RLFindRoots(num, den, kvect)
mymat = _RLSortRoots(mymat)
open_loop_poles = den.roots
Expand Down Expand Up @@ -346,13 +350,19 @@ def _RLSortRoots(mymat):
return sorted


def _RLFeedbackClicks(event, sys):
def _RLFeedbackClicks(event, sys,fig,point):
"""Print root-locus gain feedback for clicks on the root-locus plot
"""
s = complex(event.xdata, event.ydata)
K = -1./sys.horner(s)
if abs(K.real) > 1e-8 and abs(K.imag/K.real) < 0.04:
print("Clicked at %10.4g%+10.4gj gain %10.4g damp %10.4g" %
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
point.set_ydata(s.imag)
point.set_xdata(s.real)
point.set_markersize(8)
fig.suptitle("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
fig.canvas.draw()

rlocus = root_locus