Gazebo Simulator


The intention of this guide is to familiarize you with the Gazebo simulator. Make sure you have gone through the computer setup before proceeding.

What is a Robot Simulator?


In short, a robot simulator allows one to interact with a robot and its environment virtually without requiring a real robot. Robot simulators often provide the following functionality,

The Gazebo Simulator


Topics in HRI

We will use the Gazebo simulator for this course. It offers a number of powerful abilities is quite customizable.

Starting the Simulator


  1. Start roscore.
    Go to the terminal and run the following command.

    $ roscore

    You should see an output that looks like the following.
    
          ... logging to ~/.ros/log/9cf88ce4-b14d-11df-8a75-00251148e8cf/roslaunch-machine_name-13039.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://machine_name:33919/
          ros_comm version 1.15.8
    
          SUMMARY
          ======
    
          PARAMETERS
           * /rosdistro: noetic
           * /rosversion: 1.15.8
    
          NODES
    
          auto-starting new master
          process[master]: started with pid [13054]
          ROS_MASTER_URI=http://machine_name:11311/
    
          setting /run_id to 9cf88ce4-b14d-11df-8a75-00251148e8cf
          process[rosout-1]: started with pid [13067]
          started core service [/rosout]
                


  2. Lunch Gazebo.
    You can launch the robot in many simulated worlds. To see a list of worlds, type in

    $ roslaunch turtlebot3_gazebo turtlebot3_

    and double tap tab, which should offer you a list of possible simulated worlds. For instance, if we use the turtlebot3_gazebo_house.launch option, you will some terminal output and a visualization like the following will pop up.
    Screenshot of a turtlebot3 waffle within house. Includes gazebo interface.
    If you want to create your own world, you can put your robot in an empty world and then follow instructions for populating your own world later in this page.

    $ roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch

Using the Gazebo GUI


The Gazebo website has a guide on using the Gazebo graphical interface.

Using RViz with the Simulator


To launch an instance of RViz, run the following command.

$ roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch

This command takes care of preparing the setup for you, so the RViz instance would be ready for you from the beginning. If all goes well, you should have a window that looks like the following.

Screenshot of rviz interface for turtlebot3 waffle within house.

RViz vs Gazebo

While both RViz and Gazebo are graphical user interfaces that seem somewhat similar, their nature is quite different. Gazebo is a simulator. It places robots in a virtual world and allows users to give it commands and generates simulated sensor data. This sensor data is not very human friendly (e.g. some numbers and binaries). RViz simply visualizes this generated sensor data so that human users can understand what their robot observes in human terms.

Topics


Note that like any other ROS node, the robot simulator publishes and subscribe to topics. In this case, the simulator publishes and subscribes to the same topics that real robot does.
The following documentation gives high level details of a few topics. To explore more use the tools discussed in ROS Resources.

cmd_vel

When you publish to this topic, you'll set the robot's velocity. The linear.x direction sets forward velocity and angular.z sets angular velocity.

scan

The robot's LiDAR publishes measurements to this topic. LiDAR is used for measuring distance via lasers. The laser scan message consists of a number of attributes,


$ rosmsg show sensor_msgs/LaserScan
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
float32 angle_min
float32 angle_max
float32 angle_increment
float32 time_increment
float32 scan_time
float32 range_min
float32 range_max
float32[] ranges
float32[] intensities
     

For initial purposes, the most important one is ranges, a list of 360 numbers where each number corresponds to the distance to the closest obstacle from the LiDAR at various angles. Each measurement is 1 degree apart. The first entry in the array corresponds to what is in front of the robot.

camera/rgb/image_raw

Publishes the RGB image seen by the robot's camera.

Populating a Simulated World


To populate a simulated world, use the "insert" menu (top left) in Gazebo. This menu will show a number of 3D models that can be inserted into Gazebo.

A list of insertable 3D objects into Gazebo.
Simply click on one and drag them into your world. Below you can see the house environment populated with a cylinder and a trashcan.
The house environment populated with a cylinder and a trashcan.

For more on populating the world, refer the to Gazebo manual.

Saving The World

If you have altered a world, you can save it using file->save world from within Gazebo. You should save the world in the directory catkin_ws/src/intro_robo/intro_robo_utils/worlds as a file with the .world extension.

Loading the World

Assuming you performed the steps above, you should be able to reload your world after shutting down Gazebo via the following command. Do not include the .world extension.

$ roslaunch intro_robo_utils turtlebot3_custom_world.launch world:=name_of_the_world

Video Recording a Simulation


To record what is happening in your simulation, simply click on the video camera icon on the top right of your simulation. It should provide you with a number of format options. For our purposes, select the mp4 format and proceed with recording your simulation. To stop the recording click again on the video camera icon. Gazebo should pop up a file manager window, ask you for a file name, and request an address for saving the file.

The gazebo record icon.

Once you have the mp4 video, inspect and ensure that it captures your intended behavior. In the next step, we are going to turn the video into a gif via the command line tool ffmpeg. Note that while the command itself is very long, you only need to replace the italics to fit it for your own purposes.

$ ffmpeg -i input_name.mp4 -vf "eq=brightness=brightness,fps=frames_per_sec,scale=width:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output_name.gif

Here is a description of what each italic represents and the recommended values:

Let us know if you run into any issues with this command.

Shutting Down the Simulator


To shut down the simulator, go back to the terminal in step 2 and hit Ctrl-C.