Gazebo Components
There are six components involved in running an instance of a Gazebo simulation:
- Gazebo Server
- Gazebo Client
- World Files
- Model Files
- Environment Variables
- Plugins
1- Gazebo Server
The first main component involved in running an instance of a Gazebo simulation is the Gazebo Server or also known by gzserver.
gzserver performs most of the heavy-lifting for Gazebo. It is responsible for parsing the description files related to the scene we are trying to simulate, as well as the objects within. It then simulates the complete scene using a physics and sensor engine.
While the server can be launched independently by using the following command in a terminal:
$ gzserver
It does not have any GUI component. Running gzserver in a so-called headless mode can come in handy in certain situations, but we will talk more about that in future lessons.
2- Gazebo Client
The second main component involved in running an instance of a Gazebo simulation is the Gazebo Client or also known by gzclient.
gzclient on the other hand provides the very essential Graphical Client that connects to the gzserver and renders the simulation scene along with useful interactive tools. While you can technically run gzclient by itself using the following command:
$ gzclient
it does nothing at all (except consume your compute resources), since it does not have a gzserver to connect to and receive instructions from. Combining Gazebo Server and Gazebo Client
It is a common practice to run gzserver first, followed by gzclient, allowing some time to initialize the simulation scene, objects within, and associated parameters before rendering it. To make our lives easier, there is a single intuitive command that necessarily launches both the components sequentially:
$ gazebo
3- World Files
A world file in Gazebo contains all the elements in the simulated environment. These elements are your robot model, its environment, lighting, sensors, and other objects. You have the ability to save your simulation to a world file that usually has a .world
extension.
Gazebo can also read the content of a world file from your disk to generate the simulation. To launch the simulation from a world file, type:
$ gazebo <yourworld>.world
The world file is formatted using the Simulation Description Format or SDF for short. Here’s the basic format of an SDF world file:
<?xml version="1.0" ?>
<sdf version="1.5">
<world name="default">
<physics type="ode">
...
</physics>
<scene>
...
</scene>
<model name="box">
...
</model>
<model name="sphere">
...
</model>
<light name="spotlight">
...
</light>
</world>
</sdf>
4- Model Files
For simplification, you must create a separate SDF file of your robot with exactly the same format as your world file. This model file should only represent a single model (ex: a robot) and can be imported by your world file. The reason why you need to keep your model in a separate file is to use it in other projects. To include a model file of a robot or any other model inside your world file, you can add the following code to the world’s SDF file:
<include>
<uri>model://model_file_name</uri>
</include>
5- Environment Variables
There are many environment variables that Gazebo uses, primarily to locate files (world, model, …) and set up communications between gzserver and gzclient. While working on a robotic project, you’ll leave these variables as default. Here’s an example of a variable that Gazebo uses:
GAZEBO_MODEL_PATH:
List of directories where Gazebo looks to populate a model file.
6- Plugins
To interact with a world, model, or sensor in Gazebo, you can write plugins. These plugins can be either loaded from the command line or added to your SDF world file. You’ll learn about World Plugins later in the lesson.
Understanding the GUI
The Gazebo GUI is divided into four major sections:
- Scene
- Side Panel
- Toolbars
- Menu
Scene
The scene is where you will be spending most of your time, whether creating a simulation or running one. While you can use a trackpad to navigate inside the scene, a mouse is highly recommended.
You can pan the scene by pressing the left mouse button and dragging. If you hold down SHIFT in addition, you can now rotate the view. You can zoom in and out by using the mouse scroll or pressing and dragging the RMB.
Side Panel
The side panel on the left consists of three tabs:
- World
- Insert
- Layers
World
This tab displays the lights and models currently in the scene. By clicking on individual model, you can view or edit its basic parameters like position and orientation. In addition, you can also change the physics of the scene like gravity and magnetic field via the Physics option. The GUI option provides access to the default camera view angle and pose.
Insert
This is where you will find objects (models) to add to the simulation scene. Left click to expand or collapse a list of models. To place an object in the scene, simply left-click the object of interest under the Insert tab; this will bind the object to your mouse cursor, and now you can place it anywhere in the scene by left-clicking at that location.
Layers
This is an optional feature, so this tab will be empty in most cases. To learn more about Layers, click here.
Top Toolbar
Next, we have a toolbar at the top. It provides quick access to some cursor types, geometric shapes, and views.
Select mode
Select mode is the most commonly used cursor mode. It allows you to navigate the scene.
Translate mode
One way to change an object’s position is to select the object in the world tab on the side panel and then change its pose via properties. This is cumbersome and also unnatural, the translate mode cursor allows you to change the position of any model in the scene. Simply select the cursor mode and then use the proper axis to drag the object to its desired location.
Rotate mode
Similar to translate mode, this cursor mode allows you to change the orientation of any given model.
Scale mode
Scale mode allows you to change the scale, and hence, overall size of any model.
Undo/Redo
Since we humans are best at making mistakes, the undo tool helps us revert our mistakes. On the other hand if you undid something that you did not intend to, the redo tool can come to the rescue.
Simple shapes
You can insert basic 3D models like cubes, spheres, or cylinders into the scene.
Lights
Add different light sources like a spotlight, point light, or directional light to the scene.
Copy/Paste
These tools let you copy/paste models in the scene. On the other hand, you can simply press Ctrl+C to copy and Ctrl+V to paste any model.
Align
This tool allows you to align one model with another along one of the three principal axes.
Change view
The change view tool lets you view the scene from different perspectives like top view, side view, front view, bottom view.
Bottom Toolbar
The Bottom Toolbar has a neat play and pause button. This button allows you to pause the simulation and conveniently move objects around. This toolbar also displays data about the simulation, such as the simulation time, the real time, and the relationship between the two. There is also an frames-per-second counter that can be found to gauge your system’s performance for any given scene.
Menu
The Menu: Some of the menu options are duplicated in the Toolbars or as right-click context menu options in the Scene. If you click on Edit, you can switch to the Building Editor to design building or the Model Editor to build models. We will be working in both of these features in the upcoming concepts.
Lesson 1-6
simulating the first robot
1- Create directories for the world and model files
$ mkdir /home/workspace/myrobot
$ cd /home/workspace/myrobot
$ mkdir world && mkdir model
Construct the robot’s chassis
2- Launch Gazebo and switch to the model editor
gazebo
3- create the robot Chassis In the model editor, drop a box anywhere in the scene and double click it to change its position and dimension as follows: Make sure to scroll down to the bottom to edit the object position
- Position: [X, Y, Z] = [0, 0, 0.2]
- Visual and Collision geometry: [X, Y, Z] = [0.3, 1.0, 0.1]
Attach wheels to the robot’s chassis
4- Construct the robot wheels
Insert a cylinder inside the scene and then edit its position and orientation: Make sure to scroll down to the bottom to edit the object position.
- Z pose = 0.2
- Roll = 1.5707 rad
- Visual and Collision geometry: [Radius, Length] = [0.2, 0.1]
Then, create a copy of this wheel and paste it on the other side of the robot. 5- Connect wheels to the chassis via joints
- Joint Types: Revolute
- Parent: Chassis
- Child: Wheel
- Joint Axis: Z
- Align Links Joint 1: mid x; minimum y and reverse
- Align Links Joint 2: mid x; maximum y and reverse
6- Save the model file
- Model: Save it as robot in /home/workspace/myrobot/model
- Exit the Model Editor
7- Save the world file
- World: Save is as myworld in /home/workspace/myrobot/- world
Exit Gazebo
Launching Gazebo world file from disk
To load the world file with Gazebo open a terminal, change the working directory and launch it:
$ cd /home/workspace/myrobot/world/
$ gazebo myworld
SDF Format
As you learned earlier, world and model files in Gazebo are formatted using the Simulation Description Format or SDF for short. You can now open the contents of either the world file or model file and check to see if it follows the SDF format. To open the contents of the world file inside a terminal type in the following:
$ cd /home/workspace/myrobot/world/
$ gedit myworld
The SDF format in this world file should follow this general structure:
<?xml version="1.0" ?>
<sdf version="1.5">
<world name="default">
<physics type="ode">
...
</physics>
<scene>
...
</scene>
<model name="box">
...
</model>
<model name="sphere">
...
</model>
<light name="spotlight">
...
</light>
</world>
</sdf>
Next, you will learn how to write a Plugin to interact with your World in Gazebo.
Lesson 1-7 Writing a plugin
Simple steps to interact with a World in Gazebo through a World plugin
1- Create a directory for scripts inside myrobot to store a hello.cpp
file
$ cd /home/workspace/myrobot
$ mkdir script
$ cd script
$ gedit hello.cpp
Inside hello.cpp
, include this code:
#include <gazebo/gazebo.hh>
namespace gazebo
{
class WorldPluginMyRobot : public WorldPlugin
{
public: WorldPluginMyRobot() : WorldPlugin()
{
printf("Hello World!\n");
}
public: void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
{
}
};
GZ_REGISTER_WORLD_PLUGIN(WorldPluginMyRobot)
}
2- Create a CamkeLists.txt file
$ cd /home/workspace/myrobot
$ gedit CMakeLists.txt
Inside, CMakeLists.txt, include the following:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
find_package(gazebo REQUIRED)
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")
add_library(hello SHARED script/hello.cpp)
target_link_libraries(hello ${GAZEBO_LIBRARIES})
3- Create a build directory and compile the code
$ cd /home/workspace/myrobot
$ mkdir build
$ cd build/
$ cmake ../
$ make # You might get errors if your system is not up to date!
$ export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:/home/workspace/myrobot/build
4- Open your world file and attach the plugin to it
$ cd /home/workspace/myrobot/world/
$ gedit myworld
Copy this code
<plugin name="hello" filename="libhello.so"/>
and paste it under
<world name="default">
5- Launch the world file in Gazebo to load both the world and the plugin
$ cd /home/workspace/myrobot/world/
$ gazebo myworld
6- Visualize the output
A Hello World! message is printed in the terminal. This message interacts with the Gazebo World that includes your two-wheeled robot.
Troubleshooting
In case your plugins failed to load, you’ll have to check and troubleshoot your error. The best way to troubleshoot errors with Gazebo is to launch it with the verbose as such:
$ gazebo myworld --verbose
GitHub Repo
I hope you followed along with these instructions, built your first model in Gazebo, included in an empty world, and interacted with the world through a World Plugin. You can always clone this lab from GitHub by clicking here. Follow the instructions in the Readme file to launch the world.
Lesson 1-8 Exploring the building editor
Building Editor
Follow these steps to design a house for your robot with the Building Editor tool in Gazebo:
- open a termianl and launch Gazebo
- click edit and launch the building editor
- Inside the 2d view section, create walls and edit their length, height, and thickness
- add features such as window, door, and/or stairs
- add colors and/or textures
- save your model to
/home/worksapce/myrobot/model
- exit the building editor and get back to the gazebo main interface
Lesson 1-9 Outro
The following wiki, pages and posts are tagged with
Title | Type | Excerpt |
---|