Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ros_gz_bridge/src/parameter_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ int main(int argc, char * argv[])
bridge_node->declare_parameter<bool>("lazy", false);
bridge_node->get_parameter("lazy", lazy_subscription);

bool expand_gz_topic_names = false;
bridge_node->get_parameter("expand_gz_topic_names", expand_gz_topic_names);
std::string ns = bridge_node->get_namespace();

const std::string delim = "@";
const std::string delimGzToROS = "[";
const std::string delimROSToGz = "]";
Expand All @@ -102,6 +106,21 @@ int main(int argc, char * argv[])
config.gz_topic_name = arg.substr(0, delimPos);
arg.erase(0, delimPos + delim.size());

if (expand_gz_topic_names) {
std::string gz_topic = config.gz_topic_name;
// Strip leading slash from the topic to prevent double slashes (e.g., /demo//chatter)
if (!gz_topic.empty() && gz_topic.front() == '/') {
gz_topic.erase(0, 1);
}

// Safely append the namespace
if (ns == "/") {
config.gz_topic_name = "/" + gz_topic;
} else {
config.gz_topic_name = ns + "/" + gz_topic;
}
}

// Get the direction delimiter, which should be one of:
// @ == bidirectional, or
// [ == only from GZ to ROS, or
Expand Down