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:
- Two-wheeled Robot Repository: https://bitbucket.org/theconstructcore/two-wheeled-robot-simulation/src/master/
- Robot Ignite Academy, the place to learn to program robots using only a web browser
- ROS Development Studio (the environment used in the video), another powerful online tool for pushing your ROS learning in a practical way
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:
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.
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:
Congratulations!!! You just learned how to spawn a robot in a gazebo simulation.
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:
- Two-Wheeled Robot Repository
- Related courses: