@@ -124,12 +124,15 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
124124 bode_plot_params = kwargs ['bode_plot_params' ]
125125 tvect = kwargs ['tvect' ]
126126 event = type ('event' , (object ,), {'xdata' : start_mat [0 ][0 ].real ,'ydata' :start_mat [0 ][0 ].imag })()
127- _RLFeedbackClicks (event , sys , f , sisotool ,bode_plot_params ,tvect )
128-
129- if PrintGain :
127+ _RLFeedbackClicksSisotool (event , sys , f ,bode_plot_params ,tvect )
130128
129+ if PrintGain and sisotool == False :
130+ f .canvas .mpl_connect (
131+ 'button_release_event' , partial (_RLFeedbackClicksPoint ,sys = sys ,fig = f ))
132+ elif sisotool == True :
133+ print ('this is run' )
131134 f .canvas .mpl_connect (
132- 'button_release_event' , partial (_RLFeedbackClicks ,sys = sys ,fig = f ,sisotool = sisotool , bode_plot_params = bode_plot_params ,tvect = tvect ))
135+ 'button_release_event' ,partial (_RLFeedbackClicksSisotool ,sys = sys , fig = f , bode_plot_params = bode_plot_params ,tvect = tvect ))
133136
134137 # plot open loop poles
135138 poles = array (denp .r )
@@ -357,40 +360,56 @@ def _RLSortRoots(mymat):
357360 prevrow = sorted [n , :]
358361 return sorted
359362
363+ def _RLFeedbackClicksSisotool (event ,sys ,fig ,bode_plot_params ,tvect ):
364+ """Update Sisotool plots if a new point on the root locus plot is clicked
365+ """
366+ s = complex (event .xdata , event .ydata )
367+ K = - 1. / sys .horner (s )
368+ ax_rlocus = fig .axes [1 ]
369+ if _RLFeedbackClicksPoint (event ,sys ,fig ,ax_rlocus ):
370+ _SisotoolUpdate (sys ,fig ,K .real [0 ][0 ],bode_plot_params ,tvect )
371+
360372
361- def _RLFeedbackClicks (event ,sys ,fig ,sisotool , bode_plot_params , tvect ):
362- """Print root-locus gain feedback for clicks on the root-locus plot
373+ def _RLFeedbackClicksPoint (event ,sys ,fig ,ax_rlocus = None ):
374+ """Display root-locus gain feedback point for clicks on the root-locus plot
363375 """
376+ if ax_rlocus is None :
377+ ax_rlocus = fig .axes [0 ]
378+ sisotool = False
379+ else :
380+ sisotool = True
381+
364382 (nump , denp ) = _systopoly1d (sys )
365383 s = complex (event .xdata , event .ydata )
366- K = - 1. / sys .horner (s )
367- if abs (K .real ) > 1e-8 and abs (K .imag / K .real ) < 0.04 :
384+ K = - 1. / sys .horner (s )
385+ if abs (K .real ) > 1e-8 and abs (K .imag / K .real ) < 0.04 :
368386 print ("Clicked at %10.4g%+10.4gj gain %10.4g damp %10.4g" %
369387 (s .real , s .imag , K .real , - 1 * s .real / abs (s )))
370388 fig .suptitle ("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
371389 (s .real , s .imag , K .real , - 1 * s .real / abs (s )))
372390
373- if sisotool :
374- ax_rlocus = fig .axes [1 ]
375- else :
376- ax_rlocus = fig .axes [0 ]
377-
391+ # Remove the previous points
378392 for line in reversed (ax_rlocus .lines ):
379393 if len (line .get_xdata ()) == 1 :
380394 line .remove ()
381395 del line
382396 #else:
383397 # break
384398
399+ # Visualise clicked point, display all roots for sisotool mode
385400 if sisotool :
386401 mymat = _RLFindRoots (nump , denp , K .real )
387- ax_rlocus .plot ([root .real for root in mymat ],[root .imag for root in mymat ],'m.' ,marker = 's' ,markersize = 8 , zorder = 20 )
388- _SisotoolUpdate ( sys , fig , K . real [ 0 ][ 0 ], bode_plot_params , tvect )
402+ ax_rlocus .plot ([root .real for root in mymat ], [root .imag for root in mymat ], 'm.' , marker = 's' , markersize = 8 ,
403+ zorder = 20 )
389404 else :
390405 ax_rlocus .plot (s .real , s .imag , 'k.' , marker = 's' , markersize = 8 , zorder = 20 )
391406
392407 fig .canvas .draw ()
393408
409+ return True
410+
411+
412+
394413def _sgrid_func (fig = None , zeta = None , wn = None ):
395414 if fig is None :
396415 fig = pylab .gcf ()
0 commit comments