23 from std_msgs.msg
import ColorRGBA
25 from cob_light.msg
import LightMode, LightModes, SetLightModeAction, SetLightModeGoal
26 from cob_light.srv
import StopLightMode, StopLightModeRequest
28 from simple_script_server
import *
47 self.
num_leds = rospy.get_param(
"~num_leds", 1)
49 if rospy.has_param(
"~color_charging"):
50 charging_color_param = rospy.get_param(
"~color_charging")
53 charging_color_param = [0.0, 1.0, 0.7, 0.4]
56 if rospy.has_param(
"~color_warning"):
57 color_warning_param = rospy.get_param(
"~color_warning")
60 color_warning_param = [1.0, 1.0, 0.0, 1.0]
63 if rospy.has_param(
"~color_error"):
64 color_error_param = rospy.get_param(
"~color_error")
67 color_error_param = [1.0, 0.0, 0.0, 1.0]
70 if rospy.has_param(
"~color_critical"):
71 color_critical_param = rospy.get_param(
"~color_critical")
74 color_critical_param = [1.0, 0.0, 0.0, 1.0]
83 if not rospy.has_param(
"~light_components"):
84 rospy.logwarn(
"parameter light_components does not exist on ROS Parameter Server")
89 self.
mode = LightMode()
90 self.
mode.priority = 8
95 if not rospy.has_param(
"~sound_components"):
96 rospy.logwarn(
"parameter sound_components does not exist on ROS Parameter Server")
100 self.
sound_critical = rospy.get_param(
"~sound_critical",
"My battery is empty, please recharge now.")
101 self.
sound_warning = rospy.get_param(
"~sound_warning",
"My battery is nearly empty, please consider recharging.")
116 action_server_name = component +
"/set_light"
119 rospy.logdebug(
"waiting for %s action server to start",action_server_name)
120 if not client.wait_for_server(rospy.Duration(5)):
122 rospy.logerr(
"%s action server not ready within timeout, aborting...", action_server_name)
124 rospy.logdebug(
"%s action server ready",action_server_name)
127 goal = SetLightModeGoal()
129 client.send_goal(goal)
130 client.wait_for_result()
131 res = client.get_result()
139 srv_server_name = component +
"/stop_mode"
141 rospy.wait_for_service(srv_server_name, timeout=2)
142 srv_proxy = rospy.ServiceProxy(srv_server_name, StopLightMode)
143 req = StopLightModeRequest()
147 except Exception
as e:
148 rospy.logerr(
"%s service failed: %s",srv_server_name, e)
153 sss.say(component, [text])
161 mode = copy.copy(self.
mode)
162 mode.mode = LightModes.FLASH
165 mode.colors.append(color)
175 mode = copy.copy(self.
mode)
176 mode.mode = LightModes.FLASH
179 mode.colors.append(color)
186 mode = copy.copy(self.
mode)
187 mode.mode = LightModes.FLASH
190 mode.colors.append(color)
209 rospy.logdebug(
'adjusting leds')
210 mode = copy.copy(self.
mode)
213 mode.mode = LightModes.CIRCLE_COLORS
214 mode.frequency = 60.0
217 for _
in range(leds):
218 mode.colors.append(color)
220 mode.mode = LightModes.BREATH
223 hue = 0.34 * (self.
power_state.relative_remaining_capacity / 100.0)
224 rgb = colorsys.hsv_to_rgb(hue, 1, 1)
225 color = ColorRGBA(rgb[0], rgb[1], rgb[2], 1.0)
227 mode.colors.append(color)
233 if __name__ ==
"__main__":
234 rospy.init_node(
"battery_monitor")