From a8cac1f196fc079dbefaa6013a1422bacf7f4411 Mon Sep 17 00:00:00 2001 From: Tim Clephas Date: Fri, 23 Aug 2024 15:03:43 +0200 Subject: [PATCH] Allow updating already sent static transforms Signed-off-by: Tim Clephas --- tf2_ros_py/tf2_ros/static_transform_broadcaster.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tf2_ros_py/tf2_ros/static_transform_broadcaster.py b/tf2_ros_py/tf2_ros/static_transform_broadcaster.py index c05a73e22..e3d4b14ce 100644 --- a/tf2_ros_py/tf2_ros/static_transform_broadcaster.py +++ b/tf2_ros_py/tf2_ros/static_transform_broadcaster.py @@ -61,8 +61,8 @@ def __init__(self, node: Node, qos: Optional[Union[QoSProfile, int]] = None) -> ) self.pub_tf = node.create_publisher(TFMessage, "/tf_static", qos) - self.net_message = TFMessage() - self._child_frame_ids = set() + # Keep a dict of transforms to avoid duplicate child_frame_ids + self.transforms = {} def sendTransform(self, transform: Union[TransformStamped, List[TransformStamped]]) -> None: if not isinstance(transform, list): @@ -72,8 +72,8 @@ def sendTransform(self, transform: Union[TransformStamped, List[TransformStamped transform = [transform] for t_in in transform: - if t_in.child_frame_id not in self._child_frame_ids: - self._child_frame_ids.add(t_in.child_frame_id) - self.net_message.transforms.append(t_in) + self.transforms[t_in.child_frame_id] = t_in - self.pub_tf.publish(self.net_message) + net_message = TFMessage() + net_message.transforms = list(self.transforms.values()) + self.pub_tf.publish(net_message)