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

Revision history [back]

click to hide/show revision 1
initial version

Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:

Go to gazebo_ros_create.h and add a new private variable: std::string robot_namespace_;

Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load (I added it around line 56)

this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) { 
  this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
}

With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace in order to add the robotNamespace String on it:

this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
  this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
}

Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel, /odom and /sensor_state and change them to local names cmd_vel, odom and sensor_state.

cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );

sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1);
odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", 1);
joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);

Finally, rosmake the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)

Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.

Thanks!

Ana

click to hide/show revision 2
added robotNamespace to topic_namespace and erased slashes from topic names

Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:

Go to gazebo_ros_create.h and add a new private variable: std::string robot_namespace_;

Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load (I added it around line 56)

this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) { 
  this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
}

With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace in order to add the robotNamespace String on it:

this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
  this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
}

Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel, /odom and /sensor_state and change them to local names cmd_vel, odom and sensor_state.. The lines should now look like this:

cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );

sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1);
odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", 1);
joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);

Finally, rosmake the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)

Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.

Thanks!

Ana

Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:

  1. Go to gazebo_ros_create.h and add a new private variable:

    std::string robot_namespace_;

  2. Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load (I added it around line 56)

    this->robot_namespace_ = ""; if (_sdf->HasElement("robotNamespace")) { this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/"; }

    }

  3. With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace in order to add the robotNamespace String on it:

    this->node_namespace_ = ""; if (_sdf->HasElement("node_namespace")) { this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/"; }

    }

  4. Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel, /odom and /sensor_state and change them to local names cmd_vel, odom and sensor_state. The lines should now look like this:

    cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this ); );

    sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", rosnode_->advertise<turtlebot_node::turtlebotsensorstate>("sensor_state", 1); odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", rosnode_->advertise<nav_msgs::odometry>("odom", 1); joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);

    rosnode_->advertise<sensor_msgs::jointstate>("joint_states", 1);

  5. Finally, rosmake the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)

Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.

Thanks!

Ana

Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:

  1. Go to gazebo_ros_create.h and add a new private variable:

    std::string robot_namespace_;

  2. robot_namespace_;

    Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load (I added it around line 56)

    this->robot_namespace_ = "";
    if (_sdf->HasElement("robotNamespace")) { 
      this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
    }

  3. }

    With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace in order to add the robotNamespace String on it:

    this->node_namespace_ = "";
    if (_sdf->HasElement("node_namespace")) {
      this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
    }

  4. }

    Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel, /odom and /sensor_state and change them to local names cmd_vel, odom and sensor_state. The lines should now look like this:

    cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );

    ); sensor_state_pub_ = rosnode_->advertise<turtlebot_node::turtlebotsensorstate>("sensor_state", rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1); odom_pub_ = rosnode_->advertise<nav_msgs::odometry>("odom", rosnode_->advertise<nav_msgs::Odometry>("odom", 1); joint_state_pub_ = rosnode_->advertise<sensor_msgs::jointstate>("joint_states", 1);

  5. rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);

    Finally, rosmake the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)

Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.

Thanks!

Ana

Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom /cmd_vel and /odom topics. Here is what I did:

Go to gazebo_ros_create.h and add a new private variable:

std::string robot_namespace_;

Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load (I added it around line 56)

this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) { 
  this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
}

With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace in order to add the robotNamespace String on it:

this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
  this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
}

Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel, /odom and /sensor_state and change them to local names cmd_vel, odom and sensor_state. The lines should now look like this:

cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );

sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1);
odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", 1);
joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);

Finally, rosmake the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)

Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.

Thanks!

Ana