Skip to content

Commit 54583d5

Browse files
committed
first sisotool chechpoint
1 parent c65c100 commit 54583d5

3 files changed

Lines changed: 41 additions & 18 deletions

File tree

control/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from .canonical import *
6868
from .robust import *
6969
from .config import *
70+
from .sisotool import *
7071

7172
# Exceptions
7273
from .exception import *

control/rlocus.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
# Main function: compute a root locus diagram
6161
def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
62-
PrintGain=True, grid=False):
62+
PrintGain=True, grid=False, sisotool = False, f=None, ax =None):
6363
"""Root locus plot
6464
6565
Calculate the root locus by finding the roots of 1+k*TF(s)
@@ -103,21 +103,21 @@ def root_locus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True,
103103

104104
# Create the Plot
105105
if Plot:
106-
figure_number = pylab.get_fignums()
107-
figure_title = [pylab.figure(numb).canvas.get_window_title() for numb in figure_number]
108-
new_figure_name = "Root Locus"
109-
rloc_num = 1
110-
while new_figure_name in figure_title:
111-
new_figure_name = "Root Locus " + str(rloc_num)
112-
rloc_num += 1
113-
f = pylab.figure(new_figure_name)
106+
if sisotool == False:
107+
figure_number = pylab.get_fignums()
108+
figure_title = [pylab.figure(numb).canvas.get_window_title() for numb in figure_number]
109+
new_figure_name = "Root Locus"
110+
rloc_num = 1
111+
while new_figure_name in figure_title:
112+
new_figure_name = "Root Locus " + str(rloc_num)
113+
rloc_num += 1
114+
f = pylab.figure(new_figure_name)
115+
ax = pylab.axes()
114116

115-
ax = pylab.axes()
116117

117118
if PrintGain:
118-
click_point, = ax.plot([0], [0],color='k',markersize = 0,marker='s',zorder=20)
119119
f.canvas.mpl_connect(
120-
'button_release_event', partial(_RLFeedbackClicks, sys=sys,fig=f,point=click_point))
120+
'button_release_event', partial(_RLFeedbackClicks,sys=sys,fig=f,sisotool=sisotool))
121121

122122
# plot open loop poles
123123
poles = array(denp.r)
@@ -344,21 +344,33 @@ def _RLSortRoots(mymat):
344344
return sorted
345345

346346

347-
def _RLFeedbackClicks(event, sys,fig,point):
347+
def _RLFeedbackClicks(event,sys,fig,sisotool):
348348
"""Print root-locus gain feedback for clicks on the root-locus plot
349349
"""
350+
(nump, denp) = _systopoly1d(sys)
350351
s = complex(event.xdata, event.ydata)
351352
K = -1./sys.horner(s)
352353
if abs(K.real) > 1e-8 and abs(K.imag/K.real) < 0.04:
353354
print("Clicked at %10.4g%+10.4gj gain %10.4g damp %10.4g" %
354355
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
355-
point.set_ydata(s.imag)
356-
point.set_xdata(s.real)
357-
point.set_markersize(8)
358356
fig.suptitle("Clicked at: %10.4g%+10.4gj gain: %10.4g damp: %10.4g" %
359-
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
360-
fig.canvas.draw()
357+
(s.real, s.imag, K.real, -1 * s.real / abs(s)))
358+
359+
ax = fig.axes[0]
360+
for line in reversed(ax.lines):
361+
if len(line.get_xdata()) == 1:
362+
line.remove()
363+
del line
364+
else:
365+
break
366+
367+
if sisotool:
368+
mymat = _RLFindRoots(nump, denp, K.real)
369+
ax.plot([root.real for root in mymat],[root.imag for root in mymat],'m.',marker='s',markersize=8, zorder=20)
370+
else:
371+
ax.plot(s.real, s.imag, 'k.', marker='s', markersize=8, zorder=20)
361372

373+
fig.canvas.draw()
362374

363375
def _sgrid_func(fig=None, zeta=None, wn=None):
364376
if fig is None:

control/sisotool.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__all__ = ['sisotool']
2+
3+
from .freqplot import bode_plot
4+
from .rlocus import root_locus
5+
import matplotlib.pyplot as plt
6+
7+
def sisotool(sys, kvect=None,PrintGain=True,grid=False,dB=None,Hz=None,deg=None):
8+
f, (ax1, ax2) = plt.subplots(1, 2)
9+
root_locus(sys,ax=ax1,f=f,sisotool=True)
10+
#bode_plot(sys,ax=ax2)

0 commit comments

Comments
 (0)