Dynamically pass ROS_MASTER_URI to remote machines

asked 2021-02-17 03:13:12 -0500

m.bahno gravatar image

I am running a node on remote machine:

<machine name="remote_machine" address="robot_x" env-loader="env.sh" user="user"/>

However, I may run it from different host machines (robot1, robot2, ...), where ROS master runs (of course only from one at a time). I am able to set most of my environmental variables by env-loader, however I am not able to find an elegant solution to pass ROS_MASTER_URI (or host name) to the remote machine dynamically, only hardcoded in the .sh file.

I am running ROS noetic on Ubuntu 20, so I am not able to use <env> tag for passing host ROS_MASTER_URI. I think it should be possible to do it otherwise, but right now I see no other way.

Thanks for any suggestions!

edit retag flag offensive close merge delete

Comments

May be not an efficient solution but how about creating a file in one pc which have information of the ROS_MASTER_URI and all other look into this file who is the master?

Tahir M. gravatar image Tahir M.  ( 2021-02-17 04:57:42 -0500 )edit

Thanks for suggestion! But I have also multiple possible remote machines, so preferably I would like to have a solution, which works for any combination of host and remote. Thus, I cannot have a central one for storing ROS_MASTER_URI.

m.bahno gravatar image m.bahno  ( 2021-02-17 10:14:40 -0500 )edit
1

If you're not limited to roslaunch, there is a special command line argument which can be passed to nodes called __master.

You'd set this to the master's URI, and that node would use that value.

It would still be a value which is initialised once though, I don't know whether that would be sufficient seeing as you write "dynamically passing" (which could also mean: be able to update it at runtime).

gvdhoorn gravatar image gvdhoorn  ( 2021-06-16 06:49:38 -0500 )edit

I used roslaunch because of the remote_machine tag. Do I understand your suggestion right, that first I connect via ssh to target machine and then run a rosrun with __master argument? That sounds good. My roslaunch is basically just a wrapper to rosnode. It is only a pity, that the roslaunch cannot handle this by default, that would be an elegant solution.

It would still be a value which is initialised once though, I don't know whether that would be sufficient seeing as you write "dynamically passing" (which could also mean: be able to update it at runtime).

I meant the value is set dynamically based on computer, from which it is called, but once for a whole ROS run, so this is valid approach.

m.bahno gravatar image m.bahno  ( 2021-06-17 01:25:11 -0500 )edit

I'm actually confused (probably misremembering things), but doesn't roslaunch automatically pass the value of ROS_MASTER_URI to remote processes? These lines seem to suggest it does. Have you tried not setting ROS_MASTER_URI in the env-loader?

It's been a while since I've done this, so I may be wrong.

You'd get output like:

launching remote roslaunch child with command: [env ROS_MASTER_URI=<value_from_where_roslaunch_is_invoked> /opt/ros/.../env.sh roslaunch -c ... -u ... --run_id ...]

on the machine where you start roslaunch.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-17 02:13:51 -0500 )edit

This sounds reasonable, I will test it. If it is true, then I was pretty stupid to overcomplicate things for myself...

m.bahno gravatar image m.bahno  ( 2021-06-17 02:48:04 -0500 )edit

As I wrote: it's been too long, so I may well be misremembering.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-17 03:07:58 -0500 )edit