copy_bags_off_robot.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Periodically copies bags off robot
00004 
00005 import roslib; roslib.load_manifest('semanticmodel')
00006 import rospy
00007 import pr2_msgs.msg
00008 import sys
00009 import os
00010 import re
00011 import time
00012 import subprocess as sp
00013 
00014 INTERVAL = 60.0
00015 plugged_in = False
00016 DIR='/removable/cont_ops_world_model'
00017 
00018 def handle_power_state(m):
00019     global plugged_in
00020     plugged_in = m.AC_present > 0
00021 
00022 def possibly_copy_bags():
00023     rospy.loginfo("plugged_in = {0}".format(plugged_in))
00024     files = os.listdir(DIR)
00025     bags = [f for f in files if re.match('.*\.bag', f)]
00026     rospy.loginfo("Bags are {0}".format(bags))
00027     if bags and plugged_in:
00028         rospy.loginfo("Processing bag {0}".format(bags[0]))
00029         try:
00030             filename = '{0}/{1}'.format(DIR, bags[0])
00031             sp.check_call(['scp', '-C', filename, 'bhaskara@bab:/home/bhaskara/bags/prl'])
00032             sp.check_call(['rm', filename])
00033         except Exception as e:
00034             rospy.logerr("Error copying bag: {0}".format(e))
00035     
00036 
00037 if __name__ == '__main__':
00038     rospy.init_node('possibly_copy_bags')
00039     wait_int = int(sys.argv[1]) if len(sys.argv) > 1 else INTERVAL 
00040     sub = rospy.Subscriber('power_state', pr2_msgs.msg.PowerState,
00041             handle_power_state)
00042     while not rospy.is_shutdown():
00043         possibly_copy_bags()
00044         time.sleep(wait_int)


semanticmodel
Author(s): Julian ("Mac") Mason
autogenerated on Thu Dec 12 2013 12:39:10