21 from std_msgs.msg
import Float64
22 from cob_msgs.msg
import PowerState
23 from sensor_msgs.msg
import BatteryState
41 rospy.Subscriber(
"voltage", Float64, self.
voltage_cb)
42 rospy.Subscriber(
"current", Float64, self.
current_cb)
91 except ZeroDivisionError
as e:
92 rospy.logerr(
"ZeroDivisionError: full_charge_capacity is 0.0: %s" % (e))
98 warnings.filterwarnings(
'error')
99 time_remaining_max = 10.0
100 time_remaining = time_remaining_max
114 except ZeroDivisionError
as e:
115 rospy.logerr(
"ZeroDivisionError: current is 0.0: {}".format(e))
117 rospy.logerr(
"Warning: {}".format(w))
118 except Exception
as e:
119 rospy.logerr(
"Exception: {}".format(e))
128 return min(time_remaining, time_remaining_max)
140 ps.power_consumption = power_consumption
142 ps.relative_remaining_capacity = relative_remaining_capacity
145 ps.time_remaining = time_remaining
154 bs.percentage = relative_remaining_capacity / 100.0
155 bs.power_supply_status = BatteryState.POWER_SUPPLY_STATUS_CHARGING
if self.
charging else BatteryState.POWER_SUPPLY_STATUS_NOT_CHARGING
156 bs.power_supply_health = BatteryState.POWER_SUPPLY_HEALTH_GOOD
157 bs.power_supply_technology = BatteryState.POWER_SUPPLY_TECHNOLOGY_UNKNOWN
159 bs.cell_voltage = [self.
voltage]
160 bs.location =
"emulated_battery" 161 bs.serial_number =
"emulated_battery" 166 if __name__ ==
"__main__":
167 rospy.init_node(
"power_state_aggregator")
169 rospy.loginfo(
"power state aggregator running")
170 rate = rospy.Rate(10)
171 while not rospy.is_shutdown():
175 except rospy.exceptions.ROSInterruptException
as e:
def calculate_time_remaining(self)
def full_charge_capacity_cb(self, msg)
def voltage_cb(self, msg)
def calculate_relative_remaining_capacity(self)
def calculate_power_consumption(self)
def remaining_capacity_cb(self, msg)
def current_cb(self, msg)
def temperature_cb(self, msg)