Skip to content

Commit 3c7822c

Browse files
author
Enrique Fernandez
committed
Add --exclude_topics arg
1 parent 151b1bb commit 3c7822c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bag_tools/scripts/merge.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
import argparse
3636

37-
def merge(inbags, outbag='output.bag', topics=None, raw=True):
37+
def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True):
3838
# Open output bag file:
3939
try:
4040
out = rosbag.Bag(outbag, 'a')
@@ -48,7 +48,8 @@ def merge(inbags, outbag='output.bag', topics=None, raw=True):
4848
try:
4949
rospy.loginfo(' Processing input bagfile: %s', inbag)
5050
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)
5253
except IOError as e:
5354
rospy.logerr('Failed to open input bag file %s!: %s' % (inbag, e.message))
5455
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):
6566
parser.add_argument('inbag', help='input bagfile(s)', nargs='+')
6667
parser.add_argument('--output', help='output bag file', default='output.bag')
6768
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=[])
6870
args = parser.parse_args()
6971

7072
try:
71-
merge(args.inbag, args.output, args.topics)
73+
merge(args.inbag, args.output, args.topics, args.exclude_topics)
7274
except Exception, e:
7375
import traceback
7476
traceback.print_exc()

0 commit comments

Comments
 (0)