[Documentation] [TitleIndex] [WordIndex

(訳注:最新の情報は原文を参照してください.)

ノードハンドルからプライベートネームで接続する

Why not just ~name?

The introduction of NodeHandles in roscpp created something of a conundrum when dealing with private names. If I create a NodeHandle with its own namespace:

   1 ros::init(argc, argv, "my_node_name");
   2 ros::NodeHandle nh("/my_node_handle_namespace");

Where should a private name resolve? Some options would be:

For this reason, NodeHandle does not allow passing private names directly to its methods, or to constructors that take a NodeHandle as an argument.

Accessing Private Names

The solution is to construct a NodeHandle with a private name as its namespace:

   1 ros::init(argc, argv, "my_node_name");
   2 ros::NodeHandle nh1("~");
   3 ros::NodeHandle nh2("~foo");

nh1's namespace is /my_node_name, and nh2's namespace is /my_node_name/foo.

So instead of doing this:

   1 ros::NodeHandle nh;
   2 nh.getParam("~name", ... );

You do this:

   1 ros::NodeHandle nh("~");
   2 nh.getParam("name", ... );


2024-11-09 14:35