[Gazebo in 5 minutes] 002 – How to add gazebo models to a simulation

[Gazebo in 5 minutes] 002 - How to add gazebo models to a simulation

Written by Marco Arruda

18/04/2020

What you will learn

  • Learn how to add a gazebo model to a running gazebo simulation

List of resources used in this post:

  • 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
  • Gazebo models repository where you can find different models to be spawned

Including our model in the .world file

In this post, we are assuming you already have created a ROS package called my_simulations  and the following files: ~/simulation_ws/src/my_simulations/launch/my_world.launch and ~/simulation_ws/src/my_simulations/world/empty_world.world.

If you don’t have these files, please remember to first follow the previous post: https://www.theconstructsim.com/gazebo-5-mins-launch-first-gazebo-world-using-ros/

If you check the my_world.world file, from the previous post we have the following content:

<?xml version="1.0" ?>

<sdf version="1.5">
	<world name="default">
		<!-- A global light source -->
		<include>
			<uri>model://sun</uri>
		</include>

		<!-- A ground plane -->
		<include>
			<uri>model://ground_plane</uri>
		</include>
	</world>
</sdf>

Let’s add a postbox model. Remember that you can find many Gazebo moels on the Gazebo models repository.

The final content of ~/simulation_ws/src/my_simulations/world/empty_world.world after adding the postbox would be:

<?xml version="1.0" ?>

<sdf version="1.5">
	<world name="default">
		<!-- A global light source -->
		<include>
			<uri>model://sun</uri>
		</include>

		<!-- A ground plane -->
		<include>
			<uri>model://ground_plane</uri>
		</include>

                <!-- A post box plane -->
		<include>
			<uri>model://postbox</uri>
		</include>        

	</world>
</sdf>

This adds a model called postbox in the initial position (x=0, y=0, z=0). If you want it in a different position, you can add a <pose> like in the example below:

<include>
  <uri>model://postbox</uri>
  <pose>2 1 0 0 0 0</pose>
</include>

 

Adding the gazebo model to the simulation

Now that we have our empty_world.world file set, we can start our simulation in two ways:

Option one: Click Simulation -> Choose File, then select my_world.launch. This should automatically load the web version of gazebo, called gzweb.

Postbox gazebo simulation loaded in ROSDS

Postbox gazebo simulation loaded in ROSDS

 

Option two: If you are running the tests on your computer, or you want to manually run the simulation, you can just:

source ~/simulation_ws/devel/setup.bash
roslaunch my_simulations my_world.launch --screen

If you are in ROSDS and chose to run the simulation manually, then you have to manually open the Gazebo Web (gzweb) by clicking on Tools -> Gazebo.

 

Congratulations. You have successfully loaded a custom model in a Gazebo World using ROS.

Youtube video

If you didn’t understand well all the steps explained here or needs 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.


 

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

0 Comments

Submit a Comment

Your email address will not be published.

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

Share This