0
$\begingroup$

Rosanswers logo

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?


Originally posted by Dimitri Schachmann on ROS Answers with karma: 789 on 2015-09-22

Post score: 2


Original comments

Comment by Dimitri Schachmann on 2015-09-23:
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 using getPrivateNodeHandle().getParam("param", param). Perhaps thats engough for me, but I still wonder how it would be possible with roscpp nodlet loader only.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

To pass a parameter value to a nodelet, try either passing it as an argument on the command line when you run the executable that loads the nodelet (i.e. "_param:=value") or set the parameter using ros::param::set("~param", value).

In either case the nodelet should be able to access it using getPrivateNodeHandle().getParam("param", value).


Originally posted by dseifert with karma: 106 on 2015-10-14

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Dimitri Schachmann on 2015-10-17:
The thing is I want to start multiple nodelets with the same executable with different parameters. If I run ros::param::set(...) I'm setting the parameter for all those those nodelets, don't I?

Comment by dseifert on 2015-10-20:
I would assume each nodelet is in a different namespace, and so would be the parameters.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.