[Gazebo in 5 minutes] 003 – How to spawn a robot in gazebo

Written by Marco Arruda


What you will learn

  • Learn how to spawn a robot from its package in any gazebo simulation you may have running

List of resources used in this post:

Preparing the environment

In order to spawn a gazebo model in a simulation using ROS, you need to have Gazebo and ROS installed. If you don’t want to install everything, we highly recommend using ROSDS (ROS Development Studio) which gives you access to an online environment with ROS already installed. Indeed, we are going to use that tool for easiness. You can follow the same steps on your computer as well if you don’t want to use ROSDS.

To use ROSDS, you can just create an account and start using it.

Once you have your account created, you have to create a ROSject by clicking on the New ROSject button:

Creating a new ROSject in ROSDS

Once you have the ROSject, you can open it by clicking Open:

Spawning a two-wheeled robot in a gazebo simulation

When you open a ROSject, you are able to open web shell, code editor, etc.

Let’s start opening a web shell by clicking Tools -> Shell in ROSDS. Once you have the shell, let’s clone the repository that contains the robot:

cd ~/simulation_ws/src/

git clone https://bitbucket.org/theconstructcore/two-wheeled-robot-simulation

If you see, the repository we just cloned, you will find the file m2wr_description/launch/spawn.launch which contains the code used to spawn the robot. The code is as follows:

<?xml version="1.0" encoding="UTF-8"?>
    <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find m2wr_description)/urdf/m2wr.xacro'" />
    <arg name="x" default="0"/>
    <arg name="y" default="0"/>
    <arg name="z" default="0.5"/>
    <node name="mybot_spawn" pkg="gazebo_ros" type="spawn_model" output="screen"
          args="-urdf -param robot_description -model m2wr -x $(arg x) -y $(arg y) -z $(arg z)" />

A quick look into this file shows that the file loaded in gazebo will be the m2wr_description/urdf/m2wr.xacro, in the positions xyz = 0, 0, 0.5.

Now, to actually spawn the robot, you can first load an empty world by clicking Simulations -> Empty World -> Start Simulation.

Starting an empty simulation in ROSDS

Starting an empty simulation in ROSDS

With the empty simulation running, we can now spawn our robot into the current simulation. For that, let’s first compile the workspace to make sure the package we cloned is ok:

cd ~/simulation_ws/
source devel/setup.bash
rospack profile

Now let’s spawn our robot:

roslaunch m2wr_description spawn.launch

If everything went as expected, you should have the two-wheeled robot in the simulation:

A two-whelled robot running in ROSDS

A two-whelled robot running in ROSDS

Congratulations!!! You just learned how to spawn a robot in a gazebo simulation.

Youtube video

If you didn’t understand well all the steps explained here or need more understanding of the files we created, remember that we have the live version of this post on YouTube. Also, if you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.

Keep pushing your ROS Learning.

Links & Resources mentioned in the video:


Discover How to Equip Your Teams with ROS Skills Fast

The Construct For Enterprise

Check Out These Related Posts

5 Mistakes Robotics & ROS Teachers Make

5 Mistakes Robotics & ROS Teachers Make

Last week, a colleague of mine asked me for advice on how to teach ROS at university because she is going to start delivering a ROS class next month. Then I decided to record this video with 5 mistakes I have made in the past while teaching ROS at the university. I hope that this video is useful for you and helps you avoid the mistakes that I made so you can start delivering ROS classes smoothly.

read more


Share This