ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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);
...
}