0
$\begingroup$

Rosanswers logo

Hello, I have ubuntu 14.04 , Ros indigo and Gazebo 2.2.6. I am running a gazebo_ros_control simulation, a simple robot with two movable joints. I can move the robot with rostopic commands. The problem is, that I am trying to publish messages to the topics from another program running in the same PC, but I get the following error:

 ROS_MASTER_URI is not defined in the environment. Either type the following or (preferrably) add this to your ~/.bashrc 
 file in order set up your local machine as a ROS master:
 
 export ROS_MASTER_URI=http://localhost:11311
 
 then, type 'roscore' in another shell to actually launch the master program.

I have set ROS_MASTER_URI and ROS_IP to my .bashrc file and sourced it. I have tried setting ROS_MASTER_URI and ROS_HOSTNAME. I have tried setting all three of them. I have tried using "192.168.1.2 " instead of "localhost". I have tried to echo the variables and I get the expected result. Ι even tried to format my pc and reinstall everything, in case of broken packages. I always get the same error. What could be the problem?


edit: The output of env | grep -i ros | sort

ROS_ROOT=/opt/ros
ROS_PACKAGE_PATH=/home/sofia/catkin_ws/src:/home/sofia/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
ROS_MASTER_URI=http://192.168.1.2:11311
LD_LIBRARY_PATH=/home/sofia/catkin_ws/devel/lib:/opt/ros/indigo/lib
CPATH=/home/sofia/catkin_ws/devel/include:/opt/ros/indigo/include
PATH=/opt/ros/bin:/opt/ros/indigo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
ROSLISP_PACKAGE_DIRECTORIES=/home/sofia/catkin_ws/devel/share/common-lisp
ROS_DISTRO=indigo
PYTHONPATH=/home/sofia/catkin_ws/devel/lib/python2.7/dist-packages:/opt/ros/indigo/lib/python2.7/dist-packages
ROS_IP=192.168.1.2
PKG_CONFIG_PATH=/home/sofia/catkin_ws/devel/lib/pkgconfig:/opt/ros/indigo/lib/pkgconfig
CMAKE_PREFIX_PATH=/home/sofia/catkin_ws/devel:/opt/ros/indigo
ROS_ETC_DIR=/opt/ros/indigo/etc/ros

the lines I added to .bashrc

source /opt/ros/indigo/setup.bash
source ~/catkin_ws/devel/setup.bash
export GAZEBO_MODEL_PATH=/home/sofia/catkin_ws/src/
export GAZEBO_PLUGIN_PATH=$PWD:$GAZEBO_PLUGIN_PATH
export ROS_PACKAGE_PATH=/home/sofia/catkin_ws/src:$ROS_PACKAGE_PATH
export ROS_ROOT=/opt/ros
export PATH=$ROS_ROOT/bin:$PATH
export ROS_MASTER_URI=http://192.168.1.2:11311
export ROS_IP=192.168.1.2 
export ROS_HOSTNAME=192.168.1.2

Edit2: The only reason I started changing ROS variables was the error I am getting by the program.

env | grep -i ros output without exporting any ROS enviroment variables:

CMAKE_PREFIX_PATH=/home/sofia/catkin_ws/devel:/opt/ros/indigo
CPATH=/home/sofia/catkin_ws/devel/include:/opt/ros/indigo/include
LD_LIBRARY_PATH=/home/sofia/catkin_ws/devel/lib:/opt/ros/indigo/lib
PATH=/opt/ros/indigo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
PKG_CONFIG_PATH=/home/sofia/catkin_ws/devel/lib/pkgconfig:/opt/ros/indigo/lib/pkgconfig
PYTHONPATH=/home/sofia/catkin_ws/devel/lib/python2.7/dist-packages:/opt/ros/indigo/lib/python2.7/dist-packages
ROS_DISTRO=indigo
ROS_ETC_DIR=/opt/ros/indigo/etc/ros
ROS_MASTER_URI=http://localhost:11311
ROS_PACKAGE_PATH=/home/sofia/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
ROS_ROOT=/opt/ros/indigo/share/ros
ROSLISP_PACKAGE_DIRECTORIES=/home/sofia/catkin_ws/devel/share/common-lisp

Edit3: there is a ros::init(arg,argc,"somename"), but why would that cause an error to occur? Why would getenv("ROS_MASTER_URI")=NULL since echo $ROS_MASTER_URI gives another result? (http://docs.ros.org/diamondback/api/roscpp/html/master_8cpp_source.html)

Could that be because I have already started a roscore? If I remove ros::init I get error like

You must call ros::init() before creating the first NodeHandle
Couldn't find an AF_INET address for [] ...

Originally posted by SofiaGr on ROS Answers with karma: 28 on 2017-10-25

Post score: 0


Original comments

Comment by gvdhoorn on 2017-10-25:
Please add the output of env | grep -i ros | sort to your question (use the edit button/link for that), as well as all lines that you added to your .bashrc to try and fix this.

Comment by SofiaGr on 2017-10-25:
Ok, I edited my question. Thank you.

Comment by gvdhoorn on 2017-10-25:
Just a test: comment the lines which export the following variables: ROS_PACKAGE_PATH, ROS_ROOT, PATH, ROS_MASTER_URI, ROS_IP and ROS_HOSTNAME.

For a single PC setup almost all of those should not be needed.

Then start a new terminal, remove the build and devel folders ..

Comment by gvdhoorn on 2017-10-25:
.. from your ~/catkin_ws, run catkin_make (or catkin build) again, source ~/catkin_ws/devel/setup.bash and try to run your programs again.

I'm curious to know why you decided to override ROS_ROOT and ROS_PACKAGE_PATH like that?

Overriding ROS_ROOT like that is not a good idea.

Comment by gvdhoorn on 2017-10-25:
re: edit2: please don't post updates in comments. Edit your original question. I've merged your comments into your question, but please keep it in mind.

Comment by gvdhoorn on 2017-10-25:
These values are what I would expect for a normal, single PC, ROS setup.

re: still getting error: do you get the error for all ros nodes? what about talker and listener from the ros_tutorials package?

Comment by gvdhoorn on 2017-10-25:
If those work, then I think we'll need to take a look at the code of the program / node you use to "publish messages to the topics from another program running in the same PC".

Comment by SofiaGr on 2017-10-25:
I just tested simple publisher and subscriber and they work. I will try to look at the code, which is not mine. I thought I had some problems with my configuration because the code does not produce errors to the person that wrote it.

Comment by gvdhoorn on 2017-10-25:
If those test nodes work it's likely that the problem is with the program that does give you problems.

Look for anything that could interfere with the programs "environment" (ie: environment variables), or with the way the ROS node is initialised (ie: ros::init(..) and friends).

Comment by gvdhoorn on 2017-10-26:
re: edit3: you cannot remove ros::init(..). I merely mentioned that function because that is what (eventually) will print the error that you show in your OP.

Why would getenv("ROS_MASTER_URI")=NULL

I'm not sure I follow. Does the program that doesn't work do this?

Comment by SofiaGr on 2017-10-26:
I assumed that the error comes from roscpp's master.cpp, and such error would occur if getenv("ROS_MASTER_URI")=NULL. Also, if I type somewhere in the program getenv("ROS_DISTRO"), I get NULL, but echoing it gives indigo.

Comment by gvdhoorn on 2017-10-26:
Without seeing (more of) the program it's probably going to be difficult assisting you.

What you could try is to cut away as much as possible from the program you are debugging. Remove everything except the ros::init(..) and ros::spin() calls (and other needed code). Then compile that ..

Comment by gvdhoorn on 2017-10-26:
.. and see if it exhibits the same symptoms. Is the node that has the problem doing anything special?

Are you starting it in a special / unconventional way (from another C/C++ program perhaps)?

getenv(..) returning NULL typically means the variable really doesn't exist.

Comment by SofiaGr on 2017-10-26:
Well... it has tons of libraries, so I don't know what to remove first! I will ask the person who wrote it. Thank you for your help!

Comment by gvdhoorn on 2017-10-26:
If you have any new information or have figured out what was wrong, please post a comment or an answer so we can mark this question as resolved. In any case some kind of resolution would be nice.

Comment by gvdhoorn on 2017-10-26:
Interestingly we now have another question where the poster has the exact same problem: #q274225.

@Dirk Thomas: any idea? I tried looking at the commits and changelog of ros_comm, but nothing really stands out.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

After noticing that throught the program, getenv() would return null, I exported ROS_MASTER_URI to a .sh file in /etc/profile.d Now it works.


Originally posted by SofiaGr with karma: 28 on 2017-10-26

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by gvdhoorn on 2017-10-26:
This is rather / highly irregular.

Is the program run as root? Does it have the setuid bit set to start as root or any other user? I ask because in that case the environment may simply not be setup for the user, with missing env vars as result.

Comment by SofiaGr on 2017-10-26:
hmmm.. I am not doing anything to run it as root. The program runs another executable. But I didn't have the time to look into the code, so I don't know many details.

Comment by gvdhoorn on 2017-10-26:
So the program runs another executable? And is that "other executable" the ROS node? It could just be that the environment is really not set, resulting in the errors.

Comment by gvdhoorn on 2017-10-26:
Could you add something like the following to the program?

#include <unistd.h>
#include <sys/types.h>

...

printf("euid: %d\n", geteuid());
printf("egid: %d\n", getegid());

That should tell you what the user and group id are under which the program is started.

Comment by SofiaGr on 2017-10-27:
The ros::init is in the "other executable". I will do that in a day or two, because I have to export some data, now that it works. Too afraid to rebuild it XD

Comment by gvdhoorn on 2017-10-27:\

The ros::init is in the "other executable".

hm, that could possibly be a problem.

I'll await your update.

Thanks for sticking with it and trying to diagnose what is really going on.

Comment by gvdhoorn on 2017-11-04:
Hi. Have you had a chance to take a look at this again?

Comment by SofiaGr on 2017-11-04:
Sorry for the delay. Yes, I did. All I got printed was "Boot file filename.fboot could not be opened"

Comment by gvdhoorn on 2017-11-04:
What? That does not make any sense to me.

Can you say anything about what sort of system this is?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.