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

Add nested namespace to nodes

asked 2021-03-20 15:11:46 -0600

alsora gravatar image

updated 2021-03-20 19:56:28 -0600

Hi,

I have an application where two nodes are created.

/app_ns/first_node
/second_node

As you can see, I'm specifying a namespace for one of the nodes, while the other has the default "". My goal, as the title says, is to add a namespace to both nodes, for example via command-line, but I'm open to other approaches.

What I would like to get is

/user_ns/app_ns/first_node
/user_ns/second_node

Unfortunately, the only way I know for specifying namespace is through the remapping arguments, which does not work in this case. For example I tried the following

$ ros2 run my_pkg my_app -r __ns:=/user_ns
$ ros2 node list
/user_ns/first_node
/user_ns/second_node

Do you know how could I get my desired output? I.e. how can I add/prepend a namespace while keeping whatever namespace the executable is already setting? Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-03-23 15:18:05 -0600

alsora gravatar image

updated 2021-03-23 15:37:02 -0600

gvdhoorn gravatar image

I found a solution in the ROS 2 nav stack where in the constructor of a node there is the following

Costmap2DROS::Costmap2DROS(
const std::string & name,
const std::string & parent_namespace,
const std::string & local_namespace)
  : nav2_util::LifecycleNode(name, "", true,
  // NodeOption arguments take precedence over the ones provided on the command line
  // use this to make sure the node is placed on the provided namespace
  rclcpp::NodeOptions().arguments({
  "--ros-args", "-r", std::string("__ns:=") +
  nav2_util::add_namespaces(parent_namespace, local_namespace),
  "--ros-args", "-r", name + ":" + std::string("__node:=") + name
})),

See https://github.com/ros-planning/navig...

this does not look the most elegant solution, but it's definitely working.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-03-20 15:11:46 -0600

Seen: 647 times

Last updated: Mar 23 '21