From 1b8dbcd5aab58d55f6ee24ca964a8d4ea972e4f9 Mon Sep 17 00:00:00 2001 From: Kotochleb Date: Mon, 18 Mar 2024 23:52:40 +0100 Subject: [PATCH] Add private namespaces Signed-off-by: Kotochleb --- ros_gz_bridge/src/ros_gz_bridge.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ros_gz_bridge/src/ros_gz_bridge.cpp b/ros_gz_bridge/src/ros_gz_bridge.cpp index 5f477398a..e09fc2631 100644 --- a/ros_gz_bridge/src/ros_gz_bridge.cpp +++ b/ros_gz_bridge/src/ros_gz_bridge.cpp @@ -44,11 +44,20 @@ void RosGzBridge::spin() std::string config_file; this->get_parameter("config_file", config_file); const std::string ros_ns = this->get_namespace(); + const std::string ros_node_name = this->get_name(); if (!config_file.empty()) { auto entries = readFromYamlFile(config_file); for (auto & entry : entries) { - if (entry.gz_topic_name[0] != '/' && ros_ns.length() > 1) { - entry.gz_topic_name = ros_ns + '/' + entry.gz_topic_name; + if (entry.gz_topic_name[0] != '/') { + if (entry.gz_topic_name[0] == '~' && + entry.gz_topic_name[1] == '/' && + ros_node_name.length() > 1) { + entry.gz_topic_name = ros_node_name + '/' + + entry.gz_topic_name.substr(2); + } + if (ros_ns.length() > 1) { + entry.gz_topic_name = ros_ns + '/' + entry.gz_topic_name; + } } this->add_bridge(entry); }