ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Using the same node twice

asked 2014-03-31 05:05:19 -0500

Maya gravatar image

updated 2016-10-24 09:02:43 -0500

ngrennan gravatar image

Hellows,

Another designing question under ROS. I have a node that I programmed, it used param from the Param Server and subscribe to a topic and publish two topics.

I wish to launch to node twice using a launch file. All my parameters arr in yaml file. But I can't find any way for the code in C++ to go search the parameters in two different namespace without compiling two executable with just the namespace of difference in the getParam() function and it really is not optimal.

For now my function look like :

my_node.param<std::string>("/namespace1/source",source, "camera/rgb/image");

Is there any way to not need the name space hard coded ?

[EDIT]

I'll try to be more precise :).

For example I use the <remap> tag to remap the topic that are given by the two nodes. So I have "topic1" and "topic2". That is ok.

But now I want to publish parameters which have the same name but associated to each node. Let's say a parameter name /source for each of the node but under the namespace Node1/source, Node/source. This can be done with the launch file, I just need to load two yaml file or so. But now for now, my code to get in the param in my C++ code is like this

my_node.param<std::string>("/Node1/source",source, "camera/rgb/image");

for the first one

my_node.param<std::string>("/Node2/source",source, "camera/rgb/image");

for the second one.

I'm wondering if there is a way to right

my_node.param<std::string>("/source",source, "camera/rgb/image");

And the node would understand by itself that it's either Node1/source or Node2/source that they need.

Hope I have been clearer. Thanks a lot =)

edit retag flag offensive close merge delete

Comments

It's definitely possible. Can you be more concrete on what your resulting setup should look like, i.e. which topics would you like to have for each node and where should the names come from? It looks to me as if you might not need any parameters and can do everything from launch files.

dornhege gravatar image dornhege  ( 2014-03-31 05:14:44 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-03-31 05:41:41 -0500

demmeln gravatar image

Is this about each node accessing it's own parameters (not another node's)? In that case you should use 'private parameters' such that your code is agnostic about the actual node name and even additional layers of namespaces:

http://wiki.ros.org/roscpp/Overview/P...

edit flag offensive delete link more

Comments

I used private parameters. This is exactly what I was searching for for. Thanks @demmeln and @dornhege

Maya gravatar image Maya  ( 2014-03-31 05:52:21 -0500 )edit
2

answered 2014-03-31 06:02:42 -0500

dornhege gravatar image

Fix that:

my_node.param<std::string>("/source",source, "camera/rgb/image");

to (no "/"!)

my_node.param<std::string>("source",source, "camera/rgb/image");

If your my_node nodehandle is a private nodehandle, it will load the different private parameters.

Given that this looks like a parameter for a topic, there are probably better ways to do this that do not require loading parameters at all.

edit flag offensive delete link more

Comments

I'll use the same syntax for other parameter like where to load a model. For the topic parameter I will change it to a default value that need to be remap in the launcher would it be better ?

Maya gravatar image Maya  ( 2014-03-31 18:55:14 -0500 )edit
2

That's usually the simpler way.

dornhege gravatar image dornhege  ( 2014-03-31 21:39:17 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-03-31 05:05:19 -0500

Seen: 2,936 times

Last updated: Mar 31 '14