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

confusing about simple ros c++ code

asked 2013-05-31 17:18:20 -0600

AdrianPeng gravatar image

updated 2014-01-28 17:16:43 -0600

ngrennan gravatar image

Hi,

I have a simple question about c++ pointer. This is the main.

int main(int argc, char** argv)
{
  ros::init(argc, argv, "joint_trajectory_action_node");
  ros::NodeHandle node;//("~");
  JointTrajectoryExecuter jte(node);

  ros::spin();

  return 0;
}

And this is part of the constructor of JointTrajectoryExecuter

public:
  JointTrajectoryExecuter(ros::NodeHandle &n) :
    node_(n),
    action_server_(node_, "joint_trajectory_action",
                   boost::bind(&JointTrajectoryExecuter::goalCB, this, _1),
                   boost::bind(&JointTrajectoryExecuter::cancelCB, this, _1),
                   false),
    has_active_goal_(false)

node_ is defined as ros::NodeHandle node_;

I don't understand "node_(n)".

Can anyone give me any hint?

Thanks!

edit retag flag offensive close merge delete

Comments

1

I think you may be referring to a initialization list

mortonjt gravatar image mortonjt  ( 2013-05-31 18:09:27 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-05-31 19:30:58 -0600

If you look at the ros::NodeHandle documentation, you can find a copy constructor that matches that signature:

ros::NodeHandle::NodeHandle(const NodeHandle &rhs)

Essentially, this creates a new NodeHandle instance that inherits a copy of all the parameters from the original NodeHandle. In the JointTrajectoryExecuter class you reference, this creates a local NodeHandle variable within the class that is a a copy of the NodeHandle created when the node is first initialized. The class can then use this local copy for handling actions, messages, etc.

In general, this isn't necessary, as all NodeHandle objects in a given node point to the same underlying object. But this version does allow the new NodeHandle to inherit the namespace of the original NodeHandle, if one was specified.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-31 17:18:20 -0600

Seen: 574 times

Last updated: May 31 '13