Dynamically pass ROS_MASTER_URI to remote machines
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!
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?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
.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).
I used
roslaunch
because of theremote_machine
tag. Do I understand your suggestion right, that first I connect viassh
to target machine and then run arosrun
with__master
argument? That sounds good. Myroslaunch
is basically just a wrapper torosnode
. It is only a pity, that theroslaunch
cannot handle this by default, that would be an elegant solution.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.
I'm actually confused (probably misremembering things), but doesn't
roslaunch
automatically pass the value ofROS_MASTER_URI
to remote processes? These lines seem to suggest it does. Have you tried not settingROS_MASTER_URI
in theenv-loader
?It's been a while since I've done this, so I may be wrong.
You'd get output like:
on the machine where you start
roslaunch
.This sounds reasonable, I will test it. If it is true, then I was pretty stupid to overcomplicate things for myself...
As I wrote: it's been too long, so I may well be misremembering.