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

Revision history [back]

You want the publisher to be declared as a global object. You create the node handle in your start up routine/constructor and initialise the publisher from that.

 //globally defined
 ros::Publisher pub_;

 //in your constructor
 int main(int argc, char** argv){
 ...
 pub_ = nh_.advertise<PointCloud> ("points2", 1);
 ...
 }