How to set and access local parameters when launching a nodelet?
I know how to set and read local a parameter using a plain node with
"_param:=value"
on the command line and
string value;
ros::param::get("~param", value)
To get the value in the code. But all my attempts to do so with a nodelet fail.
I need to add a local parameter to a nodelet I start. I though I need to add it to the my_argv
parameter:
nodelet::M_string remappings;
nodelet::V_string my_argv;
my_argv.push_back("_param:=foo");
manager.load("NodeletName", "my_namespace/NodeletClassName", remappings, my_argv);
And in the nodelet, after onInit()
in some callback I have:
std::string param;
ros::param::get("~param", param);
std::cout << "param = " << param << "." << std::endl;
Which prints param = .
. I also tried getPrivateNodeHandle().getParam("param", param)
with no success.
I guess I'm doing it completely wrong?
The background is, that I want to start load multiple nodelets of the same type but with different configurations. Perhaps there is some other canonical way for that?
When I launch the same nodelet with in a launch file, I am able to set the arguments using
args="_param:=value"
and the read them usinggetPrivateNodeHandle().getParam("param", param)
. Perhaps thats engough for me, but I still wonder how it would be possible with roscpp nodlet loader only.