def __init__(self, nx, ny, widget): ratio = nx / ny self._canvas = scene.SceneCanvas(show=True, size=widget.GetSize(), keys='interactive', parent=widget) grid = self._canvas.central_widget.add_grid() self._view = grid.add_view(row=0, col=0, camera='panzoom') self._view.camera.rect = (0., -0.5, ratio, 1.) for p in np.linspace(0., ratio, num=5 * nx + 1): scene.InfiniteLine(pos=p, color=(0.3, 0.3, 0.3, 1.), vertical=True, parent=self._view.scene) for p in np.linspace(-0.5, 0.5, num=5 * ny + 1): if p == 0.: scene.InfiniteLine(pos=p, color=(0.5, 0.5, 0.5, 1.), vertical=False, parent=self._view.scene) else: scene.InfiniteLine(pos=p, color=(0.3, 0.3, 0.3, 1.), vertical=False, parent=self._view.scene) c_x = np.linspace(0., ratio, num=nx + 1) c_y = np.linspace(-0.5, 0.5, num=ny + 1) grid = np.array(np.meshgrid(c_x, c_y, indexing='ij')).T grid = grid.reshape((nx + 1) * (ny + 1), 2) scene.Markers(pos=grid, symbol='square', size=4, face_color=(0.6, 0.6, 0.6, 1.), parent=self._view.scene)
def __init__(self, graph_index=None, graph_time=None, graph_position=None, graph_error=None, graph_fan=None, graph_target=None): self.graph_index, self.graph_time, self.graph_position, self.graph_error, self.graph_fan, self.graph_target = graph_index, graph_time, graph_position, graph_error, graph_fan, graph_target self.last_graph_index = graph_index.value - 1 self.line_opacity = 0.8 self.data_pos = np.zeros((0, 2), dtype=np.float32) self.data_pos_error = np.zeros((0, 2), dtype=np.float32) self.color = np.ones((0, 4), dtype=np.float32) self.data_fan = np.zeros((0, 2), dtype=np.float32) self.data_target = np.zeros((0, 2), dtype=np.float32) self.canvas = scene.SceneCanvas( keys='interactive', show=True, title='Ping-Pong Ball PID Oscilloscope') grid = self.canvas.central_widget.add_grid(spacing=0) #https://github.com/vispy/vispy/blob/master/vispy/scene/cameras/panzoom.py self.viewbox_fan = grid.add_view(row=0, col=1, camera='panzoom', parent=self.canvas.scene) self.viewbox_pos = grid.add_view(row=0, col=1, camera='panzoom', parent=self.canvas.scene) self.viewbox_pos.events.resize.connect(self.on_resize) # add some axes x_axis = scene.AxisWidget(orientation='bottom') x_axis.stretch = (1, 0.1) grid.add_widget(x_axis, row=1, col=1) x_axis.link_view(self.viewbox_pos) y_axis = scene.AxisWidget(orientation='left', text_color='red') y_axis.stretch = (0.1, 1) grid.add_widget(y_axis, row=0, col=0) y_axis.link_view(self.viewbox_pos) y2_axis = scene.AxisWidget(orientation='right', text_color='green') y2_axis.stretch = (0.1, 10) grid.add_widget(y2_axis, row=0, col=2) y2_axis.link_view(self.viewbox_fan) # y2_axis.transform = STTransform(scale=(1, 0.2, 1)) t1 = Text('Detected Ball Position [m]', parent=self.canvas.scene, color='red') t1.font_size = 10 # t1.pos = self.canvas.size[0] // 2, self.canvas.size[1] // 3 t1.pos = 167, 20 t2 = Text('Detected Ball Position Error [m]', parent=self.canvas.scene, color='yellow') t2.font_size = 10 t2.pos = 185, 35 t3 = Text('Fan RPM [RPM]', parent=self.canvas.scene, color='green') t3.font_size = 10 t3.pos = 130, 50 t4 = Text('Target Height [m]', parent=self.canvas.scene, color='blue') t4.font_size = 10 t4.pos = 135, 65 # add a line plot inside the viewbox self.line_pos = None self.line_pos_error = None self.line_target = None self.line_fan = None # add horizontal lines scene.InfiniteLine(0.0, [0.5, 0.5, 0.5, 0.5], vertical=False, parent=self.viewbox_pos.scene) # auto-scale to see the whole line. self.viewbox_pos.camera.set_range() self.auto_scale = True self.auto_scroll = False self.canvas.events.mouse_press.connect(self.on_mouse_press) self.canvas.events.mouse_release.connect(self.on_mouse_release) self.canvas.events.key_press.connect(self.on_key_press) return
# add some axes x_axis = scene.AxisWidget(orientation='bottom') x_axis.stretch = (1, 0.1) grid.add_widget(x_axis, row=1, col=1) x_axis.link_view(viewbox) y_axis = scene.AxisWidget(orientation='left') y_axis.stretch = (0.1, 1) grid.add_widget(y_axis, row=0, col=0) y_axis.link_view(viewbox) # add a line plot inside the viewbox line = scene.Line(pos, color, parent=viewbox.scene) # add vertical lines vert_line1 = scene.InfiniteLine(100, [1.0, 0.0, 0.0, 1.0], parent=viewbox.scene) vert_line2 = scene.InfiniteLine(549.2, [0.0, 1.0, 0.0, 1.0], vertical=True, parent=viewbox.scene) # add horizontal lines hor_line1 = scene.InfiniteLine(0.3, [1.0, 0.0, 1.0, 1.0], vertical=False, parent=viewbox.scene) hor_line2 = scene.InfiniteLine(-5.1, [1.0, 1.0, 0.0, 1.0], vertical=False, parent=viewbox.scene) # auto-scale to see the whole line. viewbox.camera.set_range()