Gazebo機器人仿真學習探索筆記(二)基本使用說明

本文介紹了Gazebo7的使用方法,包括如何啟動預設環境模型,理解環境文件結構,以及如何分別運行Gazebo服務器和客戶端。此外,還詳細說明了Gazebo的快捷鍵操作方式,並提供了模型和世界文件的基本概念。

在完成Gazebo7安裝後,需要熟悉Gazebo,方便之後使用。

部分源代碼可以參考:https://bitbucket.org/osrf/gazebo/src/

如果還沒有安裝請參考之前內容完成安裝,快速打開ubuntu終端的方式(CTRL+ALT+t):

~$ gazebo


Gazebo7自帶了很多構建好的環境模型,可以直接使用,這些模型位置和安裝路徑相關:

relaybot@relaybot-desktop:~$ ls /usr/share/gazebo-7/worlds/
actor.world                    pioneer2dx.world
blank.world                    plane_demo.world
camera.world                   plugin.world
cart_demo.world                polyline.world
cessna_demo.world              population.world
contact.world                  pr2.world
depth_camera.world             presentation.world
elevator.world                 pressure_sensor.world
empty_1_0.world                projector.world
empty_bullet.world             quad_rotor_demo_2.world
empty_sky.world                quad_rotor_demo.world
empty.world                    random_velocity.world
everything.world               ray_cpu.world
flocking.world                 ray_noise_plugin.world
force_torque_demo.world        road_textures.world
friction_demo.world            road.world
gripper.world                  robocup09_spl_field.world
heightmap_dem.world            robocup14_spl_field.world
heightmap.world                robocup_3Dsim.world
hydra_demo.world               rubble.world
imu_demo.world                 seesaw.world
initial_velocity.world         shapes_bitmask.world
joint_damping_demo.world       shapes_layers.world
joint_friction_demo.world      shapes.world
joints.world                   sim_events.world
lift_drag_demo.world           simple_arm.world
lights.world                   simple_gripper.world
linear_battery_demo.world      single_rotor_demo.world
logical_camera.world           sonar_demo.world
magnetometer.world             sphere_atlas_demo.world
mud_bitmask.world              stacks.world
mud.world                      timer_gui.world
multilink_shape.world          torsional_friction_demo.world
nested_model.world             transporter.world
openal.world                   trigger.world
ortho.world                    twin_rotor_demo.world
osrf_elevator.world            underwater.world
pioneer2dx_camera.world        willowgarage.world
pioneer2dx_laser_camera.world  wireless_sensors.world
pioneer2dx_laser.world
在ubuntu下默認的路徑爲:/usr/share/gazebo-7/worlds/。



啓動一個示例,如下:

/usr/share/gazebo-7/worlds$ gazebo lift_drag_demo.world


啓動一個帶有天空的環境:

/usr/share/gazebo-7/worlds$ gazebo empty_sky.world


<?xml version="1.0" ?>
<sdf version="1.5">
  <world name="default">
    <scene>
      <sky>
        <clouds>
          <speed>12</speed>
        </clouds>
      </sky>
    </scene>
    <!-- A global light source -->
    <include>
      <uri>model://sun</uri>
    </include>
    <!-- A ground plane -->
    <include>
      <uri>model://ground_plane</uri>
    </include>
  </world>
</sdf>

注意這個環境中,天空中只有雲彩速度爲12,場景中還有光源和大地。

啓動一個帶有機器人模型的環境:

/usr/share/gazebo-7/worlds$ gazebo pioneer2dx_laser_camera.world


<?xml version="1.0" ?>
<sdf version="1.5">
  <world name="default">
    <!-- Ground -->
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <!-- A global light source -->
    <include>
      <uri>model://sun</uri>
    </include>

    <!-- Pioneer2dx model -->
    <model name="pioneer2dx">
      <include>
        <uri>model://pioneer2dx</uri>
      </include>

      <include>
        <uri>model://hokuyo</uri>
        <pose>0.2 0 .38 0 0 0</pose>
      </include>

      <include>
        <uri>model://camera</uri>
        <pose>0.2 0 .3 0 0 0</pose>
      </include>

      <joint name="camera_joint" type="revolute">
        <parent>pioneer2dx::pioneer2dx::chassis</parent>
        <child>pioneer2dx::camera::link</child>
        <axis>
          <xyz>0 0 1</xyz>
          <limit>
            <lower>0</lower>
            <upper>0</upper>
          </limit>
        </axis>
      </joint>

      <joint name="laser_joint" type="revolute">
        <parent>pioneer2dx::pioneer2dx::chassis</parent>
        <child>pioneer2dx::hokuyo::link</child>
        <axis>
          <xyz>0 0 1</xyz>
          <limit>
            <lower>0</lower>
            <upper>0</upper>
          </limit>
        </axis>
      </joint>

    </model>

  </world>
</sdf>

參考上述模板,可以學習環境文件,主要由大地,光源,機器人模型,機器人模型包括本體,激光和攝像頭等具體配置。

除此之外,還有gzserver和gzclient。

gazebo命令实际上运行两个不同的可执行文件。 第一个称为gzserver,第二个称为gzclient。
gzserver可执行程序运行物理更新循环和传感器数据生成。 这是Gazebo的核心,可以独立于图形界面使用。 您可能会在论坛中看到“run headless”这个短语。 这个短语相当于只运行gzserver。 一个示例用例将涉及在不需要用户界面的云计算机上运行gzserver。
gzclient可执行文件运行基于QT的用户界面。 此应用程序提供了一个很好的可视化的模拟,并在各种模拟属性方便的控制。

當然,這兩個可以分別啓動。

gazebo使用的快捷鍵:

ActionOperationInstruction
MODE
Enter Selection mode (default mode)Escpress Esc for mode to select models and right-click for context menu
Enter Rotate moderpress "r" for Rotate (model) mode
Enter Translate modetpress "t" for Translate (model) mode
Enter Scale modespress "s" for Scale (model) mode
Enter Snap modenpress "n" for Snap (model) mode
MODELS
Delete modelDeletepress Delete when a model is selected to delete from scene
Copy modelCtrl + cpress Ctrl + "c" when model is selected to copy
Paste modelCtrl + vpress Ctrl + "v" to paste copied model
MANIPULATING MODELS
Rotate modelrpress "r" for Rotate mode; click model & rotate using markers
Translate modeltpress "t" for Translate mode; click model & translate using markers
Scale modelspress "s" for Scale mode; click model & scale using markers
Constrain along axisx/y/zhold key while manipulating model to constrain movement along that axis
Snap to 45° when rotatingCtrl + draghold Ctrl while rotating model to rotate in 45° increments
Snap to grid when translatingCtrl + draghold Ctrl while translating model to snap to grid
Snap to 1 m when scalingCtrl + draghold Ctrl while scaling mode to scale in 1 m increments
Snap when insertingCtrl + draghold Ctrl while inserting model to enable snap to grid
Snap models togethernpress "n" for Snap mode; click one link, then a second to snap first link to second
GUI LAYOUT
Hide toolbarsCtrl + hhide/show top toolbar and bottom time panel
Enter fullscreenF11enter/exit fullscreen
ActionOperationInstruction
EDITORS
Open Model EditorCtrl + mopen Model Editor to construct or edit models
Open Schematic View (Model Editor)Ctrl + eopen Schematic View in Model Editor
Open Building EditorCtrl + bopen Building Editor to construct buildings
Show floor plan (Building Editor)fshow/hide floor plan in Building Editor 2D View
Show building features (Building Editor)gshow/hide building features in Building Editor 2D View
New canvas (both Editors)Ctrl + ncreate new canvas
Save model (both Editors)Ctrl + ssave model for later use
Save as (both Editors)Ctrl + Shift + ssave model for later use & give it a name
Exit (both Editors)Ctrl + xexit Editor
WORLD
Save worldCtrl + spress Ctrl + "s" to save world for later use
Save asCtrl + Shift + spress Ctrl + Shift + "s" to save world for later use & give it a name
Reset worldCtrl + rpress Ctrl + "r" to reset world to its original state
Reset model posesCtrl + Shift + rpress Ctrl + Shift + "r" to reset models to their original poses
DATA
Visualize topicsCtrl + topen dialog with list of topics currently advertized
Log dataCtrl + dopen dialog to record log files
MISCELLANEOUS
Quit GazeboCtrl + qpress Ctrl + "q" to quit Gazebo

Gazebo 鼠標控制
場景視角改變


注意這裏gazebo並不能與ROS通訊,如果需要可以使用下面命令:

rosrun gazebo_ros gazebo
rosrun gazebo_ros gzserver
rosrun gazebo_ros gzclient
rosrun gazebo_ros spawn_model
rosrun gazebo_ros perf
rosrun gazebo_ros debug

啓動後可以看到:

~$ rostopic list 
/clock
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/rosout
/rosout_agg
具體在之後筆記中再補充。


附件:官網教程。

Run Gazebo

These three steps will run Gazebo with a default world.

  1. Install Gazebo.

  2. Open a terminal. On most Ubuntu systems you can press CTRL+ALT+t

  3. Start Gazebo by entering the following at the command prompt.

    gazebo
    

Run Gazebo with a robot

Let's simulate something a bit more interesting by loading a world with a pioneer2dx.

  1. Open a terminal and enter the following command.

    gazebo worlds/pioneer2dx.world
    

Where are the worlds located?

You may have noticed the mysterious worlds/pioneer2dx.world argument in the above command. This instructs gazebo to find the pioneer2dx.world file, and load it on start.

World files are located in a versioned system directory, for example /usr/share/gazebo-7 on Ubuntu. If you have Gazebo 7.0 installed on Ubuntu, in a terminal type the following to see a complete list of worlds.

ls /usr/share/gazebo-7/worlds

For a Gazebo 7.0 installation on OS X using Homebrew, type the following to see a complete list of worlds.

ls /usr/local/share/gazebo-7/worlds

Client and server separation

The gazebo command actually runs two different executables for you. Thefirst is called gzserver, and the second gzclient.

The gzserver executable runs the physics update-loop and sensor datageneration. This is the core of Gazebo, and can be used independently of agraphical interface. You may see the phrase "run headless" thrown about inthe forums. This phrase equates to running only the gzserver. An exampleuse case would involve running gzserver on a cloud computer where a userinterface is not needed.

The gzclient executable runs a QT based userinterface. This application provides a nice visualization of simulation, andconvenient controls over various simulation properties.

Try running each of these executables. Open a terminal and run the server:

gzserver

Open another terminal and run the graphical client:

gzclient

At this point you should see the Gazebo user interface. You restart thegzclient application as often as you want, and even run multipleinterfaces.

This page describes each of the items involved in running a Gazebo simulation.

World Files

The world description file contains all the elements in a simulation, including robots, lights, sensors, and static objects. This file is formatted using SDF (Simulation Description Format), and typically has a .world extension.

The Gazebo server (gzserver) reads this file to generate and populate a world.

A number of example worlds are shipped with Gazebo. These worlds are located in <install_path>/share/gazebo-<version>/worlds.

Model Files

A model file uses the same SDF format as world files, but should only contain a single <model> ... </model>. The purpose of these files is to facilitate model reuse, and simplify world files. Once a model file is created, it can be included in a world file using the following SDF syntax:

<include>
  <uri>model://model_file_name</uri>
</include>

A number of models are provided in the online model database (in previous versions, some example models were shipped with Gazebo). Assuming that you have an Internet connection when running Gazebo, you can insert any model from the database and the necessary content will be downloaded at runtime.

Environment Variables

Gazebo uses a number of environment variables to locate files, and set up communications between the server and clients.

Starting with Gazebo 1.9.0, default values that work for most cases are compiled in. This means you don't need to set any variables.

Here are the variables:

GAZEBO_MODEL_PATH: colon-separated set of directories where Gazebo will search for models

GAZEBO_RESOURCE_PATH: colon-separated set of directories where Gazebo will search for other resources such as world and media files.

GAZEBO_MASTER_URI: URI of the Gazebo master. This specifies the IP and port where the server will be started and tells the clients where to connect to.

GAZEBO_PLUGIN_PATH: colon-separated set of directories where Gazebo will search for the plugin shared libraries at runtime.

GAZEBO_MODEL_DATABASE_URI: URI of the online model database where Gazebo will download models from.

These defaults are also included in a shell script:

source <install_path>/share/gazebo/setup.sh

If you want to modify Gazebo's behavior, e.g., by extending the path it searches for models, you should first source the shell script listed above, then modify the variables that it sets.

Gazebo Server

The server is the workhorse of Gazebo. It parses a world description file given on the command line, and then simulates the world using a physics and sensor engine.

The server can be started using the following command. Note that the server does not include any graphics; it's meant to run headless.

gzserver <world_filename>

The <world_filename> can be:

  1. relative to the current directory,

  2. an absolute path, or

  3. relative to a path component in GAZEBO_RESOURCE_PATH.

Worlds that are shipped with Gazebo are located in <install_path>/share/gazebo-<version_number>/worlds.

For example, to use the empty.world which is shipped with Gazebo, use the following command

gzserver worlds/empty.world

Graphical Client

The graphical client connects to a running gzserver and visualizes the elements. This is also a tool which allows you to modify the running simulation.

The graphical client is run using:

gzclient

Server + Graphical Client in one

The gazebo command combines server and client in one executable. Instead of running gzserver worlds/empty.world and then gzclient, you can do this:

gazebo worlds/empty.world

Plugins

Plugins provide a simple and convenient mechanism to interface with Gazebo. Plugins can either be loaded on the command line, or specified in a world/model file (see the SDF format). Plugins specified on the command line are loaded first, then plugins specified in the world/model files are loaded. Most plugins are loaded by the server; however, plugins can also be loaded by the graphical client to facilitate custom GUI generation.

Example of loading a plugin on the command line:

gzserver -s <plugin_filename> <world_file>

The same mechanism is used by the graphical client:

gzclient -g <plugin_filename>

For more information refer to the plugins overview page.


Introduction

Gazebo uses a distributed architecturewith separate libraries for physics simulation,rendering, user interface, communication, and sensor generation.Additionally, gazebo provides two executable programs for running simulations:

  • a server gzserver for simulating the physics, rendering, and sensors

  • a client gzclient that provides a graphical interface tovisualize and interact with the simulation

The client and server communicate using the gazebo communication library.

Communication Between Processes

The communication library currently uses the open sourceGoogle Protobuf for the message serializationand boost::ASIO for the transport mechanism.It supports the publish/subscribe communication paradigm.For example, a simulated world publishes body pose updates,and sensor generation and GUI will consume these messages to produce output.

This mechanism allows for introspection of a running simulation,and provides a convenient mechanism to control aspectsof Gazebo.

System

Gazebo Master

This is essentially a topic name server.It provides namelookup, and topic management.A single master can handle multiple physics simulations,sensor generators, and GUIs.

Communication Library

  • Dependencies: Protobuf and boost::ASIO
  • External API:
  • Internal API: None
  • Advertised Topics: None
  • Subscribed Topics: None

This library is used by almost all subsequent libraries.It acts as the communication and transport mechanism for Gazebo.It currently supports only publish/subscribe,but it is possible to useRPCwith minimal effort.

Physics Library

  • Dependencies: Dynamics engine (with internal collision detection)
  • External API: Provides a simple and generic interface to physics simulation
  • Internal API: Defines a fundamental interface to the physics library for 3rd party dynamic engines.

The physics library provides a simple and generic interface tofundamental simulation components, including rigid bodies,collision shapes, and joints for representing articulationconstraints.This interface has been integrated with four open-sourcephysics engines:

A model described in theSimulation Description Format (SDF)using XML can be loaded by each of these physics engines.This provides access to different algorithm implementationsand simulation features.

Rendering Library

  • Dependencies: OGRE
  • External API: Allows for loading, initialization, and scene creation
  • Internal API: Store metadata for visualization, call the OGRE API for rendering.

The rendering library uses OGRE to provide a simple interfacefor rendering 3D scenes to both the GUI and sensor libraries.It includes lighting, textures, and sky simulation.It is possible to write plugins for the rendering engine.

Sensor Generation

  • Dependencies: Rendering Library, Physics Library
  • External API: Provide functionality to initialize and run a set of sensors
  • Internal API: TBD

The sensor generation library implements all the various types of sensors,listens to world state updates from a physics simulator andproduces output specified by the instantiated sensors.

GUI

  • Dependencies: Rendering Library, Qt
  • External API: None
  • Internal API: None

The GUI library uses Qt to create graphical widgets for users to interact with the simulation.The user may control the flow of time by pausing or changing time step sizevia GUI widgets.The user may also modify the scene by adding, modifying, or removing models.Additionally there are some tools for visualizing andlogging simulated sensor data.

Plugins

The physics, sensor, and rendering libraries support plugins.These plugins provide users with access to the respective librarieswithout using the communication system.


Capture screenshots

To capture a screenshot of the scene displayed in the Gazebo 3D render window, find and click on the camera icon on the toolbar above the render window.

Screenshot save location

The captured image will be saved to ~/.gazebo/pictures with a timestamped filename.







<think>我们被要求比较PyBullet和Gazebo机器人仿真中的性能差异。根据引用[1][2][3]提供的信息,我们可以从多个维度进行分析。以下是详细的比较: 1. **物理引擎精度**: - **PyBullet**:基于Bullet物理引擎,专注于实时计算,适合快速原型设计和强化学习训练。其物理精度适中,但在高速碰撞或复杂接触场景下可能出现穿透现象[^1][^3]。 - **Gazebo**:默认使用ODE(Open Dynamics Engine),但支持切换至更高精度的物理引擎(如Simbody)。在复杂接触力学(如多足机器人足地交互)中表现更稳定,适合高保真仿真[^3]。 2. **计算效率**: - **PyBullet**:采用轻量级架构,支持CPU并行计算。在单机多核环境下可高效运行多个仿真实例(如批量RL训练),典型步频可达1000Hz以上[^1][^2]。 - **Gazebo**:架构较重,实时因子(Real-time Factor)通常低于1(即仿真慢于实时),尤其在开启高精度传感器模型时性能下降显著。 3. **传感器仿真**: - **PyBullet**:提供基础传感器(RGB-D相机、LiDAR、IMU),但噪声模型较简单。可通过插件扩展,但开发复杂。 - **Gazebo**:内置丰富的传感器模型(如热成像、GPS、力传感器),且支持自定义噪声参数,更适合多传感器融合验证[^4]。 4. **开发便利性**: - **PyBullet**:Python API简洁,与深度学习框架(PyTorch/TensorFlow)集成度高。例如,一行代码即可创建仿真环境: ```python import pybullet as p p.connect(p.GUI) # 或p.DIRECT用于无界面模式 ``` - **Gazebo**:依赖ROS通信,需编写XML描述文件(SDF/URDF)。典型工作流包含: 1. 设计机器人模型(SDF) 2. 编写ROS节点控制插件 3. 通过`gazebo_ros`包发布/订阅话题 5. **典型应用场景**: | **需求** | **PyBullet推荐** | **Gazebo推荐** | |-------------------|------------------|----------------| | 强化学习训练 | ✓ 高效并行 | ✗ | | 硬件在环测试 | ✗ | ✓ 支持实时接口 | | 多传感器仿真 | △ 有限 | ✓ 完善 | | 人形机器人平衡 | ✓ 快速迭代 | ✓ 高精度 | > **关键结论**:PyBullet适合算法快速验证(如RL策略训练),而Gazebo更适用于需要高物理精度和复杂传感器模拟的系统级验证[^4]。 §§相关问题§§ 1. 如何选择机器人仿真工具:PyBullet还是Gazebo? 2. PyBullet中如何实现多机器人并行仿真? 3. Gazebo的SDF模型与URDF有何区别? 4. 四足机器人的足地接触模型在PyBullet中如何配置? 5. 如何将PyBullet训练的强化学习策略迁移到Gazebo环境? </think> ### PyBullet与Gazebo机器人仿真中的性能差异分析 #### 1. **物理引擎精度** - **PyBullet**: 基于Bullet物理引擎,采用**离散碰撞检测**和**脉冲-based求解器**。优势在于计算效率高(典型步频$f_s \geq 1000\text{Hz}$),但复杂接触场景(如多足机器人足地交互)可能出现轻微穿透现象。 数学表达: $$ \Delta p = J M^{-1} J^T \lambda $$ 其中$\Delta p$为位置修正量,$J$为雅可比矩阵,$\lambda$为接触力。 - **Gazebo**: 默认使用**ODE引擎**(可选Simbody/DART),采用**连续碰撞检测**和**LCP求解器**。在摩擦模型和软接触场景中精度更高,但计算开销更大(实时因子$RTF < 1$时仿真慢于实时)[^4]。 #### 2. **计算效率对比** | 指标 | PyBullet | Gazebo | |---------------|------------------------------|------------------------------| | **单线程速度** | $\sim 10\times$ 实时速度 | $\sim 0.5\times$ 实时速度 | | **并行扩展** | 支持多实例并行(CPU-based) | 依赖ROS节点分布式计算 | | **GPU加速** | 部分支持(OpenCL/CUDA) | 有限支持(仅渲染环节) | | **内存占用** | $\sim 150\text{MB}$(基础) | $\sim 1\text{GB}$(带GUI) | > 实验数据:在四足机器人仿真中,PyBullet可在i7-11800H上同时运行20个实例,而Gazebo仅支持2-3个[^2]。 #### 3. **传感器仿真能力** - **PyBullet**: 提供基础传感器模型(IMU/RGB-D相机),噪声模型较简单: ```python # IMU噪声示例 accel_data = p.getBaseAcceleration(robot_id) accel_data += np.random.normal(0, 0.05, 3) # 添加高斯噪声 ``` - **Gazebo**: 支持高保真传感器(激光雷达/力传感器/热成像),可配置复杂噪声特性: ```xml <gazebo reference="camera_link"> <sensor type="camera" name="hd_cam"> <noise> <type>gaussian</type> <mean>0.0</mean> <stddev>0.007</stddev> </noise> </sensor> </gazebo> ``` #### 4. **典型应用场景推荐** - **选择PyBullet当**: - 需要快速RL策略训练(批量仿真) - 对实时性要求高($RTF > 5$) - 硬件资源有限(如笔记本开发) - **选择Gazebo当**: - 需验证多传感器融合算法 - 要求物理精度$ \epsilon < 10^{-3} $ - 与真实硬件进行HIL测试[^4] > **关键差异总结**:PyBullet是“算法沙盒”,Gazebo是“系统验证台”。实际开发中常组合使用:PyBullet训练→Gazebo验证[^2]。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangrelay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值