In order to load gazebo 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:
Opening a ROSject in ROSDS
Creating the ROS Package
In order to run anything using ROS, we need a ROS package, so, let’s create one. For that, you are going to need a terminal/shell. In ROSDS, you can have a terminal by clicking Tools -> Shell.
Let’s first create the workspace. In this case, let’s call it ~/simulation_ws
mkdir ~/simulation_ws/src -p
Now let’s then compile our empty workspace
source /opt/ros/kinetic/setup.bash
source /usr/share/gazebo/setup.sh
cd ~/simulation_ws/
catkin_make
Now let’s create our ROS package. Let’s call it my_simulations:
source ~/simulation_ws/devel/setup.bash
cd ~/simulation_ws/src
catkin_create_pkg my_simulations
Now, let’s create a launch and a world folder inside the my_simulations package.
cd my_simulations
mkdir launch world
Now, inside the launch folder, let’s create a file named my_world.launch:
Inside the my1stmodel folder, let’s create two files, one named model.config and another named model.sdf.
cd models/my1stmodel/
touch model.config model.sdf
These two files, model.config and model.sdf, are required for every gazebo model. You can find those files in the ground_plane model provided by gazebo, for example.
Let’s paste the following content on our my1stmodel/model.config
<?xml version="1.0"?>
<model>
<name>My first model</name>
<version>1.0</version>
<sdf version="1.5">model.sdf</sdf>
<author>
<name>Your name</name>
<email>your@email.com</email>
</author>
<description>
My first model for gazebo
</description>
</model>
And in our models/my1stmodel/model.sdf, let’s add the following:
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 launched your first custom Gazebo World using ROS.
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.
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:
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
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-wheeledrobot in the simulation:
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.
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 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:
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.
Learn how to launch an empty world in the gazebo simulator using ROS commands.
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
Preparing the environment
In order to load gazebo 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:
Opening a ROSject in ROSDS
Creating the ROS Package
In order to run anything using ROS, we need a ROS package, so, let’s create one. For that, you are going to need a terminal/shell. In ROSDS, you can have a terminal by clicking Tools -> Shell.
Let’s first create the workspace. In this case, let’s call it ~/simulation_ws
mkdir ~/simulation_ws/src -p
Now let’s then compile our empty workspace
source /opt/ros/kinetic/setup.bash
source /usr/share/gazebo/setup.sh
cd ~/simulation_ws/
catkin_make
Now let’s create our ROS package. Let’s call it my_simulations:
source ~/simulation_ws/devel/setup.bash
cd ~/simulation_ws/src
catkin_create_pkg my_simulations
Now, let’s create a launch and a world folder inside the my_simulations package.
cd my_simulations
mkdir launch world
Now, inside the launch folder, let’s create a file named my_world.launch:
user:~/simulation_ws/src$ roslaunch my_simulations my_world.launch --screen
... logging to /home/user/.ros/log/1b7241b4-782c-11ea-a2f3-161ed25550cd/roslaunch-rosdscomputer-7087.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://rosdscomputer:40747/
SUMMARY
========
PARAMETERS
* /rosdistro: kinetic
* /rosversion: 1.12.14
* /use_sim_time: True
NODES
/
gazebo (gazebo_ros/gzserver)
gazebo_gui (gazebo_ros/gzclient)
auto-starting new master
process[master]: started with pid [7108]
ROS_MASTER_URI=http://master:11311
setting /run_id to 1b7241b4-782c-11ea-a2f3-161ed25550cd
process[rosout-1]: started with pid [7126]
started core service [/rosout]
process[gazebo-2]: started with pid [7140]
process[gazebo_gui-3]: started with pid [7158]
[ INFO] [1586194149.892774702]: Finished loading Gazebo ROS API Plugin.
[ INFO] [1586194149.894694146]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting...
GZCLIENT disabled by The Construct
[ INFO] [1586194150.663164508, 0.021000000]: waitForService: Service [/gazebo/set_physics_properties] is now available.
[ INFO] [1586194150.694158392, 0.050000000]: Physics dynamic reconfigure ready.
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 launched your first Gazebo World using ROS.
Youtube video
If you didn’t understand 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.
Gazebo is a leader in robot simulation. It is a tool relied upon by hundreds of thousands of users and developers around the world.
Perhaps you have heard “Gazebo simulation” many times, but you don’t know exactly what it is or how it works. In this post, you will learn what a Gazebo simulation is by practicing, as it pertains to ROS development.
You don’t need a ROS installation for this, as we will use the ROS Development Studio (ROSDS), an online platform that provides access to ROS1 & ROS2 computers and other powerful ROS tools within a browser!
Action first before the theory! Grab a copy of the project used for this post using the link below. If you don’t have an account on the ROSDS, you will be guided to create one.
Once you have cloned the project, open it up and give it a moment to finish loading.
If you want to know how to install Gazebo in an existing ROS environment on your local computer, then please follow this tutorial:
[irp posts=”8194″ name=”All about Gazebo ROS (Gazebo 9)”]
Step 2: Bring up a Gazebo simulation
From the ROSDS Tools menu, pick the Shell and Gazebo tools. Yeah, we have a tool so named:). Place the tools side-by-side for best effect.
Type the following commands on the Shell to bring up a Gazebo simulation.
user:~$ roslaunch gazebo_ros mud_world.launch
You should now see something similar to this:
Step 3: What is Gazebo simulation in theory?
Well, I just showed you a Gazebo simulation in the step above, in practice. Now we are going to look what it’s in theory.
A Gazebo simulation is a robot simulation made with Gazebo, a 3D simulator with the ability to accurately and efficiently simulate populations of robots in complex indoor and outdoor environments.
It’s similar to game engines, but produces better simulations and offers a suite of sensors and interfaces for both users and programs.
It has the following main components:
World files – contain all the elements in a simulation, including robots, lights, sensors, and static objects. In the image above, the world is shown in the Gazebo app.
Models – represent individual elements. The three robots and the object in front of them are models.
gzserver – the “work horse” Gazebo program – it reads the world file to generate and populate a world.
gzclient – connects to gzserver and visualizes the elements. In the shell output, under “NODES”, we have both gzserver and gzclient listed.
gzweb – web version of gzclient, using WebGL.
Step 4: Wrapping up
And that’s it! You know what a Gazebo simulation is in both practice and theory. This knowledge is the foundation for using and creating Gazebo simulations.
Extra: Video
Prefer to watch a video demonstrating the steps above? We have one for you below!
Related Resources and Further Learning
If you are a ROS beginner and want to learn ROS basics fast, we recommend you take any of the following courses on Robot Ignite Academy:
Did you like this post? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS topics, please let us know in the comments area and we will do a video or post about it
Welcome to the ROS Q&A series again. In this post, we are going to answer and solve a question from a user on Gazebo Answers which asks how to launch a Parrot Drone simulation locally. The question can be found here.
What will you learn in this post
How to spawn a drone simulation in your local computer
Before downloading the repositories, let’s first create a catkin workspace for the parrot drone, which we will call parrot_ws. Let’s do that with the commands below:
mkdir -p ~/parrot_ws/src
cd ~/parrot_ws/
Now we have the parrot_ws (parrot workspace). Let’s then download the required git repositories which contain the simulation:
cd ~/parrot_ws/src
git clone --branch kinetic-gazebo7 https://bitbucket.org/theconstructcore/parrot_ardrone.git
git clone https://bitbucket.org/theconstructcore/spawn_robot_tools.git
You should now have the folders parrot_ardrone and spawn_robot_tools on the ~/parrot_ws/src folder.
Installing ignition-math, used by sjtu_drone
Before compiling the packages we downloaded in the previous step, we will need to install the Ignition Math library, which is used by the sjtu_drone drone found on the parrot_ardrone repository we cloned previously.
We can install the Ignition Math library with the following commands:
Now that we have the Ignition Math library installed, we can proceed to compile the packages in our workspace.
Compiling the drone package
Now that we have everything in place, we can compile our packages we downloaded previously.
IMPORTANT: it may happen that when compiling the package, catkin_make can’t find the ignition library, so we need to export the CXXFLAGS accordingly. In my local computer, the ignition library is found at /usr/include/ignition/math4, so to compile we use the following commands:
cd ~/parrot_ws
export CXXFLAGS=-isystem\ /usr/include/ignition/math4
source /opt/ros/kinetic/setup.bash
catkin_make
If everything worked as expected, great. If not, try removing the devel and build first with cd ~/parrot_ws/; rm -rf build/ devel/ and compile it again with the commands exemplified above.
If everything went ok, you should have something like:
root@79e5b2505ede:~/parrot_ws# export CXXFLAGS=-isystem\ /usr/include/ignition/math4
root@79e5b2505ede:~/parrot_ws# source /opt/ros/kinetic/setup.bash; catkin_make
Base path: /root/parrot_ws
Source space: /root/parrot_ws/src
Build space: /root/parrot_ws/build
Devel space: /root/parrot_ws/devel
Install space: /root/parrot_ws/install
####
#### Running command: "cmake /root/parrot_ws/src -DCATKIN_DEVEL_PREFIX=/root/parrot_ws/devel -DCMAKE_INSTALL_PREFIX=/root/parrot_ws/install -G Unix Makefiles" in "/root/parrot_ws/build"
####
...
-- catkin 0.7.14
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 6 packages in topological order:
-- ~~ - custom_teleop
-- ~~ - drone_demo
-- ~~ - ardrone_as
-- ~~ - sjtu_drone
-- ~~ - spawn_robot_tools_pkg
-- ~~ - drone_construct
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'custom_teleop'
-- ==> add_subdirectory(parrot_ardrone/custom_teleop)
-- +++ processing catkin package: 'drone_demo'
-- ==> add_subdirectory(parrot_ardrone/drone_demo)
-- +++ processing catkin package: 'ardrone_as'
-- ==> add_subdirectory(parrot_ardrone/ardrone_as)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- Generating .msg files for action ardrone_as/Ardrone /root/parrot_ws/src/parrot_ardrone/ardrone_as/action/Ardrone.action
Generating for action Ardrone
-- ardrone_as: 7 messages, 0 services
-- +++ processing catkin package: 'sjtu_drone'
-- ==> add_subdirectory(parrot_ardrone/sjtu_drone)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- thread
-- signals
-- system
-- filesystem
-- program_options
-- regex
-- iostreams
-- date_time
-- chrono
-- atomic
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so
...
-- Generating done
-- Build files have been written to: /root/parrot_ws/build
####
#### Running command: "make -j4 -l4" in "/root/parrot_ws/build"
####
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneActionFeedback
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneGoal
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneActionGoal
Scanning dependencies of target _ardrone_as_generate_messages_check_deps_ArdroneResult
[ 0%] Built target _ardrone_as_generate_messages_check_deps_ArdroneResult
...
Scanning dependencies of target plugin_drone
[ 1%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_cam.dir/src/plugin_ros_cam.cpp.o
[ 3%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_imu.dir/src/plugin_ros_imu_native.cpp.o
[ 5%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_drone.dir/src/plugin_drone.cpp.o
[ 7%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_sonar.dir/src/plugin_ros_sonar.cpp.o
...
[ 9%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_imu.so
[ 11%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_sonar.so
[ 11%] Built target plugin_ros_sonar
[ 13%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_cam.dir/src/util_ros_cam.cpp.o
[ 13%] Built target plugin_ros_imu
Scanning dependencies of target plugin_ros_init
[ 15%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_ros_init.dir/src/plugin_ros_init.cpp.o
[ 17%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/plugin_drone.dir/src/pid_controller.cpp.o
[ 19%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_drone.so
[ 19%] Built target plugin_drone
Scanning dependencies of target spawn_drone
[ 21%] Building CXX object parrot_ardrone/sjtu_drone/CMakeFiles/spawn_drone.dir/src/spawn_drone.cpp.o
...
[ 23%] Linking CXX executable /root/parrot_ws/src/parrot_ardrone/sjtu_drone/bin/spawn_drone
[ 23%] Built target spawn_drone
Scanning dependencies of target spawn_robot_tools_pkg_xacro_generated_to_devel_space_
[ 23%] Built target spawn_robot_tools_pkg_xacro_generated_to_devel_space_
Scanning dependencies of target ardrone_as_generate_messages_cpp
[ 25%] Generating C++ code from ardrone_as/ArdroneFeedback.msg
[ 27%] Generating C++ code from ardrone_as/ArdroneActionResult.msg
[ 29%] Generating C++ code from ardrone_as/ArdroneAction.msg
[ 31%] Generating C++ code from ardrone_as/ArdroneResult.msg
[ 33%] Generating C++ code from ardrone_as/ArdroneActionGoal.msg
[ 35%] Generating C++ code from ardrone_as/ArdroneGoal.msg
[ 37%] Generating C++ code from ardrone_as/ArdroneActionFeedback.msg
Scanning dependencies of target ardrone_as_generate_messages_py
[ 37%] Built target ardrone_as_generate_messages_cpp
[ 39%] Generating Python from MSG ardrone_as/ArdroneFeedback
Scanning dependencies of target ardrone_as_generate_messages_nodejs
[ 41%] Generating Javascript code from ardrone_as/ArdroneFeedback.msg
[ 43%] Generating Javascript code from ardrone_as/ArdroneActionResult.msg
[ 47%] Generating Javascript code from ardrone_as/ArdroneAction.msg
[ 47%] Generating Python from MSG ardrone_as/ArdroneActionResult
[ 49%] Generating Javascript code from ardrone_as/ArdroneResult.msg
[ 50%] Generating Javascript code from ardrone_as/ArdroneActionGoal.msg
[ 52%] Generating Python from MSG ardrone_as/ArdroneAction
[ 54%] Generating Javascript code from ardrone_as/ArdroneGoal.msg
[ 56%] Generating Javascript code from ardrone_as/ArdroneActionFeedback.msg
[ 58%] Generating Python from MSG ardrone_as/ArdroneResult
[ 58%] Built target ardrone_as_generate_messages_nodejs
Scanning dependencies of target ardrone_as_generate_messages_eus
[ 60%] Generating EusLisp code from ardrone_as/ArdroneFeedback.msg
[ 62%] Generating EusLisp code from ardrone_as/ArdroneActionResult.msg
[ 64%] Generating Python from MSG ardrone_as/ArdroneActionGoal
[ 66%] Generating EusLisp code from ardrone_as/ArdroneAction.msg
[ 68%] Generating Python from MSG ardrone_as/ArdroneGoal
[ 70%] Generating EusLisp code from ardrone_as/ArdroneResult.msg
[ 72%] Generating EusLisp code from ardrone_as/ArdroneActionGoal.msg
[ 74%] Generating Python from MSG ardrone_as/ArdroneActionFeedback
[ 76%] Generating EusLisp code from ardrone_as/ArdroneGoal.msg
[ 78%] Generating EusLisp code from ardrone_as/ArdroneActionFeedback.msg
[ 80%] Generating Python msg __init__.py for ardrone_as
[ 82%] Generating EusLisp manifest code for ardrone_as
[ 82%] Built target ardrone_as_generate_messages_py
Scanning dependencies of target ardrone_as_generate_messages_lisp
[ 84%] Generating Lisp code from ardrone_as/ArdroneFeedback.msg
[ 86%] Generating Lisp code from ardrone_as/ArdroneActionResult.msg
[ 88%] Generating Lisp code from ardrone_as/ArdroneAction.msg
[ 90%] Generating Lisp code from ardrone_as/ArdroneResult.msg
[ 92%] Generating Lisp code from ardrone_as/ArdroneActionGoal.msg
[ 94%] Generating Lisp code from ardrone_as/ArdroneGoal.msg
[ 96%] Generating Lisp code from ardrone_as/ArdroneActionFeedback.msg
[ 96%] Built target ardrone_as_generate_messages_lisp
[ 96%] Built target ardrone_as_generate_messages_eus
Scanning dependencies of target ardrone_as_generate_messages
[ 96%] Built target ardrone_as_generate_messages
...
[ 98%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_cam.so
[ 98%] Built target plugin_ros_cam
[100%] Linking CXX shared library /root/parrot_ws/src/parrot_ardrone/sjtu_drone/plugins/libplugin_ros_init.so
[100%] Built target plugin_ros_init
Once the package is compiled, in every shell you need to source the parrot_ws so that ROS can find the compiled packages. In each shell you can run the commands below:
cd ~/parrot_ws/
source devel/setup.bash
rospack profile
Launching the simulation
Now that you have everything in place, you should be able to launch the simulation with the command below:
After running rosrun teleop_twist_keyboard teleop_twist_keyboard.py you can easily move the robot using the keyboard.
So that is the post for today. You can also find a live version of this post on our YouTube channel in the link below. Also, please consider subscribing to our channel if you liked the content and press the bell for a new video every day.