ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Change turtlebot initial position in gazebo ros

asked 2019-12-04 06:47:55 -0500

kiko453 gravatar image

updated 2019-12-04 06:48:19 -0500

When launching roslaunch turtlebot_gazebo turtlebot_world.launch, turtlebot initial position is always at the center (0,0,0). How can I change this initial position? I want for example the turtleot to be at (5,0, 0) in my map.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-04 07:45:52 -0500

Delb gravatar image

updated 2019-12-04 07:46:09 -0500

The position of the robot is determined when calling the node spawn_model from the package gazebo_ros. This node is called at the line <include file="$(find turtlebot_gazebo)/launch/includes/$(arg base).launch.xml">. It will call the launch file kobuki.launch.xml. In this file you have :

  <!-- Gazebo model spawner -->
  <node name="spawn_turtlebot_model" pkg="gazebo_ros" type="spawn_model"
        args="$(optenv ROBOT_INITIAL_POSE) -unpause -urdf -param robot_description -model turtlebot"/>

Your solution is to create a new launch file similar to turtlebot_world.launch and instead of using the include to kobuki.launch.xml copy the content direclty in your launch file and remove the argument $(optenv ROBOT_INITIAL_POSE) to set your pose, using the arguments -x, -y, -Y (for yaw) like this :

  <!-- Gazebo model spawner -->
  <node name="spawn_turtlebot_model" pkg="gazebo_ros" type="spawn_model"
        args="-x 5 -y 0 -Y 0 -unpause -urdf -param robot_description -model turtlebot"/>

Or if you don't want to change anything you can directly set the envirronment variable ROBOT_INITIAL_POSE to the desired arguments :

export ROBOT_INITIAL_POSE="-x 5 -y 0 -Y 0"

Note that after executing this you have to use roslaunch in the same terminal.

edit flag offensive delete link more


Hi many thanks. The first soplution worked fine, but now the origin of my robot in rviz does match anymore with the origin in gazebo. in the my_map.yaml file there is a field origin: [12.2, -12.2, 0.0]. How do I have to change it such the position match with the one I set in kobuki.launch.xml. In other what coordinate transformation do I have to apply?

kiko453 gravatar image kiko453  ( 2019-12-04 12:29:32 -0500 )edit

That would be related to the AMCL configration, there are the parameters initial_pose_x, initial_pose_y and initial_pose_a, you just need to set them at the same values as the parameters of spawn_model.

Delb gravatar image Delb  ( 2019-12-06 02:20:39 -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

1 follower


Asked: 2019-12-04 06:47:55 -0500

Seen: 2,261 times

Last updated: Dec 04 '19