ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

How to use namespaces?

Operating System: Linux Mint = Ubuntu 16.04
Installation type: from source
Version or commit hash: release-beta2
DDS implementation: Fast-RTPS
Client library (if applicable): boost, restcpp

I’ve read this article and generally I realized how namespaces works.

However some practical questions are unclear. Do I need to add namespace manually when I crate a client for the lifecycle service OR system does that for me?

e.g. previously I had

communicationNode.createClient(nodeName + "__get_state");

in ROS2 beta2 it doesn’t work any more (rclcpp::client::ClientBase::wait_for_service() always ended by timeout).

I tried those options

communicationNode.createClient('/' + namespace + '/' + nodeName + "__get_state");
communicationNode.createClient("/rq/" + namespace + '/' + nodeName + "__get_state");

none of them doesn’t seem to work as well.

Could you hint me what is the right way to call lifecycle “__get_state” service now?

Namespaces are expanded for you automatically. You can see some examples here:

In your particular case, you might need to know the target node’s name and do something like this:

communicationNode.createClient("/" + nodeName + "/get_state");

But I’m not 100% sure without seeing what you’re doing exactly.

1 Like

Yeap. It works this way.

communicationNode.createClient("/" + nodeName + "/get_state");

I guess it was all about ‘/’ instead of ‘__’ used formerly.

Thank you for prompt response and useful samples.