remove_leading_slashes.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 
4 # Copyright 2016 The Cartographer Authors
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 """A simple tool to remove leading slashes from frame names."""
18 
19 import argparse
20 import os
21 import rosbag
22 
23 
24 def ParseArgs():
25  argument_parser = argparse.ArgumentParser(
26  description="Removes leading slashes from frame names.")
27  argument_parser.add_argument("input", type=str, help="Input bag")
28  return argument_parser.parse_args()
29 
30 
31 def RewriteMsg(msg):
32  if hasattr(msg, "header"):
33  if msg.header.frame_id.startswith("/"):
34  msg.header.frame_id = msg.header.frame_id[1:]
35  if hasattr(msg, "child_frame_id"):
36  if msg.child_frame_id.startswith("/"):
37  msg.child_frame_id = msg.child_frame_id[1:]
38  if hasattr(msg, "transforms"):
39  for transform_msg in msg.transforms:
40  RewriteMsg(transform_msg)
41 
42 
43 def Main():
44  options = ParseArgs()
45  with rosbag.Bag(os.path.splitext(options.input)[0] + ".filtered.bag",
46  "w") as outbag:
47  for topic, msg, t in rosbag.Bag(options.input).read_messages():
48  RewriteMsg(msg)
49  outbag.write(topic, msg, msg.header.stamp if msg._has_header else t)
50 
51 
52 if __name__ == "__main__":
53  Main()


cartographer_ros
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:06:05