Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
54583d5
first sisotool chechpoint
icam0 May 23, 2018
2e1bf7d
second sisotool checkpoint
icam0 May 24, 2018
f4545dd
changed matplotlib event handler
icam0 May 25, 2018
e3c1f31
improved sisotool readability
icam0 May 25, 2018
72ffb63
Merge branch 'bode_margins_plot' into sisotool_merge
icam0 May 25, 2018
bde60f5
Added display of GM and PM in bode plot. Fixed Hz bug support. Fixed …
icam0 May 28, 2018
bc74a0a
Added support for both matplotlib 1.x.x. and 2.x.x and fixed redrawin…
icam0 May 29, 2018
1e3a925
Added docstring and unittest
icam0 May 29, 2018
94a0ea1
removed bug where a pole or zero would be deleted if only 1 of them w…
icam0 May 30, 2018
c0e533e
root locus smooth with zoom bug
icam0 Jun 2, 2018
fe13ae1
Fixed zooming on plot. Now displays smoother root locus plot.
icam0 Jun 2, 2018
2ba8277
Fixed paning on plot and clicking on the root locus plot while zoomed
icam0 Jun 3, 2018
c26187f
Added unit test for rootlocus zoom functionality
icam0 Jun 3, 2018
9962cea
Fixed sisotool unittest
icam0 Jun 3, 2018
938ae88
Fixed frequency response unittest
icam0 Jun 3, 2018
9f13a77
small change to sisotool test
icam0 Jun 3, 2018
6e06a9c
small change to unittests
icam0 Jun 3, 2018
cdb9f42
fixed python 2 integer division error in false gain of rootlocus
icam0 Jun 3, 2018
90959bd
changed root locus test to a numerically more significant one.
icam0 Jun 3, 2018
70ec8be
changed root locus test indices.
icam0 Jun 3, 2018
9f50e13
Merge branch 'master' into sisotool_final
repagh Jul 9, 2018
3e7cad6
Merge branch 'master' into sisotool_final
murrayrm Dec 29, 2018
43d8b95
Merge branch 'master' into sisotool_final
murrayrm Apr 11, 2019
03f87a3
Fix small typo from manual merge
murrayrm Apr 12, 2019
17c4a95
fixed issues identified in review
murrayrm Apr 12, 2019
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
Prev Previous commit
Next Next commit
changed matplotlib event handler
  • Loading branch information
icam0 committed May 25, 2018
commit f4545dd76a96098867a330b8194abb70649778ff
49 changes: 34 additions & 15 deletions control/rlocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
bode_plot_params = kwargs['bode_plot_params']
tvect = kwargs['tvect']
event = type('event', (object,), {'xdata': start_mat[0][0].real,'ydata':start_mat[0][0].imag})()
_RLFeedbackClicks(event, sys, f, sisotool,bode_plot_params,tvect)

if PrintGain:
_RLFeedbackClicksSisotool(event, sys, f,bode_plot_params,tvect)

if PrintGain and sisotool == False:
f.canvas.mpl_connect(
'button_release_event', partial(_RLFeedbackClicksPoint,sys=sys,fig=f))
elif sisotool == True:
print('this is run')
f.canvas.mpl_connect(
'button_release_event', partial(_RLFeedbackClicks,sys=sys,fig=f,sisotool=sisotool,bode_plot_params=bode_plot_params,tvect=tvect))
'button_release_event',partial(_RLFeedbackClicksSisotool,sys=sys, fig=f, bode_plot_params=bode_plot_params,tvect=tvect))

# plot open loop poles
poles = array(denp.r)
Expand Down Expand Up @@ -357,40 +360,56 @@ def _RLSortRoots(mymat):
prevrow = sorted[n, :]
return sorted

def _RLFeedbackClicksSisotool(event,sys,fig,bode_plot_params,tvect):
"""Update Sisotool plots if a new point on the root locus plot is clicked
"""
s = complex(event.xdata, event.ydata)
K = -1./sys.horner(s)
ax_rlocus = fig.axes[1]
if _RLFeedbackClicksPoint(event,sys,fig,ax_rlocus):
_SisotoolUpdate(sys,fig,K.real[0][0],bode_plot_params,tvect)


def _RLFeedbackClicks(event,sys,fig,sisotool,bode_plot_params,tvect):
"""Print root-locus gain feedback for clicks on the root-locus plot
def _RLFeedbackClicksPoint(event,sys,fig,ax_rlocus=None):
"""Display root-locus gain feedback point for clicks on the root-locus plot
"""
if ax_rlocus is None:
ax_rlocus = fig.axes[0]
sisotool = False
else:
sisotool = True

(nump, denp) = _systopoly1d(sys)
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:
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)))
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)))

if sisotool:
ax_rlocus = fig.axes[1]
else:
ax_rlocus = fig.axes[0]

# Remove the previous points
for line in reversed(ax_rlocus.lines):
if len(line.get_xdata()) == 1:
line.remove()
del line
#else:
# break

# Visualise clicked point, display all roots for sisotool mode
if sisotool:
mymat = _RLFindRoots(nump, denp, K.real)
ax_rlocus.plot([root.real for root in mymat],[root.imag for root in mymat],'m.',marker='s',markersize=8, zorder=20)
_SisotoolUpdate(sys,fig,K.real[0][0],bode_plot_params,tvect)
ax_rlocus.plot([root.real for root in mymat], [root.imag for root in mymat], 'm.', marker='s', markersize=8,
zorder=20)
else:
ax_rlocus.plot(s.real, s.imag, 'k.', marker='s', markersize=8, zorder=20)

fig.canvas.draw()

return True



def _sgrid_func(fig=None, zeta=None, wn=None):
if fig is None:
fig = pylab.gcf()
Expand Down
8 changes: 4 additions & 4 deletions control/sisotool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def sisotool(sys, kvect = None, xlim = None, ylim = None, plotstr_rlocus = '-',r
'fig': fig,
}

#To-do find out clever way to pass correct settings to other plots
_SisotoolUpdate(sys, fig, 1,bode_plot_params,tvect)
# First time call to setup the bode and step response plots
_SisotoolUpdate(sys, fig,1 if kvect is None else kvect[0],bode_plot_params)

# Setup the root-locus plot window
root_locus(sys,kvect=kvect,xlim=xlim,ylim = ylim,plotstr=plotstr_rlocus,grid = rlocus_grid,fig=fig,bode_plot_params=bode_plot_params,tvect=tvect,sisotool=True)

def _SisotoolUpdate(sys,fig,K,bode_plot_params,tvect):
def _SisotoolUpdate(sys,fig,K,bode_plot_params,tvect=None):

# Get the subaxes and clear them
ax_mag,ax_rlocus,ax_phase,ax_step = fig.axes[0],fig.axes[1],fig.axes[2],fig.axes[3]
Expand All @@ -55,7 +55,7 @@ def _SisotoolUpdate(sys,fig,K,bode_plot_params,tvect):
bode_plot_params['syslist'] = sys*K.real
bode_plot(**bode_plot_params)

# Generate the step response
# Generate the step response and plot it
sys_closed = (K*sys).feedback(1)
if tvect is None:
tvect, yout = step_response(sys_closed)
Expand Down