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

ros2: How to transfer parameters between nodes from the terminal (without global parameter server)

asked 2022-11-02 07:50:07 -0500

rafaelrojas gravatar image

updated 2022-11-03 01:40:39 -0500

After two nodes have been launched, and they run independently. Is it possible to transfer a parameter from one node to the other from the terminal? For example, if I want to transfer the parameter "param_name" from Node1 to Node2, I would like to do something like

ros2 param set /Node2 param_name "$(ros2 param get /Node1 param_name)"

I need this feature because I have the following situation:

  1. I have a follow joint trajectory controller running on a real-time pc which controls a robot. This PC contains the description of the robot. This robot description can variate for several reasons beyond my control.
  2. In a second PC I run a RVIZ instance. In order to visualize the robot, I need the current robot_description available on the controllers PC.

My problem arises because I'm not able to programmatically sync the robot_description in the controller with the robot description in the RVIZ PC in a reliable and automated way.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-11-02 08:20:46 -0500

ljaniec gravatar image

I think this tutorial about ROS2 Global Parameters can help you:

In this tutorial I will show you how to create a sort of “global parameter server” node to keep ROS2 global parameters for all your other nodes.

The thing is, in ROS2, params are specific to a specific node. You set params for a node, you start the node, and if you kill the node, the params are gone ( if you don’t know how ROS2 params work, first read: how to get/set params from a node with Python and Cpp).

So, what can you do if you want to:

Keep some parameters alive for the entire duration of the application,
And have parameters that are used by multiple nodes?

Well, there is a way to solve that problem. You create a node that keeps some global parameters. When you start your application, the first thing you do is start this node, which stays alive as long as your application is alive. Then, any node you create at launch time, or at any time after that, can retrieve parameters from this “global parameter server”.

Note that doing this is not necessarily the best solution for your application. It’s actually kind of a hack, and goes in the opposite way of how ROS2 was designed. So, before you do that, be sure there is no other option.

Notes at the end are especially important:

ROS2 global parameters: good idea or not?

"If you’re starting your ROS2 application and directly implement a global parameter server, well, stop right now and think twice.

There are many debates on what’s the best way to handle “global” parameters, and one of the question you should ask first is not “how to do” but “do I need to do that for my application?”.

ROS2, by design, and for good reasons, makes you create parameters that are specific to a node. Unless you’re a true ROS expert, it might be good to try to follow the framework rules and conventions.

Here are some alternatives:

  • If that’s possible for you, you could create a variable on top of your launch file, and pass it to all of your nodes as a parameter. Thus, all nodes (at launch time) will get this parameter. However, if you manually add another node after that, it won’t be able to retrieve the parameter from a “global” source.
  • Some robots, like the turtlebot3, uses an environment variable for the robot’s name. Not necessarily what you should do, but that’s an option.
  • Instead of a global parameter node, you could have a database (for example with sqlite) containing global values.

Also, it could be interesting to look at your design choices. Maybe you have to create global parameters because of a poorly designed application. In this case it’s maybe better to work on your design instead of finding little hacks to make things work.

If you have carefully examined ... (more)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-11-02 07:50:07 -0500

Seen: 371 times

Last updated: Nov 03 '22