motor_widget.py
Go to the documentation of this file.
00001 import rospy
00002 from functools import partial
00003 
00004 from kobuki_msgs.msg import MotorPower
00005 
00006 from rqt_robot_dashboard.widgets import IconToolButton
00007 from python_qt_binding.QtCore import QSize
00008 
00009 class MotorWidget(IconToolButton):
00010     def __init__(self, topic):
00011         self._pub = rospy.Publisher(topic, MotorPower, queue_size=5)
00012 
00013         self._off_icon = ['bg-red.svg', 'ic-motors.svg']
00014         self._on_icon = ['bg-green.svg', 'ic-motors.svg']
00015         self._stale_icon = ['bg-grey.svg', 'ic-motors.svg', 'ol-stale-badge.svg']
00016 
00017         icons = [self._off_icon, self._on_icon, self._stale_icon]
00018         super(MotorWidget, self).__init__(topic, icons=icons)
00019         self.setFixedSize(QSize(40,40))
00020 
00021         super(MotorWidget, self).update_state(2)
00022         self.setToolTip("Motors: Stale")
00023 
00024         self.clicked.connect(self.toggle)
00025 
00026 
00027     def update_state(self, state):
00028         if state is not super(MotorWidget, self).state:
00029             super(MotorWidget, self).update_state(state)
00030             if state is 0:
00031                 self.setToolTip("Motors: Off")
00032             else:
00033                 self.setToolTip("Motors: On")
00034 
00035     def toggle(self):
00036         if super(MotorWidget, self).state is 1:
00037             self._pub.publish(MotorPower(0))
00038         else:
00039             self._pub.publish(MotorPower(1))
00040 
00041     def close(self):
00042         self._pub.unregister()
00043  


kobuki_dashboard
Author(s): Ze'ev Klapow, Marcus Liebhardt
autogenerated on Thu Jun 6 2019 19:42:44