Skip to content

Commit

Permalink
Added republish_tf_static.py for convenience when replaying rosbags w…
Browse files Browse the repository at this point in the history
…ith /tf_static not latched
  • Loading branch information
matlabbe committed Nov 26, 2023
1 parent 4e64747 commit 41fd09d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions rtabmap_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ install(PROGRAMS
# scripts/gazebo_ground_truth.py
scripts/transform_to_tf.py
scripts/yaml_to_camera_info.py
scripts/republish_tf_static.py
DESTINATION lib/${PROJECT_NAME}
)

Expand Down
43 changes: 43 additions & 0 deletions rtabmap_util/scripts/republish_tf_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from rclpy.qos import DurabilityPolicy
from rclpy.qos import HistoryPolicy
from rclpy.qos import QoSProfile
from tf2_msgs.msg import TFMessage

class StaticTransformRepublisher(Node):

def __init__(self):
super().__init__('static_transform_republisher')
qos = QoSProfile(
depth=1,
durability=DurabilityPolicy.TRANSIENT_LOCAL,
history=HistoryPolicy.KEEP_LAST,
)
self.publisher_ = self.create_publisher(TFMessage, '/tf_static', qos)
self.data = TFMessage()
self.subscription = self.create_subscription(
TFMessage,
'/tf_static_old',
self.listener_callback,
10)
self.subscription # prevent unused variable warning

def listener_callback(self, msg):
if len(self.data.transforms) == 0:
self.data = msg
else:
self.data.transforms = self.data.transforms + msg.transforms
self.get_logger().info('"Received /tf_static_old and republising latched /tf_static"')
self.publisher_.publish(self.data)

def main(args=None):
rclpy.init(args=args)
static_transform_republisher = StaticTransformRepublisher()
rclpy.spin(static_transform_republisher)
minimal_publisher.destroy_node()
rclpy.shutdown()

if __name__ == '__main__':
main()

0 comments on commit 41fd09d

Please sign in to comment.