battery_guard.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 
5 from sound_play.msg import SoundRequest
6 from sound_play.libsoundplay import SoundClient
7 
8 if __name__ == '__main__':
9  rospy.init_node('battery_guard')
10  soundclient = SoundClient()
11 
12  last_complain= rospy.Time()
13  r= rospy.Rate(.1)
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):
20  if capacity < 10:
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()
24  elif capacity < 15:
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()
28  r.sleep()


battery_guard
Author(s): Michael Goerner
autogenerated on Mon Jun 10 2019 15:49:11