Robotics StackExchange | Archived questions

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 getnodenames() 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: getnodenames() 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.

Asked by bchurch8 on 2022-11-25 17:35:55 UTC

Comments

Answers

Adding a small sleep (15ms) after the node was created seemed to fix the issue. Think the node may have needed some time to detect other nodes on the network (see this answer), but I am not entirely sure.

Asked by bchurch8 on 2022-12-01 13:53:10 UTC

Comments