bags_to_database.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 bags_to_database.py
00004 Mac Mason <mmason@willowgarage.com>
00005 
00006 We collect bag files; we want to process them into a database. So, this does
00007 that.
00008 """
00009 
00010 import os
00011 import sys
00012 import signal
00013 import time
00014 import subprocess
00015 
00016 def handler(signum, frame):
00017   global RL
00018   global RB
00019 
00020   if RL:
00021     RL.kill()
00022   if RB:
00023     RB.kill()
00024 
00025 signal.signal(signal.SIGTERM, handler)
00026 
00027 M = "** We assume that playbag.launch will run, and record to the database\n"\
00028     "** you want it to. Starting the roscore, etc. that you need for that\n"\
00029     "** to work is your problem. Enjoy!\n"
00030 
00031 print M
00032 
00033 if len(sys.argv) < 2:
00034   print "Usage: bags_to_database.py <one or more bagfiles>"
00035   sys.exit(1)
00036 
00037 # Make sure you've given us only valid files.
00038 for filename in sys.argv[1:]:
00039   try:
00040     os.stat(filename)
00041   except OSError:
00042     print "File '" + filename + "' does not exist!"
00043 
00044 
00045 # Here's the deal. We want to fire up playbag.launch, and then rosrun
00046 # semanticmodel playbag.sh <foo>. Once the call to playbag finishes, we want
00047 # to kill the roslaunch, restart the roslaunch, and start the next playbag.
00048 
00049 for bagfile in sys.argv[1:]:
00050   global RL
00051   global RB
00052   # Start the roslaunch.
00053   RL = subprocess.Popen(['roslaunch', 
00054                          'semanticmodel', 
00055                          'go.launch',
00056                          'gui:=false',  # No gui, please.
00057                          'playbag:=true',
00058                          'run_local_db:=true',
00059                          'overwrite_local_db:=false'], 
00060                         stdin=None, stdout=None, stderr=None,
00061                         env=os.environ)
00062 
00063   print "launched for", bagfile
00064 
00065   # Give it a moment to get all sorted out.
00066   time.sleep(15.0)
00067 
00068   # Now, start the rosbag.
00069   RB = subprocess.check_call(['rosrun', 
00070                               'semanticmodel', 
00071                               'playbag.sh', 
00072                               bagfile],
00073                               stdin=None, stdout=None, stderr=None,
00074                               env=os.environ)
00075 
00076   print "played for", bagfile
00077 
00078   #time.sleep(10 * 60)  # Make sure we've caught up.
00079   time.sleep(60)  # Make sure we've caught up.
00080 
00081   # check_call waits until this finishes.
00082   RL.terminate() # No more roslaunch.
00083 
00084   # Give it more time to get all sorted out.
00085   time.sleep(15.0)
00086 
00087   # and loop!
00088 


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