26.About ROS2 Gazebo

 

1.Gazebo introduction

Gazebo is the most commonly used 3D physics simulation platform in ROS systems. It supports a dynamics engine and can achieve high-quality graphics rendering. It can not only simulate robots and surrounding environments, but also add physical attributes such as friction and elastic coefficients.

For example, if we want to develop a Mars rover, we can simulate the Martian surface environment in Gazebo.Another example is that we are making drones. Due to battery life and flight restrictions, we are unable to frequently conduct experiments with real objects. At this time, we might as well use Gazebo to simulate first, and then deploy the algorithm to real objects for operation after the algorithm is almost developed.

Therefore, simulation platforms like Gazebo can help us verify robot algorithms, optimize robot design, test robot scenario applications, and provide more possibilities for robot development.

Note: This chapter is only for understanding and learning. The environment is not configured in the tutorial because real machine debugging is used directly

 

2. Installation and operation

Install through the command apt

Then you can operation it with the following command

Or the following command

After running, you can see the following page:

img

To ensure smooth loading of the model, please download and place the offline model in the ~/.gazebo/models path. The download link is as follows:https://github.com/osrf/gazebo_models

 

3. Gazebo starts the node and service

  1. View nodes

Correct return:/gazebo

  1. Check the external services provided by the node:

You can see the following results:

Out of the last few regular services, we only pay attention to the first three special services:

 

4. Create workspace and function package

Create a gazebo_demo folder, create a src file in it, and then create our function package myrobot in the src folder (take c++ as an example).

Enter the directory of myrobot, create the launch and urdf folders, and modify the CMakeLists.txt file. This step is similar to that in rviz. Create a demo01_base.urdf file in the urdf folder. This file is a simple demonstration file with only a basic cube.

The difference between this file and the previous file is that the collision and intertial attributes are added, both of which are physical related parameters. This will not be discussed.

 

5. Write launch file

When writing a launch file, the launch file mainly starts two parts: starting the Gazebo file, and then loading the robot model into Gazebo.

This command is to start Gazebo. It is just a startup command. It is not particularly complicated. The following is the command to load the model:

Note that the last two parameters of this command -entity is the name in the model file, and -file is the parameter loaded through the urdf file. Later we can also see that the model is loaded through the topic topic. The complete startup file is as follows:

After starting, you can see the following Gazebo model:

img

You can see the red model because the Gazebo label setting was added at the end.

 

6. Ignition: The next generation of Gazebo

With the advancement of technology, the Gazebo simulation platform is also constantly iterating. The new generation of Gazebo is named Ignition. It has major changes in rendering effects and simulation smoothness. We might as well give it a try.

After running successfully, the simulation interface of Ignition and the Rviz host computer will be opened. We can see the image data released after the RGBD camera simulation.

image-20220528151350359

image-20220528151358409