# How to use namespaces?

**URL:** <https://discourse.openrobotics.org/t/how-to-use-namespaces/2236>\
**Category:** ROS General\
**Tags:** kinetic, ros2\
**Created:** [July 18, 2017, 7:38pm UTC](https://discourse.openrobotics.org/t/how-to-use-namespaces/2236 "2017-07-18T19:38:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mch](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mch/32/846_2.png) [@mch](https://discourse.openrobotics.org/u/mch)\
**Post date:** [July 18, 2017, 7:38pm UTC](https://discourse.openrobotics.org/t/how-to-use-namespaces/2236/1 "2017-07-18T19:38:28Z")

</div>

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 [Topic and Service name mapping to DDS](http://design.ros2.org/articles/topic_and_service_names.html#fully-qualified-names) 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?

---

<div class="post-metadata">

**Author:** ![wjwwood](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/wjwwood/32/13715_2.png) [@wjwwood](https://discourse.openrobotics.org/u/wjwwood)\
**Post date:** [July 18, 2017, 8:24pm UTC](https://discourse.openrobotics.org/t/how-to-use-namespaces/2236/2 "2017-07-18T20:24:40Z")

</div>

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

> <https://github.com/ros2/rcl/blob/release-beta2/rcl/test/rcl/test_expand_topic_name.cpp#L131-L158>

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

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

```

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

---

<div class="post-metadata">

**Author:** ![mch](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/mch/32/846_2.png) [@mch](https://discourse.openrobotics.org/u/mch)\
**Post date:** [July 18, 2017, 8:31pm UTC](https://discourse.openrobotics.org/t/how-to-use-namespaces/2236/3 "2017-07-18T20:31:48Z")

</div>

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.
