[ros-users] strange namespace behavior when setting the ROS…

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: User discussions
Date:  
To: ros-users@code.ros.org
Subject: [ros-users] strange namespace behavior when setting the ROS_NAMESPACE environment variable
Hi all,

I tried to post this via nabble.com but somehow it didn't get through ... 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. rosversion ros says 1.4.8 .

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;
}