Ask Your Question
1

strange namespace behavior when setting the ROS_NAMESPACE environment variable

asked 2011-07-21 00:12:56 -0500

Markus Achtelik gravatar image

Hi all,

I have a node publishing a topic let's say "my_topic". Simply running this node, rostopic list tells me as expected:

/my_topic
/rosout
/rosout_agg

Now, when I want to push this node to a namespace by: export ROS_NAMESPACE=my_ns

rostopic list says:

/my_ns/my_ns/my_ns/my_topic
/rosout
/rosout_agg

Any idea where three times "my_ns" comes from? When I run the node from a launch file and set the "ns" attribute, everything is alright. I'm not doing anything fancy with namespaces etc. in the node, I put some example code below. It seems like this came with ros 1.4.8. It used to work with 1.4.6 which I had installed before.

Best, Markus

#include <ros/ros.h>
#include <std_msgs/String.h>

int main(int argc, char** argv)
{

  ros::init(argc, argv, "ns_test");
  ros::NodeHandle nh;
  ros::Publisher pub = nh.advertise<std_msgs::String> ("my_topic", 1);

  ros::Rate r(5);
  while (ros::ok())
  {
    std_msgs::String msg;
    msg.data = "my string message";
    pub.publish(msg);
    r.sleep();
  }
  return 0;
}
edit retag flag offensive close merge delete

Comments

I just tried with the electric beta, it happens there as well.
Markus Achtelik gravatar image Markus Achtelik  ( 2011-07-21 00:38:42 -0500 )edit
I have the same on diamondback/lucid.
dornhege gravatar image dornhege  ( 2011-07-21 01:24:50 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2011-07-21 05:41:30 -0500

Markus Achtelik gravatar image

I had a look into roscpp/src/libros/node_handle.cpp. It seems like this (lines 263 to 267) gets called multiple times and appends the namespace every time:

else if (!namespace_.empty())
{
  // ROSCPP_LOG_DEBUG("Appending namespace_ (%s)", namespace_.c_str());
  final = names::append(namespace_, final);
}

commenting out

final = names::append(namespace_, final);

avoided the problem, but no idea what this will break now ;-)

Best, Markus

edit flag offensive delete link more

Comments

Certainly seems like a bug to me especially if you can show the behaviour changed between 1.4.6 and 1.4.8. You should probably file a ticket against roscpp to be sure the developers are aware. Out of curiosity does it only affect topic names and not other things (node name, private parameters, etc)?
Patrick Bouffard gravatar image Patrick Bouffard  ( 2011-07-21 07:22:35 -0500 )edit
Well, it looks like when your ticket was addressed, it broke something else. :) Anyway just to connect the dots for anyone else having namespace headaches since moving to electric: https://code.ros.org/trac/ros/ticket/3617
Patrick Bouffard gravatar image Patrick Bouffard  ( 2012-01-04 15:59:01 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-07-21 00:12:56 -0500

Seen: 503 times

Last updated: Jul 21 '11