Ask Your Question
2

How to set and access local parameters when launching a nodelet?

asked 2015-09-22 04:53:39 -0500

Dimitri Schachmann gravatar image

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?

edit retag flag offensive close merge delete

Comments

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.

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2015-09-23 10:29:07 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-10-14 01:22:37 -0500

dseifert gravatar image

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).

edit flag offensive delete link more

Comments

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?

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2015-10-17 05:55:34 -0500 )edit

I would assume each nodelet is in a different namespace, and so would be the parameters.

dseifert gravatar image dseifert  ( 2015-10-20 03:13:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-09-22 04:53:39 -0500

Seen: 2,174 times

Last updated: Sep 22 '15