ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

See Currently Used ROS_Domain_ID(s) ROS2 Foxy RCLCPP

asked 2022-11-25 16:35:55 -0500

bchurch8 gravatar image

updated 2022-11-25 17:46:08 -0500

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;
    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;

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-12-01 12:53:10 -0500

bchurch8 gravatar image

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.

edit flag offensive delete link more

Question Tools



Asked: 2022-11-25 16:35:55 -0500

Seen: 829 times

Last updated: Dec 01 '22