Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import rospy
00019
00020 from python_qt_binding.QtCore import QSize
00021 from rqt_robot_dashboard.widgets import BatteryDashWidget
00022
00023
00024 class COBBattery(BatteryDashWidget):
00025 """
00026 Dashboard widget to display COB battery state.
00027 """
00028
00029 def __init__(self, context):
00030 """
00031 :param context: the plugin context
00032 :type context: qt_gui.plugin.Plugin
00033 """
00034 super(COBBattery, self).__init__('COB Battery')
00035 self._time_remaining = 0.0
00036 self._charging = False
00037
00038 self.setFixedSize(self._icons[1].actualSize(QSize(50, 30)))
00039
00040 self.update_perc(0)
00041
00042 def set_power_state(self, msg):
00043 """
00044 Sets button state based on msg
00045
00046 :param msg: message containing the power state of the COB
00047 :type msg: cob_msgs.PowerState
00048 """
00049 last_charging = self._charging
00050 last_time_remaining = self._time_remaining
00051
00052 self._time_remaining = msg.time_remaining
00053 self._charging = msg.charging
00054 if (last_charging != self._charging or last_time_remaining != self._time_remaining):
00055 drain_str = "remaining"
00056 if (self._charging):
00057 drain_str = "to full charge"
00058 self.charging = True
00059 self.setToolTip("Battery: %.2f%% \nTime %s: %d Minutes" % (msg.relative_remaining_capacity, drain_str, self._time_remaining * 60.0))
00060 self.update_perc(msg.relative_remaining_capacity)
00061
00062 def set_stale(self):
00063 self._charging = 0
00064 self._time_remaining = rospy.rostime.Duration(0)
00065 self.setToolTip("Battery: Stale")