13 from geometry_msgs.msg
import Twist, Vector3
22 self.
_scale = rospy.get_param(
'~scale', 1.0)
26 self.
_pub_cmd = rospy.Publisher(
'mouse_vel', Twist, queue_size=100)
41 self._root.title(
'Mouse Teleop')
44 self._root.resizable(0, 0)
50 self._canvas.create_arc(0, 0, 0, 0, fill=
'red', outline=
'red',
51 width=1, style=Tkinter.PIESLICE, start=90.0, tag=
'w')
52 self._canvas.create_line(0, 0, 0, 0, fill=
'blue', width=4, tag=
'v_x')
55 self._canvas.create_line(0, 0, 0, 0,
56 fill=
'blue', width=4, tag=
'v_y')
65 anchor=Tkinter.W, textvariable=self.
_text_v_x)
68 anchor=Tkinter.W, textvariable=self.
_text_v_y)
70 anchor=Tkinter.W, textvariable=self.
_text_w)
73 self._text_v_x.set(
'v_x = %0.2f m/s' % self.
_v_x)
74 self._text_v_y.set(
'v_y = %0.2f m/s' % self.
_v_y)
75 self._text_w.set(
'w = %0.2f deg/s' % self.
_w)
77 self._text_v_x.set(
'v = %0.2f m/s' % self.
_v_x)
78 self._text_w.set(
'w = %0.2f deg/s' % self.
_w)
80 self._label_v_x.pack()
82 self._label_v_y.pack()
86 self._canvas.bind(
'<Button-1>', self.
_start)
87 self._canvas.bind(
'<ButtonRelease-1>', self.
_release)
89 self._canvas.bind(
'<Configure>', self.
_configure)
96 self._root.bind(
'<KeyRelease-Shift_L>',
106 period = rospy.Duration(1.0 / self.
_frequency)
111 self._root.mainloop()
115 self._timer.shutdown()
120 self.
_x, self.
_y = event.y, event.x
132 self._width, self.
_height = event.height, event.width
156 self._canvas.coords(tag, (x0, y0, x1, y1))
159 x = -v * float(self._width)
174 yaw = w * numpy.rad2deg(self.
_scale)
176 self._canvas.itemconfig(
'w', extent=yaw)
183 linear = Vector3(v_x, v_y, 0.0)
184 angular = Vector3(0.0, 0.0, w)
192 self._text_v_x.set(
'v_x = %0.2f m/s' % self.
_v_x)
193 self._text_v_y.set(
'v_y = %0.2f m/s' % self.
_v_y)
194 self._text_w.set(
'w = %0.2f deg/s' % numpy.rad2deg(self.
_w))
196 self._text_v_x.set(
'v = %0.2f m/s' % self.
_v_x)
197 self._text_w.set(
'w = %0.2f deg/s' % numpy.rad2deg(self.
_w))
199 twist = Twist(linear, angular)
200 self._pub_cmd.publish(twist)
209 dx /= float(self._width)
212 dx = max(-1.0, min(dx, 1.0))
213 dy = max(-1.0, min(dy, 1.0))
218 if self.
_y is not None:
225 if self.
_y is not None:
233 rospy.init_node(
'mouse_teleop')
237 if __name__ ==
'__main__':
240 except rospy.ROSInterruptException:
def _configure(self, event)
def _release(self, event)
def _mouse_motion_angular(self, event)
def _relative_motion(self, x, y)
def _publish_twist(self, event)
def _change_to_motion_linear(self, event)
def _change_to_motion_angular(self, event)
def _mouse_motion_linear(self, event)
def _update_coords(self, tag, x0, y0, x1, y1)