@@ -105,9 +105,16 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
105105 mymat = _RLFindRoots (nump , denp , kvect )
106106 mymat = _RLSortRoots (mymat )
107107
108+ # Check for sisotool mode
109+ sisotool = False if 'sisotool' not in kwargs else True
110+
108111 # Create the Plot
109112 if Plot :
110- if 'sisotool' not in kwargs :
113+ if sisotool :
114+ f = kwargs ['fig' ]
115+ ax = f .axes [1 ]
116+
117+ else :
111118 figure_number = pylab .get_fignums ()
112119 figure_title = [pylab .figure (numb ).canvas .get_window_title () for numb in figure_number ]
113120 new_figure_name = "Root Locus"
@@ -117,22 +124,16 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
117124 rloc_num += 1
118125 f = pylab .figure (new_figure_name )
119126 ax = pylab .axes ()
120- else :
121- sisotool = kwargs ['sisotool' ]
122- f = kwargs ['fig' ]
123- ax = f .axes [1 ]
124- bode_plot_params = kwargs ['bode_plot_params' ]
125- tvect = kwargs ['tvect' ]
126- event = type ('event' , (object ,), {'xdata' : start_mat [0 ][0 ].real ,'ydata' :start_mat [0 ][0 ].imag })()
127- _RLFeedbackClicksSisotool (event , sys , f ,bode_plot_params ,tvect )
128127
129128 if PrintGain and sisotool == False :
130129 f .canvas .mpl_connect (
131130 'button_release_event' , partial (_RLFeedbackClicksPoint ,sys = sys ,fig = f ))
131+
132132 elif sisotool == True :
133- print ('this is run' )
133+ 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 .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 ])))
134135 f .canvas .mpl_connect (
135- 'button_release_event' ,partial (_RLFeedbackClicksSisotool ,sys = sys , fig = f , bode_plot_params = bode_plot_params ,tvect = tvect ))
136+ 'button_release_event' ,partial (_RLFeedbackClicksSisotool ,sys = sys , fig = f , bode_plot_params = kwargs [ ' bode_plot_params' ] ,tvect = kwargs [ ' tvect' ] ))
136137
137138 # plot open loop poles
138139 poles = array (denp .r )
@@ -158,6 +159,9 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
158159 _sgrid_func (f )
159160 elif grid :
160161 _sgrid_func ()
162+ else :
163+ ax .axhline (0. , linestyle = ':' , color = 'k' )
164+ ax .axvline (0. , linestyle = ':' , color = 'k' )
161165 return mymat , kvect
162166
163167
@@ -366,23 +370,22 @@ def _RLFeedbackClicksSisotool(event,sys,fig,bode_plot_params,tvect):
366370 s = complex (event .xdata , event .ydata )
367371 K = - 1. / sys .horner (s )
368372 ax_rlocus = fig .axes [1 ]
369- if _RLFeedbackClicksPoint (event ,sys ,fig ,ax_rlocus ):
373+ if _RLFeedbackClicksPoint (event ,sys ,fig ,ax_rlocus , sisotool = True ):
370374 _SisotoolUpdate (sys ,fig ,K .real [0 ][0 ],bode_plot_params ,tvect )
371375
372-
373- def _RLFeedbackClicksPoint (event ,sys ,fig ,ax_rlocus = None ):
376+ def _RLFeedbackClicksPoint (event ,sys ,fig ,ax_rlocus = None ,sisotool = False ):
374377 """Display root-locus gain feedback point for clicks on the root-locus plot
375378 """
376- if ax_rlocus is None :
379+ if sisotool == False :
377380 ax_rlocus = fig .axes [0 ]
378- sisotool = False
379- else :
380- sisotool = True
381381
382382 (nump , denp ) = _systopoly1d (sys )
383383 s = complex (event .xdata , event .ydata )
384384 K = - 1. / sys .horner (s )
385- if abs (K .real ) > 1e-8 and abs (K .imag / K .real ) < 0.04 :
385+ print (K )
386+ if abs (K .real ) > 1e-8 and abs (K .imag / K .real ) < 0.04 and event .inaxes == ax_rlocus .axes :
387+
388+ # Display the parameters in the output window and figure
386389 print ("Clicked at %10.4g%+10.4gj gain %10.4g damp %10.4g" %
387390 (s .real , s .imag , K .real , - 1 * s .real / abs (s )))
388391 fig .suptitle ("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
@@ -393,8 +396,6 @@ def _RLFeedbackClicksPoint(event,sys,fig,ax_rlocus=None):
393396 if len (line .get_xdata ()) == 1 :
394397 line .remove ()
395398 del line
396- #else:
397- # break
398399
399400 # Visualise clicked point, display all roots for sisotool mode
400401 if sisotool :
@@ -404,6 +405,7 @@ def _RLFeedbackClicksPoint(event,sys,fig,ax_rlocus=None):
404405 else :
405406 ax_rlocus .plot (s .real , s .imag , 'k.' , marker = 's' , markersize = 8 , zorder = 20 )
406407
408+ # Update the canvas
407409 fig .canvas .draw ()
408410
409411 return True
0 commit comments