64 matplotlib.use(
'TkAgg')
66 from matplotlib.backends.backend_tkagg
import FigureCanvasTkAgg, \
67 NavigationToolbar2TkAgg
68 from matplotlib.figure
import Figure
70 import matplotlib.pyplot
as mplPlot
71 import matplotlib.lines
as mplLine
72 import matplotlib.animation
as mplAnim
73 import matplotlib.colors
as mplColors
75 if sys.version_info[0] < 3:
77 from Tkconstants
import *
78 from tkFileDialog
import *
82 from Tkconstants
import *
83 from tkFileDialog
import *
88 _spkey =
lambda key:
'sp_'+key
96 def __init__(self, ax, maxt=4, dt=0.02):
109 self.ax.set_ylim(-100.1, 100.1)
110 self.ax.set_xlim(0, self.
maxt)
112 def addVel(self, key, color):
115 self.
vdata[key] = [0]
117 self.
lines[key].set_color(mplColors.hex2color(color))
118 self.
lines[key].set_linestyle(
'-')
119 self.ax.add_line(self.
lines[key])
124 self.
vdata[key_sp] = [0]
127 self.
lines[key_sp].set_color(mplColors.hex2color(color))
128 self.
lines[key_sp].set_linestyle(
'--')
129 self.
lines[key_sp].set_linewidth(2.0)
130 self.ax.add_line(self.
lines[key_sp])
134 return tuple(self.lines.values())
135 lastt = self.
tdata[-1]
138 for key
in self.vdata.keys():
140 self.
vdata[key].pop(0)
142 self.ax.figure.canvas.draw()
145 for key
in self.vdata.keys():
147 if key.find(
'sp_') >= 0:
150 self.
vdata[key].append(y[key])
152 return tuple(self.lines.values())
157 for k,s
in self.enabled.iteritems():
158 if s
and k.find(
'sp_') == -1:
159 v[k] = 200.0 * np.random.rand(1) - 100.0
168 def enable(self, key, setpoint):
175 self.
vdata[key_sp] = [setpoint] * len(self.
tdata)
180 def disable(self, key):
189 def setpoint(self, key, setpoint):
199 def __init__(self, wCanvas, width, height, motorNames, colors):
205 color = mplColors.hex2color(
"#ffcccc")
207 fig = mplPlot.Figure(figsize=(width/dpi, height/dpi), dpi=dpi,
210 ax = fig.add_subplot(111, xlabel=
"t (seconds)", ylabel=
'v (percent)')
214 for motor
in motorNames:
215 self.m_rtData.addVel(motor, colors[motor])
217 canvas = FigureCanvasTkAgg(fig, master=wCanvas)
218 canvas.get_tk_widget().grid(row=0, column=0)
221 ani = mplAnim.FuncAnimation(fig, self.m_rtData.update,
222 self.m_rtData.emitter, interval=10, blit=
True)
226 def enable(self, motors, setpoints):
227 if type(motors) == str:
228 self.m_rtData.enable(motors, setpoints)
229 elif type(motors) == list
or type(motors) == tuple:
231 self.m_rtData.enable(motor, setpoints[motor])
233 print "BUG: Bad paramaters:", repr(motors), repr(setpoints)
235 def disable(self, motors):
236 if type(motors) == str:
237 self.m_rtData.disable(motors)
238 elif type(motors) == list
or type(motors) == tuple:
240 self.m_rtData.disable(motor)
242 print "BUG: Bad paramaters:", repr(motors), repr(setpoints)
244 def setpoint(self, motors, setpoints):
245 if type(motors) == str:
246 self.m_rtData.setpoint(motors, setpoints)
247 elif type(motors) == list
or type(motors) == tuple:
249 self.m_rtData.setpoint(motor, setpoints[motor])
251 print "BUG: Bad paramaters:", repr(motors), repr(setpoints)