Skip to content

Commit 97be01b

Browse files
authored
Make sure to cache transforms in tf2_ros_py. (#634)
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]>
1 parent 1684a55 commit 97be01b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tf2_ros_py/tf2_ros/static_transform_broadcaster.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ def __init__(self, node: Node, qos: Optional[Union[QoSProfile, int]] = None) ->
6161
)
6262
self.pub_tf = node.create_publisher(TFMessage, "/tf_static", qos)
6363

64+
self.net_message = TFMessage()
65+
self._child_frame_ids = set()
66+
6467
def sendTransform(self, transform: Union[TransformStamped, List[TransformStamped]]) -> None:
6568
if not isinstance(transform, list):
6669
if hasattr(transform, '__iter__'):
6770
transform = list(transform)
6871
else:
6972
transform = [transform]
70-
self.pub_tf.publish(TFMessage(transforms=transform))
73+
74+
for t_in in transform:
75+
if t_in.child_frame_id not in self._child_frame_ids:
76+
self._child_frame_ids.add(t_in.child_frame_id)
77+
self.net_message.transforms.append(t_in)
78+
79+
self.pub_tf.publish(self.net_message)

0 commit comments

Comments
 (0)