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

Getting node name namespace from rclcpp

asked 2021-05-24 10:47:26 -0600

Hi is there a way to get to a node namespace in some clean way before that node is constructed using make shared? Processing argv doesn't seem like a good idea :/

Let's say

int main(int argc, char **argv) {
  rclcpp_init(argc, argv);
  // i want to get to the namespace and name here
  auto node = std::make_shared<MyCustomNode>();
  // currently this is the way I do this, but this is
  auto ns = node->get_namespace();
  auto name = node->get_name()
}

to get the namespace I could create some simple node, but that will collide with my desired one, when I want to get the name (I think?)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-05-24 17:36:52 -0600

updated 2021-05-24 17:48:58 -0600

I did some digging, and while there might have been something I missed, I do not believe it is possible. The function that gets the namespace at the lower level is rcl_node_get_namespace() but that still takes in a node field. Looking into its implementation does indeed require that a node exists so there's not some simplifed code you could easily rip out to find it.

Source: https://github.com/ros2/rcl/blob/b6f0...

The creation of this is called on the node rcl init functions, which then is called when a node is created. Digging in deeper leads to the RMW layer at which I stopped trying to track it. If you need to go that low level, you're not in for a good time.

Edit: Found where it remaps the namespace in rcl https://github.com/ros2/rcl/blob/b6f0... but as you can see, it relies on the global_arguments, which I believe is the global namespace potential remaps (if you're trying to find the remapped name) but that requires a valid context to exist, which is created with the node.

tl;dr: No, you need a node object to exist so that there's at least a context in the process to gather that information.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2021-05-24 10:47:26 -0600

Seen: 2,840 times

Last updated: May 24 '21