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 """.. 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
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
00058 rospy.init_node('record')
00059
00060
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
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()
00076
00077
00078 prefix = rospy.get_param('~prefix', DEFAULT_PREFIX)
00079 rospy.loginfo('logging with prefix: ' + str(prefix))
00080
00081
00082 cmd = ['rosbag', 'record', '-o' + prefix, '-j']
00083 cmd.extend(topics.split())
00084 rospy.loginfo('running command: ' + str(cmd))
00085
00086
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
00096
00097
00098
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())