How can I access NodeHandle w/ Nodelets?
Hi,
I have the following Nodelet onInit:
void OD::onInit()
{
ros::NodeHandle& private_nh = getPrivateNodeHandle();
ros::NodeHandle& nh = getNodeHandle();
NODELET_DEBUG("Initialized the Nodelet (OD)");
odom_sub = nh.subscribe("/base_odometry/odom", 10, &OD::odomCallback, this);
}
Where I have declared a nodeHandle and a privateNodeHandle. If I understood correctly, a good rule of thumb is to use the nodeHandle with Topics and the Private one with Parameters.
Well, on the odomCallback, I want check if nh.ok()
or if private_nh.ok()
, as well as private_nh.param<float>("uav_sphere_scale", scale, 1);
, but none of this work and give the error:
error: ‘nh’ was not declared in this scope
(...)
error: ‘private_nh’ was not declared in this scope
private_nh.param<float>("uav_sphere_scale", scale, 1);
On my class, OD, the onInit
was declared as public and the odomCallback as protected.
My question is, how can I access, either the NodeHandle, or the PrivateNodeHandle on my callback function?
EDIT: I already tried to declare the NodeHandlers a-priori:
namespace nodelet_obstacle_detector
{ class OD : public nodelet::Nodelet { public: virtual void onInit(); ros::NodeHandle& private_nh; ros::NodeHandle& nh;
But it shows the following error when I compile:
/home/(...)/nodelet_obstacle_detector.h:49:11: error: uninitialized reference member in ‘class nodelet_obstacle_detector::OD’
class OD : public nodelet::Nodelet
^
/home/(...)/nodelet_obstacle_detector.h:54:30: note: ‘ros::NodeHandle& nodelet_obstacle_detector::OD::nh’ should be initialized
ros::NodeHandle& nh;
Thank you in advance.