Ask Your Question

share params between nodes ROS2

asked 2020-12-27 07:01:08 -0500

Wolf gravatar image

In ROS1 there you can read params from node namespace (prefixing param name with "~") and global namespace (prefixing param name with "/")

If understand the tutorials


correctly, for ROS2 every node has its own param server and name space. Params can be adjusted via launch file or command line. However, regardles of the prefix in cpp code, the node will query its own namespace.

Now, what would be the recommended pattern if 2 cpp nodes shall share a common parameter that must be known to both of them? Is there any way to avoid having 2 parameters in different namespaces with the same value?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-12-27 21:01:28 -0500

tfoote gravatar image

The parameter can be queried from a remote node. So you can choose one node to be the primary one and then query the remote parameter from that node from the other nodes.

edit flag offensive delete link more


What if there is no logical choice for a primary node?

gvdhoorn gravatar image gvdhoorn  ( 2020-12-28 02:38:21 -0500 )edit

That's outside the scope of the question where they "shall share a common parameter that must be known to both of them". But for completeness if they can both operate independently then I wouldn't consider the parameters redundant and then you should be willing to set them both.

tfoote gravatar image tfoote  ( 2020-12-28 15:23:28 -0500 )edit

Two nodes sharing a common parameter does not necessarily mean there is a natural choice for a primary node. They could both (or there could be more) duplicates, none of which is the primary one.

I don't understand how this is out-of-scope here, as you suggested "choose one node to be the primary one", on which your answer hinged. My question seems to follow logically: what if that's not possible.

From your comment it would appear you suggest setting all shared parameters on all nodes in that case.

That's ok, but would seem to be a different answer and something the OP seems to like to avoid having to do.

gvdhoorn gravatar image gvdhoorn  ( 2020-12-29 01:56:52 -0500 )edit

"There's no logical choice" is a hypothetical catch 22, if there's no logical solution there cant be a solution. However if they are indistinguishable or equal then you as the deployer can choose one to be primary. You don't have to make A reference B and B reference A and be fully symmetrical.

If there are two nodes which are exact duplicates you can choose to make one primary, which is the one you'll address and the other one secondary which will reference the primary one.

Alternatively you could choose to have a third node which manages the common parameters specifically for the original two nodes to share references to. This third node would need to have the semantics of the parameters understood, but it could also understand more of the semantics of the coordination too which might be different than running the nodes in standalone ...(more)

tfoote gravatar image tfoote  ( 2021-05-22 01:58:50 -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



Asked: 2020-12-27 07:01:08 -0500

Seen: 108 times

Last updated: Dec 27 '20