00001
00002 import serial
00003 import roslib;
00004 roslib.load_manifest('cob_battery')
00005 import rospy
00006 from diagnotic_msgs.msg import *
00007
00008 ns_global_prefix = "/battery_controller"
00009 rospy.init_node('battery_node')
00010
00011 if not rospy.has_param(ns_global_prefix + "/devicestring"):
00012 rospy.logerr("parameter %s does not exist on ROS Parameter Server, aborting...",ns_global_prefix + "/devicestring")
00013 sys.exit()
00014 devicestring_param = rospy.get_param(self.ns_global_prefix + "/devicestring")
00015 if not rospy.has_param(ns_global_prefix + "/minimum_battery_voltage"):
00016 rospy.logerr("parameter %s does not exist on ROS Parameter Server, aborting...",ns_global_prefix + "/minimum_battery_voltage")
00017 sys.exit()
00018 minvalue_param = rospy.get_param(self.ns_global_prefix + "/minimum_battery_voltage")
00019 if not rospy.has_param(ns_global_prefix + "/maximum_battery_voltage"):
00020 rospy.logerr("parameter %s does not exist on ROS Parameter Server, aborting...",ns_global_prefix + "/maximum_battery_voltage")
00021 sys.exit()
00022 maxvalue_param = rospy.get_param(self.ns_global_prefix + "/maximum_battery_voltage")
00023
00024 diagnostic_publisher = rospy.Publisher("/diagnostics", DiagnosticStatus)
00025 batcon = serial.Serial("/dev/ttyUSB2", 230400)
00026 msg = DiagnosticStatus()
00027 msg.level = 0
00028 msg.name = "battery_state"
00029 msg.message = "measuring battery voltage"
00030 valuevoltage = KeyValue()
00031 valuevoltage.key = "Voltage"
00032 valuevoltage.value = "0"
00033 msg.values.append(valuevoltage)
00034 valuepercentage = KeyValue()
00035 valuepercentage.key = "Percentage"
00036 valuepercentage.value = "0"
00037 msg.values.append(valuevoltage)
00038
00039
00040 while not rospy.is_shutdown():
00041 batcon.write("B\r")
00042 batvalue = batcon.readline()
00043 diagnostic_publisher.publish(msg)
00044
00045