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

Multiple Turtlebots in Gazebo

asked 2012-05-14 09:50:32 -0600

jjamp gravatar image

updated 2015-07-20 17:55:39 -0600

130s gravatar image

Is it possible to separate the /cmd_vel and /odom topics when spawning multiple turtlebots in Gazebo?

My launch file looks like this:


  <param name="/use_sim_time" value="true" /> 
 <node name="gazebo" pkg="gazebo" type="gazebo" args="-u $(find gazebo_worlds)/worlds/" respawn="false" output="screen"/>

<group ns="robot1">
  <param name="robot_description" command="$(find xacro)/ '$(find turtlebot_description)/urdf/turtlebot.urdf.xacro'" /> 
  <node name="spawn_turtlebot_model1" pkg="gazebo" type="spawn_model" args=" -urdf -param robot_description -namespace robo1 -x 0 -y 1  -model robo1" respawn="false" output="screen"/>   


<param name="robot_description" command="$(find xacro)/ '$(find turtlebot_description)/urdf/turtlebot.urdf.xacro'" /> 
 <node name="spawn_turtlebot_model2" pkg="gazebo" type="spawn_model" args=" -urdf -param robot_description -namespace robo2 -x 1 -y 1  -model robo2" respawn="false" output="screen"/>
  <node name="spawn_turtlebot_model3" pkg="gazebo" type="spawn_model" args=" -urdf -param robot_description -namespace robo3 -x 1 -y -1   -model robo3" respawn="false" output="screen"/>


and rostopic list looks like this:


With this setup I see 3 turtlebots in gazebo but get only one cmd_vel and odom topic so I can't control only them separately. I use natty with electric

Any ideas? Thank you very much

edit retag flag offensive close merge delete


What nodes are generating your odom and cmd_vel messages?

DimitriProsser gravatar image DimitriProsser  ( 2012-05-14 10:31:47 -0600 )edit

Thanks Ryan, I tried your solution and changed line 36 to node_namespaceP_ = new ParamT<std::string>("robotNamespace","",0);
but the topics still are /odom and /cmd_vel. What else needs to be changed?

jjamp gravatar image jjamp  ( 2012-05-14 23:06:11 -0600 )edit

Did you test to see that passing in that renamed parameter via the URDF (gazebo.urdf.xacro) in turtlebot_description renames it correctly?

Ryan gravatar image Ryan  ( 2012-05-15 02:26:08 -0600 )edit

How do I do that? I'm not sure for what I have to look.

jjamp gravatar image jjamp  ( 2012-05-15 02:56:08 -0600 )edit

and when will you release the new version of the turtlebot simulator?

jjamp gravatar image jjamp  ( 2012-05-16 01:40:38 -0600 )edit

I actually tried to put in the xml file the robotNamespace parameter, but it is not detected... always cmd_vel..

maurizio gravatar image maurizio  ( 2012-08-14 09:19:25 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2012-05-14 11:04:00 -0600

Ryan gravatar image

On line #36 in gazebo_ros_create.cpp in the turtlebot_gazebo_plugins package, change "node_namespace" to "robotNamespace". IIRC (I can't find the thread I used originally), the robotNamespace parameter is automatically populated with the Gazebo -namespace argument, and that'll turn into a prefix to odom and cmd_vel.

I think that's all I had to do to fix this particular problem - we have an as-yet-unreleased branch of the TurtleBot simulator code which has been fully tested with this, but we have just been a little too busy to put together the patches.

edit flag offensive delete link more

answered 2012-11-25 14:50:09 -0600

Ana gravatar image

updated 2012-11-25 14:54:33 -0600

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.



edit flag offensive delete link more

answered 2012-08-14 07:09:34 -0600

maurizio gravatar image


I tried to follow this instructions but I was not able to deploy two turblebots: I see just one /odom and /cmd_vel topic. Besides the modification to the aforementioned gazebo_ros_create.cpp I use to launch file for the two turtlebots, here I just report one, the second differs just by the namespace.

Thank you

<group ns="SCORZIE">
  <param name="robot_description" command="$(find xacro)/ '$(find turtlebot_description)/urdf/turtlebot.urdf.xacro'"/>
  <node name="spawn_turtlebot_model" pkg="gazebo" type="spawn_model" args="$(optenv ROBOT_INITIAL_POSE) -unpause -urdf -param robot_description -x 9 -y 5 -z 0.05 -model turtlebot1" respawn="false" output="screen" ns="SCORZIE"/>

  <node pkg="diagnostic_aggregator" type="aggregator_node" name="diagnostic_aggregator" ns="SCORZIE" >
    <rosparam command="load" file="$(find turtlebot_bringup)/config/diagnostics.yaml" />

  <node pkg="robot_state_publisher" type="state_publisher" name="robot_state_publisher" output="screen" ns="SCORZIE">
    <param name="publish_frequency" type="double" value="20.0" />

  <!-- The odometry estimator -->

  <node pkg="robot_pose_ekf" type="robot_pose_ekf" name="robot_pose_ekf" ns="SCORZIE">
    <param name="freq" value="30.0"/>
    <param name="sensor_timeout" value="1.0"/>
    <param name="publish_tf" value="true"/>
    <param name="odom_used" value="true"/>
    <param name="imu_used" value="false"/>
    <param name="vo_used" value="false"/>
    <param name="output_frame" value="odom"/>
    <param name="output_frame" value="odom" />

  <!-- throttling -->
  <node pkg="nodelet" type="nodelet" name="pointcloud_throttle" args="load pointcloud_to_laserscan/CloudThrottle openni_manager" respawn="true" ns="SCORZIE">
    <param name="max_rate" value="20.0"/>
    <remap from="cloud_in" to="/camera/depth/points"/>
    <remap from="cloud_out" to="cloud_throttled"/>

  <!-- Fake Laser -->
  <node pkg="nodelet" type="nodelet" name="kinect_laser" args="load pointcloud_to_laserscan/CloudToScan openni_manager" respawn="true" ns="SCORZIE">
    <param name="output_frame_id" value="/camera_depth_frame"/>
    <!-- heights are in the (optical?) frame of the kinect -->
    <param name="min_height" value="-0.15"/>
    <param name="max_height" value="0.15"/>
    <remap from="cloud" to="/cloud_throttled"/>

  <!-- Fake Laser (narrow one, for localization -->
  <node pkg="nodelet" type="nodelet" name="kinect_laser_narrow" args="load pointcloud_to_laserscan/CloudToScan openni_manager" respawn="true" ns="SCORZIE">
    <param name="output_frame_id" value="/camera_depth_frame"/>
    <!-- heights are in the (optical?) frame of the kinect -->
    <param name="min_height" value="-0.025"/>
    <param name="max_height" value="0.025"/>
    <remap from="cloud" to="/cloud_throttled"/>
    <remap from="scan" to="/narrow_scan"/>

edit flag offensive delete link more

Question Tools



Asked: 2012-05-14 09:50:32 -0600

Seen: 2,907 times

Last updated: Jul 20 '15