@@ -122,9 +122,12 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
122
122
ax , f = nogrid ()
123
123
pylab .title (new_figure_name )
124
124
125
+ ax = pylab .axes ()
126
+
125
127
if PrintGain :
128
+ click_point , = ax .plot ([0 ], [0 ],color = 'k' ,markersize = 0 ,marker = 's' ,zorder = 20 )
126
129
f .canvas .mpl_connect (
127
- 'button_release_event' , partial (_RLFeedbackClicks , sys = sys ))
130
+ 'button_release_event' , partial (_RLFeedbackClicks , sys = sys , fig = f , point = click_point ))
128
131
129
132
# plot open loop poles
130
133
poles = array (denp .r )
@@ -157,6 +160,7 @@ def _default_gains(num, den, xlim, ylim):
157
160
kmax = _k_max (num , den , real_break , k_break )
158
161
kvect = np .hstack ((np .linspace (0 , kmax , 50 ), np .real (k_break )))
159
162
kvect .sort ()
163
+
160
164
mymat = _RLFindRoots (num , den , kvect )
161
165
mymat = _RLSortRoots (mymat )
162
166
open_loop_poles = den .roots
@@ -346,13 +350,19 @@ def _RLSortRoots(mymat):
346
350
return sorted
347
351
348
352
349
- def _RLFeedbackClicks (event , sys ):
353
+ def _RLFeedbackClicks (event , sys , fig , point ):
350
354
"""Print root-locus gain feedback for clicks on the root-locus plot
351
355
"""
352
356
s = complex (event .xdata , event .ydata )
353
357
K = - 1. / sys .horner (s )
354
358
if abs (K .real ) > 1e-8 and abs (K .imag / K .real ) < 0.04 :
355
359
print ("Clicked at %10.4g%+10.4gj gain %10.4g damp %10.4g" %
356
360
(s .real , s .imag , K .real , - 1 * s .real / abs (s )))
361
+ point .set_ydata (s .imag )
362
+ point .set_xdata (s .real )
363
+ point .set_markersize (8 )
364
+ fig .suptitle ("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
365
+ (s .real , s .imag , K .real , - 1 * s .real / abs (s )))
366
+ fig .canvas .draw ()
357
367
358
368
rlocus = root_locus
0 commit comments