Ask Your Question

How to Implement Global Ros Variables

asked 2020-10-13 11:28:38 -0500

fruitbot gravatar image

I am working on a stationary pick-and-place type robot. I have created a large catkin workspace for a project that uses various packages. Currently, when I want to change certain variables in my project (like camera location), I need to open multiple packages and edit files individually. I want to streamline the project by creating a configuration file that holds global variables for the entire workspace (so they only need to be edited in one place).

Is this possible to do in ROS? Any suggestions would be appreciated!

edit retag flag offensive close merge delete



Currently, when I want to change certain variables in my project (like camera location), I need to open multiple packages and edit files individually

are you not using TF?

Edit: reason I ask this and don't directly address your question is I'm wondering whether this is an xy-problem. If you could give a few more examples of the sort of data you're looking to share, perhaps we can give better answers.

gvdhoorn gravatar image gvdhoorn  ( 2020-10-13 12:17:43 -0500 )edit

Yes I am using TF. I realize I wasn't clear in my original question. For each variable I want to change, there is only ONE corresponding file I need to edit. When my physical set up changes, say I set up the robot in a new area, I need to edit quite variables, and therefore quite a few files. In addition to camera location, there are multiple bins that the arm sorts items in to, whose position and size may change. Workspace area may change size. Most of the edits take place in my main urdf, but a couple are in other places. Perhaps I should edit my urdfs so all the configurable information is my main urdf?

The reason I was hoping to make some sort of global configuration file is because other people will be setting up my project and I want to make configuration as easy ...(more)

fruitbot gravatar image fruitbot  ( 2020-10-13 12:54:41 -0500 )edit

Edit: IP address for robotic arm is another variable, one that is not urdf related. Another is camera path location (eg. /dev/video0, /dev/video1)

fruitbot gravatar image fruitbot  ( 2020-10-13 13:11:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-14 04:05:35 -0500

gvdhoorn gravatar image

updated 2020-10-14 04:08:11 -0500

Given the types of data you mention, I would suggest to use the ROS parameter server for this.

The roslaunch rosparam tag in combination with .yaml files makes for a very convenient way to store and load settings of a ROS application. Example:

  device: /dev/video0
  area: [0.1, 0.3, 0.2, 0.4]
 - id: 1
   area: [0.1, 0.3, 0.2, 0.4]
 - id: 4


Whether you load those parameters in the private namespace of nodes, or put them in a separate namespace and then have nodes load "their section" from that namespace would be a design decision only you can make (the former would reduce coupling though, so might perhaps be a better approach).

One thing I'm still wondering about: if you have to edit multiple files "when things change", this may be an indication of a violation of separation of concerns (ie: too many nodes/classes/functions need to be aware of various details to be able to do their work). It may be good to investigate whether all those entities actually need all that information, or whether they could get it from somewhere else (as part of a service request coming in, fi).

edit flag offensive delete link more


The ROS parameter server looks like the tool I need. I will continue to look into it.

Your concern about "separation of concerns" may be valid. This project is my first experience with ROS, so I will keep an eye out for that as I and clean things up.

Thanks for your help!

fruitbot gravatar image fruitbot  ( 2020-10-14 11:05:39 -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-10-13 11:27:05 -0500

Seen: 69 times

Last updated: Oct 14 '20