5 from sound_play.msg
import SoundRequest
8 if __name__ ==
'__main__':
9 rospy.init_node(
'battery_guard')
12 last_complain= rospy.Time()
14 while not rospy.is_shutdown():
15 with open(
'/sys/class/power_supply/BAT0/capacity')
as f:
16 capacity= int(f.readline().rstrip())
17 with open(
'/sys/class/power_supply/BAT0/status')
as f:
18 status= f.readline().rstrip()
19 if status !=
"Charging" and rospy.Time.now() - last_complain > rospy.Duration(60):
21 rospy.logerr(
"No battery power remaining. Connect the robot laptop to power immediately.")
22 soundclient.play(SoundRequest.NEEDS_PLUGGING_BADLY)
23 last_complain= rospy.Time.now()
25 rospy.logwarn(
"Only little battery power remaining. Please connect the robot laptop to power.")
26 soundclient.play(SoundRequest.NEEDS_PLUGGING)
27 last_complain= rospy.Time.now()