cob_battery.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
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     #TODO When nonbutton Dashboard objects are available rebase this widget
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")


cob_dashboard
Author(s): Alexander Bubeck
autogenerated on Sun Jun 9 2019 20:20:03