Ask Your Question

Revision history [back]

A NodeHandle is an object which represents your ROS node. You usually only need one or two node handles.

ros::NodeHandle nh; //public node handle
ros::NodeHandle("~"); // private node handle

If you are a beginner then you can safely ignore the second line. Otherwise, keep in mind that all the topics, services, parameters you manipulate are resolved depending on where your node is placed in the ROS namespace hierarchy (see ROS_NAMESPACE environment variable for instance). By default the node handle will create topics, etc. in your current position but it can be overridden by giving a parameter when creating the ROS NodeHandle. The special character "~" represents your node private space where you can create communication channels without having to worry with name collision or other problems like this.

Anyway, if this is unclear for you: create only one node handle without any argument. See the roscpp tutorial for more information on this matter.

A NodeHandle is an object which represents your ROS node. You usually only need one or two node handles.

ros::NodeHandle nh; //public node handle
ros::NodeHandle("~"); ros::NodeHandle nhPrivate("~"); // private node handle

If you are a beginner then you can safely ignore the second line. Otherwise, keep in mind that all the topics, services, parameters you manipulate are resolved depending on where your node is placed in the ROS namespace hierarchy (see ROS_NAMESPACE environment variable for instance). By default the node handle will create topics, etc. in your current position but it can be overridden by giving a parameter when creating the ROS NodeHandle. The special character "~" represents your node private space where you can create communication channels without having to worry with name collision or other problems like this.

Anyway, if this is unclear for you: create only one node handle without any argument. See the roscpp tutorial for more information on this matter.