0. 简介
官网镇楼:
Gazebogazebosim.org
Gazebo 同我们常用的 vrep, adams 一样,都是内置物理引擎(Physics Engine)的动力学仿真软件,只不过 ROS 直接集成了 Gazebo,像其他开源软件(OpenCV,OMPL)一样。
By the way,vrep 也是提供了 ros 接口的,不过我一般用内置的 lua 脚本、外部的 python、甚至 matlab 来实现 vrep 仿真。
先看下 gazebo 官方教程有哪些版块,如下:

再看下与 ROS 相关的版块有哪些,如下:

1. gazebo_ros_pkgs 元功能包
Gazebo 通过 gazebo_ros_pkgs
元功能包与 ROS 建立连接。
https://github.com/ros-simulation/gazebo_ros_pkgs
gazebo_ros_pkgs is a set of ROS packages that provide the necessary interfaces to simulate a robot in the Gazebo 3D rigid body simulator for robots. It integrates with ROS using ROS messages, services and dynamic reconfigure.
From https://wiki.ros.org/gazebo_ros_pkgs
gazebo_ros_pkgs
元功能包默认安装路径 opt/ros/kinetic/share
,里面只有一个 package.xml
文件,看下里面的内容:
<?xml version="1.0"?>
<package format="2">
<name>gazebo_ros_pkgs</name> <!-- This is a meta package! -->
<version>2.5.19</version>
<description>Interface for using ROS with the <a href="http://gazebosim.org/">Gazebo</a> simulator.</description>
<maintainer email="jrivero@osrfoundation.org">Jose Luis Rivero</maintainer>
<license>BSD,LGPL,Apache 2.0</license>
<url type="website">http://gazebosim.org/tutorials?cat=connect_ros</url>
<url type="bugtracker">https://github.com/ros-simulation/gazebo_ros_pkgs/issues</url>
<url type="repository">https://github.com/ros-simulation/gazebo_ros_pkgs</url>
<author>John Hsu, Nate Koenig, Dave Coleman</author>
<buildtool_depend>catkin</buildtool_depend>
<exec_depend>gazebo_dev</exec_depend>
<exec_depend>gazebo_msgs</exec_depend>
<exec_depend>gazebo_plugins</exec_depend>
<exec_depend>gazebo_ros</exec_depend>
<export>
<metapackage/>
</export>
</package>
gazebo_ros_pkgs 元功能包包含了gazebo_ros
, gazebo_plugins
, gazebo_msgs
子功能包,如下图所示:

- gazebo_ros: provides ROS plugins that offer message and service publishers for interfacing with Gazebo through ROS.
- gazebo_plugins: robot-independent Gazebo plugins for sensors, motors and dynamic reconfigurable components.
- gazebo_msgs: message and service data structures for interacting with Gazebo from ROS.
2. gazebo_ros
Usage:
rosrun gazebo_ros debug
rosrun gazebo_ros gazebo # launch both the Gazebo server and GUI.
rosrun gazebo_ros gbdrun
rosrun gazebo_ros server
rosrun gazebo_ros client # launch the Gazebo GUI
rosrun gazebo_ros spawn_model
rosrun gazebo_ros perf
(1)Using roslaunch
to Open World Models
pkg="gazebo_ros"
- 启动 empty Gazebo world
roslaunch gazebo_ros empty_world.launch
参数(Arguments):
- paused: start Gazebo in a paused state (default false)
- use_sim_time: tells ROS nodes asking for time to get the Gazebo-published simulation time, published over the ROS topic /clock (default true)
- gui: Launch the user interface window of Gazebo (default true)
- recording: enable gazebo state log recording
- debug: start gzserver (Gazebo Server) in debug mode using gdb (default false)
- verbose: run gzserver and gzclient with --verbose, printing errors and warnings to the terminal (default false)
其他的 Demo Worlds:
roslaunch gazebo_ros willowgarage_world.launch
roslaunch gazebo_ros mud_world.launch
roslaunch gazebo_ros shapes_world.launch
roslaunch gazebo_ros rubble_world.launch
其中,mud_world.launch
文件内容如下:
<launch>
<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="worlds/mud.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="true"/>
<arg name="recording" value="false"/>
<arg name="debug" value="false"/>
</include>
</launch>
- CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(YOURROBOT_gazebo_plugins)
find_package(catkin REQUIRED COMPONENTS
gazebo_ros
)
# Depend on system install of Gazebo
find_package(gazebo REQUIRED)
include_directories(include ${catkin_INCLUDE_DIRS} ${GAZEBO_INCLUDE_DIRS} ${SDFormat_INCLUDE_DIRS})
# Build whatever you need here
add_library(...) # TODO
catkin_package(
DEPENDS
gazebo_ros
CATKIN_DEPENDS
INCLUDE_DIRS
LIBRARIES
)
- package.xml
<build_depend>gazebo_ros</build_depend>
<exec_depend>gazebo_ros</exec_depend>
(2)Using roslaunch
to Spawn URDF Robots
"ROS Service Call" Robot Spawn Method
This method uses a small python script calledspawn_model
to make a service call request to thegazebo_ros
ROS node (named simply "gazebo" in the rostopic namespace) to add a custom URDF into Gazebo.
rosrun gazebo_ros spawn_model -file `rospack find MYROBOT_description`/urdf/MYROBOT.urdf -urdf -x 0 -y 0 -z 1 -model MYROBOT
# -file 指定 model xml 文件的路径
# -urdf 显示地指定 xml 文件是 urdf 文件
# -x -y -z 初始 pose

3. gazebo_plugins
(1)Plugins 类型
- ModelPlugins: provide access to the physics::Model API
- SensorPlugins: provide access to the sensors::Sensor API
- VisualPlugins: provide access to the rendering::Visual API
(2)添加 ModelPlugins
ModelPlugin
is inserted in the URDF inside the<robot>
element. It is wrapped with the<gazebo>
pill, to indicate information passed to Gazebo.
例如:
<robot>
... robot description ...
<gazebo>
<plugin name="differential_drive_controller" filename="libdiffdrive_plugin.so">
... plugin parameters ...
</plugin>
</gazebo>
... robot description ...
</robot>
(3)添加 SensorPlugins
Sensors in Gazebo are meant to be attached to links, so the <gazebo> element describing that sensor must be given a reference to that link.
例如:
<robot>
... robot description ...
<link name="sensor_link">
... link description ...
</link>
<gazebo reference="sensor_link">
<sensor type="camera" name="camera1">
... sensor parameters ...
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
... plugin parameters ..
</plugin>
</sensor>
</gazebo>
</robot>
4. gazebo && ros_control
移步至之前的博客:
丁洪凯:【ROS 学习笔记】ros_controlzhuanlan.zhihu.com
