Hi all, I have a ROS node which inits and constructs a NodeHandle
object.
The node is run from a launch file that loads a YAML file into the parameter server.
From the main I can access correctly to the rosparam I want to load:
int main(int argc, char**argv) {
ros::init(argc, argv, "my_node");
ros::NodeHandle nh;
bool param;
// this returns true
nh.getParam("/my_param", param);
}
But if I have a class that takes this nodehandle as reference and tries to access the same parameter it does not work:
class MyClass {
public:
MyClass(ros::NodeHandle& nh) : nh_(nh) {
bool param;
// this returns false
nh_.getParam("/my_param", param);
}
private:
ros::NodeHandle& nh_;
};
int main(int argc, char**argv) {
ros::init(argc, argv, "my_node");
ros::NodeHandle nh;
// call inside constructor returns false
MyClass my_class(nh);
bool param;
// this returns true
nh.getParam("/my_param", param);
}
Why is that?
The object is passed by reference so it's the same object.
How can I get the param from within the class?
Thanks.
Originally posted by mcamurri on ROS Answers with karma: 102 on 2018-11-30
Post score: 0