20 from cob_msgs.msg
import PowerState
21 from cob_phidgets.msg
import AnalogSensor
25 PHIDGET_MAX_VALUE = 999
27 PERIOD_RECORD_SIZE = 6
28 VOLTAGE_COLLECTION_TIME = 6.0
38 raise KeyError(
"Parameter \"~voltage_divider_factor\" not found on parameter server.")
55 self.voltage_bag.pop(0)
56 self.voltage_bag.append(num)
66 self.period_record.append((rospy.Time.now() - self.
last_update).to_sec())
87 for i
in range(0, len(msg.uri)):
88 if msg.uri[i] ==
"voltage":
89 voltage_raw = msg.value[i]
90 if msg.uri[i] ==
"current":
91 current_raw = msg.value[i]
93 if voltage_raw !=
None:
96 voltage = round(voltage, 3)
99 if current_raw !=
None:
120 percentage = min(percentage, 100)
121 percentage = max(percentage, 0)
136 self.pub_power_state.publish(ps)
138 if __name__ ==
"__main__":
139 rospy.init_node(
"power_state_phidget")
142 except KeyError
as e:
143 rospy.logerr(
"Shutting down: {}".format(e))
146 rospy.loginfo(
"power state phidget running")
147 rate = rospy.Rate(10)
148 while not rospy.is_shutdown():
def append_voltage_bag(self, num)
def phidget_cb(self, msg)
def calculate_power_consumption(self)
def calculate_relative_remaining_capacity(self)
def calculate_voltage(self)
float VOLTAGE_COLLECTION_TIME