From f72a3e5eaeb125f01e654b3dc67bb64b027e97d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Gonz=C3=A1lez=20Hern=C3=A1ndez?= Date: Tue, 3 Nov 2026 14:04:26 +0100 Subject: [PATCH] fix(behaviortree_ros2): use groot2_port for the legacy debugger ports groot2_port was passed as the message rate of PublisherZMQ, so every executor bound the default ports 1666 and 1667 and a second executor on the same host aborted every goal with 'Address already in use'. Use groot2_port as the server port and groot2_port - 1 as the publisher port; the default 1667 keeps 1666 and 1667. Co-Authored-By: Claude Opus 5.5 --- behaviortree_ros2/src/bt_executor_parameters.yaml | 4 ++-- behaviortree_ros2/src/tree_execution_server.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/behaviortree_ros2/src/bt_executor_parameters.yaml b/behaviortree_ros2/src/bt_executor_parameters.yaml index 7008953..5bc05ca 100644 --- a/behaviortree_ros2/src/bt_executor_parameters.yaml +++ b/behaviortree_ros2/src/bt_executor_parameters.yaml @@ -33,9 +33,9 @@ bt_server: type: int, default_value: 1667, read_only: true, - description: "Server port value to publish Groot2 messages on", + description: "Server port of the legacy debugger; its publisher uses groot2_port - 1", validation: { - bounds<>: [1, 49151] + bounds<>: [2, 49151] } } plugins: { diff --git a/behaviortree_ros2/src/tree_execution_server.cpp b/behaviortree_ros2/src/tree_execution_server.cpp index c5cdaa2..741d361 100644 --- a/behaviortree_ros2/src/tree_execution_server.cpp +++ b/behaviortree_ros2/src/tree_execution_server.cpp @@ -215,7 +215,11 @@ void TreeExecutionServer::execute( // Create shared_ptr to p_->tree without deleting capabilities auto non_deleting_tree_ptr = std::shared_ptr(&(p_->tree), [](BT::Tree*){ /* do nothing */ }); BT::DebuggableTree debugTree{non_deleting_tree_ptr, true, debug_flag}; - BT::PublisherZMQ publisher(debugTree, p_->params.groot2_port); + // The second argument of PublisherZMQ is the message rate, so the ports are passed explicitly: groot2_port is the + // server port and groot2_port - 1 the publisher port (1666 and 1667 by default). Two executors on one host need + // different values. + const auto groot2_port = static_cast(p_->params.groot2_port); + BT::PublisherZMQ publisher(debugTree, 25, groot2_port - 1, groot2_port); // Optional protocol-2 endpoint, independent of the existing Eurecat debugger. // Scope ensures destruction before the next goal replaces p_->tree. @@ -223,8 +227,8 @@ void TreeExecutionServer::execute( if(p_->params.enable_bt_viewer) { const auto port = p_->params.bt_viewer_port; - // The legacy publisher above uses its default ports 1666 and 1667. - if(port <= 1667 && port + 1 >= 1666) + // The legacy publisher above uses groot2_port - 1 and groot2_port. + if(port <= p_->params.groot2_port && port + 1 >= p_->params.groot2_port - 1) { RCLCPP_WARN(kLogger, "BT viewer ports overlap legacy debugger; viewer disabled"); }