ros-tooling / topic_tools

Tools for directing, throttling, selecting, and otherwise manipulating ROS 2 topics at a meta-level.
Apache License 2.0
71 stars 33 forks source link

transform is broken with relative topics in namespaces #95

Open bmartin427 opened 9 months ago

bmartin427 commented 9 months ago

Description

The transform tool fails to properly resolve the names of topics specified as relative to a non-root namespace.

Expected Behavior

Tool runs, subscribes to /my_namespace/chatter and emits /my_namespace/xformed.

Actual Behavior

Tool stalls with:

WARNING: topic [/my_namespacechatter] does not appear to be published yet

To Reproduce

  1. ros2 run demo_nodes_cpp talker --ros-args -r __ns:=/my_namespace
  2. ros2 run topic_tools transform chatter xformed std_msgs/String "std_msgs.msg.String(data=m.data[-1])" --import std_msgs --wait-for-start --ros-args -r __ns:=/my_namespace

System (please complete the following information)

Additional context

bmartin427 commented 9 months ago

Update: it seems that relay_field also has this same problem.

christophebedard commented 9 months ago

Does it work if you do ros2 run topic_tools transform /chatter #... instead?

bmartin427 commented 9 months ago

It works if I use /my_namespace/chatter as the input topic, or /chatter works if I move the talker out of the namespace, yes.

christophebedard commented 9 months ago

Thanks for confirming. We're using rclcpp::GenericSubscription for all topic_tools nodes instead of the usual rclcpp::Subscription, so there might be an issue there.

bmartin427 commented 9 months ago

It looks to me like these lines won't work correctly if the namespace doesn't end in '/': https://github.com/ros-tooling/topic_tools/blob/iron/topic_tools/topic_tools/transform.py#L75-L77

Appending '/' to the __ns:= remapping causes other unrelated explosions though.

christophebedard commented 9 months ago

Oops sorry, I completely missed that transform is one of the Python nodes.

I thought that topic name resolution was something that's usually left to the client library implementation.