Skip to content

Gazebo Onboarding

winkhoo edited this page Mar 28, 2022 · 5 revisions

What is Gazebo?

"Gazebo is a 3D dynamic simulator with the ability to accurately and efficiently simulate populations of robots in complex indoor and outdoor environments. While similar to game engines, Gazebo offers physics simulation at a much higher degree of fidelity, a suite of sensors, and interfaces for both users and programs." -- Gazebo official guide

Typical uses of Gazebo include:

testing robotics algorithms,

designing robots,

performing regression testing with realistic scenarios

A few key features of Gazebo include:

multiple physics engines,

a rich library of robot models and environments,

a wide variety of sensors,

convenient programmatic and graphical interfaces

1. Building a Robot using SDF model

Read through the Official Gazebo Tutorials: Build a Robot. After this tutorial, you should be able to spawn an SDF-defined robot in Gazebo. The following are some useful notes:

  • To make your SDF model visible to Gazebo you must 1)have your model follow the formatting rules for the Gazebo Model Database directory structure. 2)put your model inside the Gazebo model search path. Here is an example to create a My Robot model defined by model.sdf file inside the default search path (~/.gazebo/models)

  • It is possible to put your SDF model in other directories. Let's say you put it inside your ROS workspace ~/ros_ws/src/my_package/models, then you have to run $ export GAZEBO_MODEL_PATH=~/ros_ws/src/my_package/models to add your path to the gazebo search path.

  • Gazebo requires that mesh files be formatted as STL, Collada or OBJ, with Collada and OBJ being the preferred formats. If you use STL file, all texture information (e.g., colors) is lost.

Skill check

build a simple model and spawn inside the Gazebo using the SDF model. For example, a table with five links (i.e., tabletop + four legs).

2. Launch Gazebo using roslaunch command.

This part corresponding to the section Using roslaunch to Open World Models.

  • The world file in the tutorial is within the /worlds directory of the Gazebo resource path. Alternatively, you can put your world file inside your ROS package src path then use $(find pkg) command to locate it.

Skill check

Create a ROS package. Create a world file that loads your created SDF-based model above, put it inside the /world subfolder of your ROS package root (e.g., ~/ros_ws/src/ros_pkg/world/my_world.world). Create a launch file for your ROS package that launches Gazebo and spawn your SDF-based model.

3. Building a robot using URDF model.

According to the statement, SDF is superior to URDF in many ways. However, we use URDF instead of SDF to describe a Robot in ROS. For example, Rviz visualizes the robot with the help of URDF (not SDF).

3.1 URDF

Take a look at this tutorial about building a robot model with URDF. You will find that the syntax is quite similar.

The Xacro is commonly used to crate URDF in a more systematic way. Take a look at this tutorial.

3.1 What to include in order to use URDF in Gazebo

Take a look at this tutorial.

  • An <inertia> element within each <link> element must be properly specified and configured.

3.2 Using roslaunch to Spawn URDF Robots

Take a look at this tutorial. There are two methods documented, but you will find most packages online used the "ROS Service Call Spawn Method".

Skill check

In the same ROS package that you created in 2. Launch Gazebo using roslaunch command , create another folder /urdf. Use XACRO format to model your robot then put it into the /urdf folder. Create a launch file and use the "ROS Service Call Spawn Method" to launch your model in Gazebo.

4. Connect Gazebo to ros_control

This will guide you to add actuators for your robot and setting up the controllers.

Many ROS drivers of a real robot (e.g., Universal_Robots_ROS_Driver) use ros_control to structure the controllers. In Gazebo, we also use ros_control to structure the controller. This makes it much easier to transient from simulation to reality.

  • Add transmission elements to link actuators to joints
  • Add the gazebo_ros_control plugin into your URDF/XACRO
  • Create a .yaml config file to define your controller (see [here] for some commonly used controllers)
  • In the launch file, use controller_manager package to spawn or load the controllers.

After this tutorial, you should be able to control the motion of the simulated robot using ROS messages or action services.

DEBUG

Here I listed some problems that I have encountered and finally figured out the cause. Please feel free to contribute to the list.

  • When using roslaunch, Gazebo sometimes can't boot properly.

    • This may be caused by your last Gazebo server wasn't being exited properly. Go to the Ubuntu service monitor, see if the process named "gzservice" is running. If so, manually kill this process before roslaunch.
  • Controller manager can’t load controllers properly.

    • Some controllers will load only after the simulation start. When started gazebo in paused mode, some controllers will not load until you started the simulation.
  • Newly created simple Xacro-based robot didn’t show up in Gazebo.

    • The <initial> tag of my link is not specified, which is however required in Gazebo.

Training video

Hui showed a step-by-step demo on building a simple robot in Gazebo using URDF and connected with ros_control. The recorded video is uploaded to our google drive (ask for permissions if you don't have access)