34
34
35
35
import argparse
36
36
37
- def merge (inbags , outbag = 'output.bag' , topics = None , raw = True ):
37
+ def merge (inbags , outbag = 'output.bag' , topics = None , exclude_topics = [], raw = True ):
38
38
# Open output bag file:
39
39
try :
40
40
out = rosbag .Bag (outbag , 'a' )
@@ -48,7 +48,8 @@ def merge(inbags, outbag='output.bag', topics=None, raw=True):
48
48
try :
49
49
rospy .loginfo (' Processing input bagfile: %s' , inbag )
50
50
for topic , msg , t in rosbag .Bag (inbag , 'r' ).read_messages (topics = topics , raw = raw ):
51
- out .write (topic , msg , t , raw = raw )
51
+ if topic not in args .exclude_topics :
52
+ out .write (topic , msg , t , raw = raw )
52
53
except IOError as e :
53
54
rospy .logerr ('Failed to open input bag file %s!: %s' % (inbag , e .message ))
54
55
rospy .signal_shutdown ('Failed to open input bag file %s!: %s' % (inbag , e .message ))
@@ -65,10 +66,11 @@ def merge(inbags, outbag='output.bag', topics=None, raw=True):
65
66
parser .add_argument ('inbag' , help = 'input bagfile(s)' , nargs = '+' )
66
67
parser .add_argument ('--output' , help = 'output bag file' , default = 'output.bag' )
67
68
parser .add_argument ('--topics' , help = 'topics to merge from the input bag files' , nargs = '+' , default = None )
69
+ parser .add_argument ('--exclude_topics' , help = 'topics not to merge from the input bag files' , nargs = '+' , default = [])
68
70
args = parser .parse_args ()
69
71
70
72
try :
71
- merge (args .inbag , args .output , args .topics )
73
+ merge (args .inbag , args .output , args .topics , args . exclude_topics )
72
74
except Exception , e :
73
75
import traceback
74
76
traceback .print_exc ()
0 commit comments