I am trying to use Julia to automate an interface with a server running ROS. To do this I need to source some environment variables:
export ROS_MASTER_URI=http://xxx.xxx.xxx.xxx:xxxxx
export ROS_IP=xxx.xxx.xxx.xxx
export ROS_HOSTNAME=xxx.xxx.xxx.xxx
where the xxx’s are digits for IP addresses and port numbers.
If I run these commands in the terminal, I can thereafter run commands like rostopic list
and receive the expected output.
Running ENV["ROS_MASTER"] = "http://xxx.xxx.xxx.xxx:xxxxx"
etc. in my script and then running run(`rostopic list`)
errors out with “ERROR: Unable to communicate with master!” and a pipeline_error.
I also tried putting the export commands into my .bashrc and in my .juliarc.jl. These didn’t fix it either.
Is there something I am missing?
Thanks!
Does your script contain ENV["ROS_MASTER"]
or ENV["ROS_MASTER_URI"]
?
1 Like
I use backticks - not sure how to get those to show up in markdown
Just keep adding more backticks around the string you want to code-quote until it’s right:
``run(`rostopic list`)``
(to do the above, prepend four spaces).
And yeah, I think @schmrlng is onto something.
1 Like
I have tried setting all three variables in the script:
ENV["ROS_MASTER_URI"] = "http://xxx.xxx.xxx.xxx:xxxxx"
ENV["ROS_IP"] = "xxx.xxx.xxx.xxx"
ENV["ROS_HOSTNAME"] = "xxx.xxx.xxx.xxx"
but otherwise do not use ENV
.
Though this is not recommended (use it with causion), I shamelessly mention Shell.jl
. If it is helpful, pls report bugs or errors in the package
using Shell
Shell.run("""
export ROS_MASTER_URI=http://xxx.xxx.xxx.xxx:xxxxx
export ROS_IP=xxx.xxx.xxx.xxx
export ROS_HOSTNAME=xxx.xxx.xxx.xxx
rostopic list
""")
I get an error: “could not spawn zsh /tmp/juliawGdwxK
: no such file or directory”.
Calling Shell.run("ls")
throws the same error.
Oh, sorry. Shell.run() takes in a String, not a cmd. It works!
What do you get if you run(`env`)
? That should print all of the current environment variables. I’m unable to duplicate your issue; if the environment variables show up as you would expect them in run(`env`)
then I might double-check your ROS setup outside of julia.
schmrlng@europa ~ julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.1 (2017-10-24 22:15 UTC)
_/ |\__'_|_|_|\__'_| |
|__/ | x86_64-linux-gnu
julia> ENV["ROS_MASTER_URI"] = "http://127.0.0.1:11311"; ENV["ROS_IP"] = "127.0.0.1"; ENV["ROS_HOSTNAME"] = "127.0.0.1"
"127.0.0.1"
julia> run(`rostopic list`)
/europa
/rosout
/rosout_agg
julia> ENV["ROS_MASTER_URI"] = "http://XXX.XXX.XXX.140:11311"; ENV["ROS_IP"] = "XXX.XXX.XXX.209"; ENV["ROS_HOSTNAME"] = "XXX.XXX.XXX.209"
"XXX.XXX.XXX.209"
julia> run(`rostopic list`)
/ceres
/rosout
/rosout_agg
You may try Shell.run(..., shell="bash")
because I default the shell to zsh…
Okay, so it works in the REPL and it works in a standalone script but some other things I am running ahead of that (curl commands) cause it to not work. Seems to be a problem that I introduce.
Sorry for the false alarm.
Thanks for everyone’s input.
Yeah, looks like I just needed a sleep(1)
command.