Skip to content

Commit

Permalink
Make sure to cache transforms in tf2_ros_py. (#634)
Browse files Browse the repository at this point in the history
That way if you publish two separate transforms, they will
*both* be published (not just the latest one).  This is
a lot more intuitive and matches the behavior of the C++
static transform broadcaster.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Oct 24, 2023
1 parent 1684a55 commit 97be01b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tf2_ros_py/tf2_ros/static_transform_broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ 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()

def sendTransform(self, transform: Union[TransformStamped, List[TransformStamped]]) -> None:
if not isinstance(transform, list):
if hasattr(transform, '__iter__'):
transform = list(transform)
else:
transform = [transform]
self.pub_tf.publish(TFMessage(transforms=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.pub_tf.publish(self.net_message)

1 comment on commit 97be01b

@MatthijsBurgh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is however a breaking change. As you are not able to publish a static transform with the same child_frame_id twice. So IMO this should have been a major bump...

Please sign in to comment.