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

Written by Marco Arruda

25/04/2020

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"?>
<launch>
    <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)" />
          
</launch>

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/
catkin_make
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:

 

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

1 Comment

  1. 1

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This