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

Mux node `__none` topic not working as expected #110

Closed adamlm closed 2 weeks ago

adamlm commented 1 month ago

Description

The mux node does not properly unsubscribe from its previous subscription when switching to the __none topic. This issue allows downstream subscriptions to continue receiving messages even though they shouldn't.

Expected Behavior

When selecting the __none topic through a service call, the mux node unsubscribes from its previous topic, meaning no messages get forwarded downstream.

Actual Behavior

When selecting the __none topic though a service call, the mux node maintains its previous subscription, forwarding incoming messages downstream.

To Reproduce

  1. Open four terminals

  2. In terminal 1, start the talker node from demo_nodes_cpp

    ros2 run demo_nodes_cpp talker
  3. In terminal 2, start the mux node

    ros2 run topic_tools mux input_topics /chatter
  4. In terminal 3, start the listener node from the demo_nodes_cpp package with a topic remapping

    ros2 run demo_nodes_cpp listener --ros-args -r /chatter:=/input_topics
  5. Observe that the listener node receives messages from the talker node.

  6. In terminal 4, send a service call to select the __none topic

    
    ros2 service call /mux/select topic_tools_interfaces/srv/MuxSelect "{topic: '__none'}"
  7. Observe that the service call succeeded, the mux node acknowledged the selection change, but the listener node still receives messages from the talker node.

System (please complete the following information)

Additional context

I want to use the mux node in a three-input configuration. Two inputs would subscribe to used topics, and the third "subscription" would be to the __none topic. From my understanding, the mux node was designed to support this.

I believe the issue stems from a missing ToolBaseNode::make_subscribe_unsubscribe_decisions() function call. It seems like the call should happen in on_mux_select() after updating input_topic_ = NONE_TOPIC.

I'm more than happy to apply the fix.