ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS_MASTER_URI set, but program gives related error.

asked 2017-10-25 06:26:33 -0600

SofiaGr gravatar image

updated 2017-10-26 01:16:51 -0600

gvdhoorn gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-25 06:29:45 -0600 )edit

Ok, I edited my question. Thank you.

SofiaGr gravatar image SofiaGr  ( 2017-10-25 07:16:34 -0600 )edit

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 ..

gvdhoorn gravatar image gvdhoorn  ( 2017-10-25 07:36:13 -0600 )edit

.. 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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-25 07:38:14 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-25 08:30:15 -0600 )edit

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?

gvdhoorn gravatar image gvdhoorn  ( 2017-10-25 08:34:02 -0600 )edit

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".

gvdhoorn gravatar image gvdhoorn  ( 2017-10-25 08:34:50 -0600 )edit

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.

SofiaGr gravatar image SofiaGr  ( 2017-10-25 09:35:26 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-10-26 11:30:39 -0600

SofiaGr gravatar image

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.

edit flag offensive delete link more

Comments

1

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 12:25:12 -0600 )edit

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.

SofiaGr gravatar image SofiaGr  ( 2017-10-26 12:53:25 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 13:33:07 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 13:46:07 -0600 )edit

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

SofiaGr gravatar image SofiaGr  ( 2017-10-27 03:20:09 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-27 03:34:04 -0600 )edit

Hi. Have you had a chance to take a look at this again?

gvdhoorn gravatar image gvdhoorn  ( 2017-11-04 06:41:40 -0600 )edit

Sorry for the delay. Yes, I did. All I got printed was "Boot file filename.fboot could not be opened"

SofiaGr gravatar image SofiaGr  ( 2017-11-04 12:59:52 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-10-25 06:26:33 -0600

Seen: 3,029 times

Last updated: Oct 26 '17

Related questions