20 from std_msgs.msg
import Float64
21 from cob_msgs.msg
import PowerState
37 rospy.Subscriber(
"voltage", Float64, self.
voltage_cb)
38 rospy.Subscriber(
"current", Float64, self.
current_cb)
53 self.last_currents.pop(0)
54 self.last_currents.append(msg.data)
82 except ZeroDivisionError
as e:
83 rospy.logerr(
"ZeroDivisionError: full_charge_capacity is 0.0: %s" % (e))
89 time_remaining_max = 10.0
90 time_remaining = time_remaining_max
100 except ZeroDivisionError
as e:
101 rospy.logerr(
"ZeroDivisionError: current is 0.0: %s" % (e))
103 rospy.logwarn(
"something went wrong, cannot calculate time_remaining. full_charge_capacity=%s, remaining_capacity=%s, current=%s" % (self.
full_charge_capacity, self.
remaining_capacity, current))
108 return min(time_remaining, time_remaining_max)
122 self.pub_power_state.publish(ps)
125 if __name__ ==
"__main__":
126 rospy.init_node(
"power_state_aggregator")
128 rospy.loginfo(
"power state aggregator running")
129 rate = rospy.Rate(10)
130 while not rospy.is_shutdown():
134 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)