Gazebo is a robotic simulator that comes installed when you install ROS, but actually is a completely separate project now. It is extremely feature rich (reference here), it has a great community, supports all families of robots, a wide range of actuators and sensors, and the best part is that it's open source so there's a lot of documentation available (complete thing here). The source code is hosted on bitbucket.
Official website: http://gazebosim.org/
Let's get started by launching gazebo, there are multiple ways of doing this if you've installed gazebo separately, but if you've installed it with ROS, then this particular method will be helpful:
roscore
rosrun gazebo_ros gazebo
There are other methods as well, as we will see later:
gazebo
command after starting roscore
. This does the same thing as aboveYou must see the window below
Gazebo simulator
The following things can be noted from the window that just opened:
Everything in Gazebo is an object. Even the world which you see is through a camera which you can control using your mouse. Click the GUI property on the property window to know everything about the camera which you're using to see everything on the world window and the grid that you can see on the floor.
You can click Physics in the property window and explore the physics properties of your world. Play around with various objects in the property window to know more about them. A notable one is the Models -> ground_plane -> link property which is basically the ground surface in the world. It's already existing and everything happens over it.
In RViZ, there was a configuration file to load RViZ with the items that we like. Similarly, in Gazebo there is something called the world file which stores the configurations and the entire world objects. You can click on File -> Save World as and save it as an SDF file somewhere and open the SDF file. It's basically an XML based description file. You can get all the worlds available already on your system at the path "/usr/share/gazebo-9/worlds" (ROS melodic uses gazebo-9). More on that here. You can load a world by the following method:
gazebo worlds/pioneer2dx.world
rosrun gazebo_ros gazebo worlds/pioneer2dx.world
and it would produce the exact same results.Make sure that the currently running gazebo instance is closed before this and that the roscore
is running. After the window opens, you must be able to see a robot in the middle of the world.
Gazebo actually runs two executables when we run the command gazebo
. They're gzserver and gzclient. The gzserver handles simulation and all underlying execution of the physics engine. The gzclient simply shows the results on a Qt based GUI. This makes gazebo easy to use. We simply test everything on gazebo first, later link it with actual hardware and run only the gzserver on a robot, thus reducing the resources required for displaying the GUI.
Let's create an environment, a static world in which we'll later learn how to spawn a robot. Follow the following steps to do this:
catkin_make
in your workspace directory.cd ~/ROS_workspaces/ros_ws
catkin_make
roscore
rosrun gazebo_ros gazebo
roscd intro_robot_description/worlds/
rosrun gazebo_ros gazebo FirstWorld.world
roscore
is already running in backgroundWe could also do:
rosrun gazebo_ros gazebo ~/ROS_workspaces/ros_ws/src/intro_robot_description/worlds/FirstWorld.world
You'll see the gazebo window open with the world that we created and saved earlier.
Gazebo launched with the world file created
Let's see how to spawn (and later, control) a robot in Gazebo. It's similar to VReP but with a little additions for this, because simulations requires more information than simple visualization. For this, we'll spawn (and control) a four wheeled vehicle.
There's also an official tutorial about using a URDF in Gazebo, link here (you can check it out after reading this page).
We'll use XACRO to make this robot model. We'll follow the following procedure to develop code for this model:
To spawn a robot in gazebo, we use a node in the gazebo_ros package. The node is spawn_model. You can know more about it by running:
rosrun gazebo_ros spawn_model --help
We basically pass it the following arguments:
rosrun gazebo_ros spawn_model --help
To launch everything, run the command:
roslaunch intro_robot_description RobotLauncher.launch
The window that opens must look something like what's shown below.
Robot model spawned in Gazebo simulator
The <gazebo ... > ... </gazebo> tag is used to give Gazebo specific properties to the model. It is used to describe everything for Gazebo, from simulation properties like damping and friction to even various sensors to the model. The gazebo tag is used in three major forms, for reference to a link, joint and entire robot. It has different elements under each category. We'll discuss a few in brief. The official page on this here.
Usually, we do the following to use a gazebo tag:
The <gazebo ...> ... </gazebo> tag has the following attributes:
It has the following elements:
When referenced to links, it has the following elements:
For example:
<gazebo reference="base_link">
<material>Gazebo/DarkGrey</material>
</gazebo>
There are also sensors added through this manner (more in the "Adding a sensor" section) through this tag:
The <gazebo> tag contains a <sensor> tag to add all kinds of sensors that gazebo supports. Everything in the gazebo tag is basically a plugin. So here we talk about sensor plugins in Gazebo. Here are a few things that you must remember before starting up with sensors:
In the gazebo description file, add the following:
You can use this launch file with this RViZ configuration, run the command:
roslaunch intro_robot_description RobotLauncher.launch rviz:="true"
In case the above command throws errors (this happens because of the launch order being random). This creates some clock issues for RViZ and Gazebo. This is in fact one of the reasons why the gazebo files and robot description files are kept in separate packages and are launched using different launch files. We'll see this later, for now you could run the following commands on different terminals:
roslaunch intro_robot_description RobotLauncher.launch
rosrun rviz rviz -d $(rospack find intro_robot_description)/rviz/RobotViewer.rviz
rosrun joint_state_publisher joint_state_publisher
rosrun robot_state_publisher robot_state_publisher
Visualization of results on Gazebo
Visualization of results on RViZ
Gazebo uses the /use_sim_time parameter (on the ROS Parameter server) to synchronize ROS time with Gazebo simulation time. If it's true (which is the default configuration), then Gazebo publishes /clock as a simulation time clock. It it's set to false, then Gazebo and ROS follow individual times.
More on this here.Gazebo packages are kept isolated from robot description packages because of some launch issues, launch files do not launch nodes in a specific order.
Doing this makes it a little difficult to launch everything because now we have two launch files for the project, but on the other hand, the execution problem is then solved. The next tutorial will explore this very option.
~/.ignition/fuel/config.yaml
from https://api.ignitionfuel.org to https://api.ignitionrobotics.org