remove_leading_slashes.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # -*- coding: utf-8 -*-
00003 
00004 # Copyright 2016 The Cartographer Authors
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #    http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 """A simple tool to remove leading slashes from frame names."""
00018 
00019 import argparse
00020 import os
00021 import rosbag
00022 
00023 
00024 def ParseArgs():
00025   argument_parser = argparse.ArgumentParser(
00026       description="Removes leading slashes from frame names.")
00027   argument_parser.add_argument("input", type=str, help="Input bag")
00028   return argument_parser.parse_args()
00029 
00030 
00031 def RewriteMsg(msg):
00032   if hasattr(msg, "header"):
00033     if msg.header.frame_id.startswith("/"):
00034       msg.header.frame_id = msg.header.frame_id[1:]
00035   if hasattr(msg, "child_frame_id"):
00036     if msg.child_frame_id.startswith("/"):
00037       msg.child_frame_id = msg.child_frame_id[1:]
00038   if hasattr(msg, "transforms"):
00039     for transform_msg in msg.transforms:
00040       RewriteMsg(transform_msg)
00041 
00042 
00043 def Main():
00044   options = ParseArgs()
00045   with rosbag.Bag(os.path.splitext(options.input)[0] + ".filtered.bag",
00046                   "w") as outbag:
00047     for topic, msg, t in rosbag.Bag(options.input).read_messages():
00048       RewriteMsg(msg)
00049       outbag.write(topic, msg, msg.header.stamp if msg._has_header else t)
00050 
00051 
00052 if __name__ == "__main__":
00053   Main()


cartographer_ros
Author(s): The Cartographer Authors
autogenerated on Wed Jul 10 2019 04:10:28