See Currently Used ROS_Domain_ID(s) ROS2 Foxy RCLCPP
Is there any way to see which Domain IDs have a ROS process running on them with Foxy RCLCPP?
Currently, trying to make it so multiple instances of my app can be open at once without interference between duplicate nodes and topics. My initial thought was on startup to check which Domain IDs were in use and then set the Domain ID to an usused value to maintain separation.
However, I'm having trouble finding a good way to check which Domain IDs are in use. Initially, I tried this, but the get_node_names() call sometimes misses existing node names on that Domain ID.
int domain = 0;
bool domain_not_set = true;
while(domain_not_set){
SetEnvironmentVariable("ROS_DOMAIN_ID", domain);
rclcpp::init(argc, argv);
auto node =std::make_shared<rclcpp::Node>("test_node");
if(node->get_node_names().size() == 1){
domain_not_set = false;
}
else{
rclcpp::shutdown();
domain++;
}
}
EDIT: get_node_names() seems to correctly return the node name list for the domain which was first initialized i.e. domain 0 in the example. However, after the first iteration of the loop, only "test_node" appears in the node name list.