motor_widget.py
Go to the documentation of this file.
1 import rospy
2 from functools import partial
3 
4 from kobuki_msgs.msg import MotorPower
5 
6 from rqt_robot_dashboard.widgets import IconToolButton
7 from python_qt_binding.QtCore import QSize
8 
9 class MotorWidget(IconToolButton):
10  def __init__(self, topic):
11  self._pub = rospy.Publisher(topic, MotorPower, queue_size=5)
12 
13  self._off_icon = ['bg-red.svg', 'ic-motors.svg']
14  self._on_icon = ['bg-green.svg', 'ic-motors.svg']
15  self._stale_icon = ['bg-grey.svg', 'ic-motors.svg', 'ol-stale-badge.svg']
16 
17  icons = [self._off_icon, self._on_icon, self._stale_icon]
18  super(MotorWidget, self).__init__(topic, icons=icons)
19  self.setFixedSize(QSize(40,40))
20 
21  super(MotorWidget, self).update_state(2)
22  self.setToolTip("Motors: Stale")
23 
24  self.clicked.connect(self.toggle)
25 
26 
27  def update_state(self, state):
28  if state is not super(MotorWidget, self).state:
29  super(MotorWidget, self).update_state(state)
30  if state is 0:
31  self.setToolTip("Motors: Off")
32  else:
33  self.setToolTip("Motors: On")
34 
35  def toggle(self):
36  if super(MotorWidget, self).state is 1:
37  self._pub.publish(MotorPower(0))
38  else:
39  self._pub.publish(MotorPower(1))
40 
41  def close(self):
42  self._pub.unregister()
43 


kobuki_dashboard
Author(s): Ze'ev Klapow, Marcus Liebhardt
autogenerated on Mon Jun 10 2019 13:52:52