logger_node.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (C) 2015, Jack O'Quin
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the author nor of other contributors may be
00019 #    used to endorse or promote products derived from this software
00020 #    without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 """.. module:: logger_node
00036 
00037 This Python script runs `rosbag record` on a list of ROS topics,
00038 saving the results in an appropriate directory for use with the BWI
00039 robots.
00040 """
00041 # enable some python3 compatibility options:
00042 from __future__ import absolute_import, print_function
00043 
00044 import os
00045 import rospy
00046 import subprocess
00047 import sys
00048 
00049 from .directory import LoggingDirectory
00050 
00051 DEFAULT_PREFIX = 'bwi'
00052 
00053 
00054 def main(argv=None):
00055     """ Main function. """
00056 
00057     # create node for reading ROS parameters
00058     rospy.init_node('record')
00059 
00060     # get the topics
00061     topics = rospy.get_param('~topics', None)
00062     if topics is None or topics == "":
00063         print('error: no topics to record', file=sys.stderr)
00064         print(' usage: rosrun bwi_logging record' +
00065               ' _topics:="topic1 topic2 ..."' +
00066               ' [_directory:=""] [_prefix:="bwi"]', file=sys.stderr)
00067         return 9
00068     rospy.loginfo('topics to record: ' + topics)
00069 
00070     # configure logging directory
00071     directory = rospy.get_param('~directory', None)
00072     rospy.loginfo('~directory: ' + str(directory))
00073     logdir = LoggingDirectory(directory)
00074     rospy.loginfo('logs go here: ' + logdir.pwd())
00075     logdir.chdir()                      # change to that directory
00076 
00077     # get the file prefix
00078     prefix = rospy.get_param('~prefix', DEFAULT_PREFIX)
00079     rospy.loginfo('logging with prefix: ' + str(prefix))
00080 
00081     # this is the command we will issue:
00082     cmd = ['rosbag', 'record', '-o' + prefix, '-j']
00083     cmd.extend(topics.split())
00084     rospy.loginfo('running command: ' + str(cmd))
00085 
00086     # run the rosbag command
00087     status = subprocess.call(cmd)
00088 
00089     rospy.loginfo('rosbag returned status: ' + str(status))
00090 
00091     if status == 0 and prefix == DEFAULT_PREFIX:
00092 
00093         rospy.loginfo('start uploading bags')
00094 
00095         # In the background, begin uploading the newly-written bag to
00096         # the BWI server.  The setsid isolates the uploading scripts
00097         # from ROS shutdown signals.  The -w120 waits two minutes
00098         # before starting to upload.
00099         upload_cmd = ['/usr/bin/setsid', '/usr/local/bin/bwi',
00100                       'bags', '-w120', '-d', logdir.pwd(), prefix, '&']
00101         cmd_str = ' '.join(x for x in upload_cmd)
00102         print('running command: ' + cmd_str)
00103         os.system(cmd_str)
00104 
00105     return status
00106 
00107 if __name__ == '__main__':
00108     sys.exit(main())


bwi_logging
Author(s): Shiqi Zhang
autogenerated on Thu Jun 6 2019 17:57:20