Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 import roslib
00039 roslib.load_manifest('ocean_battery_driver')
00040 import rospy
00041 from pr2_msgs.msg import PowerState
00042 import os, sys
00043
00044 class BatteryNotifier:
00045 def __init__(self, notify_limit, state_topic, email_addresses, robot_name, mail_program):
00046 self.notify_limit = roslib.rostime.Duration(notify_limit * 60.0)
00047 rospy.init_node("battery_notifier", anonymous=True)
00048 rospy.Subscriber(state_topic, PowerState, self.update)
00049 self.email_addresses = email_addresses
00050 self.mail_program = mail_program
00051 self.robot_name = robot_name
00052 self.mail_sent = False
00053
00054 def update(self, state):
00055 if(state.time_remaining == 0 or (state.time_remaining <= self.notify_limit)):
00056 if not self.mail_sent and state.power_consumption < 0.0:
00057 self.sendEmail()
00058 self.mail_sent = True
00059 else:
00060 self.mail_sent = False
00061
00062 def sendEmail(self):
00063 mail_string = "To: "
00064 for address in self.email_addresses: mail_string += address + ", "
00065 mail_string += "\nFrom: %s@willowgarage.com" % self.robot_name
00066 mail_string += "\nSubject: Battery level on robot below %d" % self.notify_limit
00067 mail_string += "\n\nMy battery level has fallen below the notification level. You should probably think about plugging me in. \n\nThanks much,\n%s" % self.robot_name
00068
00069
00070 pipe = os.popen("%s -t" % self.mail_program, 'w')
00071 pipe.write(mail_string)
00072 pipe.close()
00073
00074 def run(self):
00075 rospy.spin()
00076
00077 if __name__ == '__main__':
00078 print >> sys.stderr, "This script is deprecated. Do not use it."
00079
00080 if len(sys.argv) < 2:
00081 notifier = BatteryNotifier(30.0, "battery_state", ["eitan@willowgarage.com"], "pre", "/usr/sbin/sendmail")
00082 else:
00083 notifier = BatteryNotifier(30.0, "battery_state", sys.argv, "pre", "/usr/sbin/sendmail")
00084
00085 notifier.run()