6 Enrique Fernandez Perdomo 7 Clearpath Robotics, Inc. 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions are met: 12 * Redistributions of source code must retain the above copyright 13 notice, this list of conditions and the following disclaimer. 14 * Redistributions in binary form must reproduce the above copyright 15 notice, this list of conditions and the following disclaimer in the 16 documentation and/or other materials provided with the distribution. 17 * Neither the name of Systems, Robotics and Vision Group, University of 18 the Balearican Islands nor the names of its contributors may be used to 19 endorse or promote products derived from this software without specific 20 prior written permission. 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 from __future__
import print_function
42 def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True):
45 out = rosbag.Bag(outbag,
'a' if os.path.exists(outbag)
else 'w')
47 print(
'Failed to open output bag file %s!: %s' % (outbag, e.message), file=sys.stderr)
53 print(
' Processing input bagfile: %s' % inbag)
54 for topic, msg, t
in rosbag.Bag(inbag,
'r').read_messages(topics=topics, raw=raw): 55 if topic
not in args.exclude_topics:
56 out.write(topic, msg, t, raw=raw)
58 print(
'Failed to open input bag file %s!: %s' % (inbag, e.message), file=sys.stderr)
66 if __name__ ==
"__main__":
67 parser = argparse.ArgumentParser(
68 description=
'Merge multiple bag files into a single one.')
69 parser.add_argument(
'inbag', help=
'input bagfile(s)', nargs=
'+')
70 parser.add_argument(
'--output', help=
'output bag file', default=
'output.bag')
71 parser.add_argument(
'--topics', help=
'topics to merge from the input bag files', nargs=
'+', default=
None)
72 parser.add_argument(
'--exclude_topics', help=
'topics not to merge from the input bag files', nargs=
'+', default=[])
73 args = parser.parse_args()
76 sys.exit(
merge(args.inbag, args.output, args.topics, args.exclude_topics))
def merge(inbags, outbag='output.bag', topics=None, exclude_topics=[], raw=True)