Gazebo附带了许多工具和实用程序。 这些教程说明了这些可用的工具,以及如何使用它们。

主要有:

1 记录和播放

2 日志过滤

3 应用力/扭矩

4 HDF5数据集

官网介绍通俗具体,非常容易,请参考附件。

附件--官方教程

Logging and playback

Overview

This tutorial explains how to use the Gazebo logging capabilities to record your simulation and then reproduce it afterwards, using either the GUI or the command line.

Gazebo log files

Gazebo log files are compressed .log files which contain an initial full description of the whole world, followed by a series of "world states".

The initial description contains complete information about everything in the world, from the scene to the entities present.

After that, every time something changes in simulation, a new world state is recorded. World states are much simpler, as they only contain information about what changed, such as:

  • Simulation statistics such as the current simulation time and the number of physics iterations.

  • Current state of each model in the scene, as well as the state of each link and joint in the model. This includes information such as instantaneous pose, velocity, acceleration and forces.

  • Current pose of each light in the world.

Tip: You can find the whole spec for the world state here.

In this tutorial we will record a few log files and then take a peek inside them at the end.

Record a log

Logging from the GUI

  1. Start your simulation. Here, as an example, we have a simple world with a double pendulum.

  2. Click on the logging icon on the top right, or hit Ctrl+D to bring up the Data Logger.

  3. You can choose the directory where your log file will be saved by clicking the Browse button. By default, log files go to the ~/.gazebo/log directory. In this example, we will save it in the ~/logs/double_pendulum/ directory.

  4. Click on the red button to start recording. You should see the number of bytes in your log file increasing on the right.

    Note: For efficiency, only models and lights which move over time are logged. If your scene is static, the number of bytes in your log file will not increase. This also means that the number of samples in your log file may be different from the number of iterations in simulation.

  5. Click on the red button again to stop logging.

  6. Expand Recordings to see the path to the state.log file which was generated. It will be inside a time-stamped directory.

Logging from the command line

From the command line, it is possible to log the whole simulation from the moment Gazebo starts running until it stops, or to trigger logging from an arbitary time.

Logging the whole simulation

As an example, you can record the random_velocity.world as follows:

gazebo -r --record_path ~/logs/random_velocity worlds/random_velocity.world

You can see a list of all of the available logging options by running gazebo --help.

  • -p [--play] arg: Play a log file.

  • -r [ --record ]: Record a log from the moment Gazebo is opened until it is closed.

  • --record_encoding arg: Compression encoding format for log data. The options are zlib (default), bz2 and txt.

The log file will only be terminated when Gazebo is closed. You can check the file was created by looking into the path given:

$ ls ~/logs/random_velocity/
state.log

Logging part of the simulation

Gazebo also provides the gz log tool, which can be used to trigger logging at any moment. While Gazebo is running, open another terminal and run the following to start recording:

gz log -d 1

And to stop:

gz log -d 0

Check out gz log --help for other options.

Play back a log file

Once you have a log file, you can replay it visually or introspect it in several ways.

Visualize in GUI

Currently, it is not possible to open a log file from the GUI, so playback must be started from the command line. Simply start Gazebo using the -p option to specify a log file, such as the one we recorded earlier:

gazebo -u -p ~/logs/double_pendulum/2016-01-25T15\:09\:49.677400/gzserver/state.log

Tip: The -u option starts the log paused.

Gazebo will open in playback mode. You can play, pause, rewind and step through the playback.

  • Use Play / Pause to stop the playback.

  • Use Rewind / Forward to skip to the beginning / end of the file.

  • Use Step back / Step forward to skip samples. The number of samples skipped each time you press a step button can be changed in the box below. Samples might be any number of iterations and seconds apart.

  • Drag the current time marker and drop it to skip through the log.

  • Input a current time on the right to skip to that sample.

Command line tools

As mentioned above, the gz log tool provides several options for introspecting your log file. Check out this tutorial for log filtering, for example.

Here, let's quickly go over how you would take a look at the recorded states.

We'll use -s to step through a recorded file, like this:

gz log -s -f ~/logs/double_pendulum/2016-01-25T15\:09\:49.677400/gzserver/state.log

You'll see the full initial SDF representation of the world, something like this:

<?xml version='1.0'?>
<gazebo_log>
<header>
<log_version>1.0</log_version>
<gazebo_version>7.0.0~pre1</gazebo_version>
<rand_seed>10622214</rand_seed>
<log_start>43 380000000</log_start>
<log_end>69 651000000</log_end>
</header><chunk encoding='txt'><![CDATA[
<sdf version ='1.6'>
<world name='default'>(...)<light name='sun' type='directional'>(...)</light><model name='ground_plane'>(...)</model><model name='double_pendulum_with_base'>(...)</model>
</world>
</sdf>]]></chunk>--- Press space to continue, 'q' to quit ---

As you press space, you will step through the subsequent states. You'll note that the states are more compact and only contain information about what has changed in the world. Here's an example of a state:

<chunk encoding='txt'><![CDATA[
<sdf version='1.6'>
<state world_name='default'>
<sim_time>43 380000000</sim_time>
<real_time>43 478499228</real_time>
<wall_time>1453763389 677873530</wall_time>
<iterations>43380</iterations>
<model name='double_pendulum_with_base'><pose>1.140 -1.074 -0.000 0.000 -0.000 0.000 </pose><scale>1.000 1.000 1.000</scale><link name='base'><pose>1.13998 -1.07367 -0.00000 0.00000 0.00000 -0.00042 </pose><velocity>-0.0000 0.0000 -0.0005 0.0004 0.0030 0.0001 </velocity></link><link name='lower_link'><pose>1.38969 -1.79815 1.41059 -2.45351 0.00000 -0.00042 </pose><velocity>0.0042 -0.2557 0.2659 1.9694 0.0048 0.0001 </velocity></link><link name='upper_link'><pose>1.13999 -1.07367 2.10000 2.33144 -0.00000 -0.00042 </pose><velocity>0.0063 -0.0008 -0.0005 -0.3739 0.0032 0.0001 </velocity></link></model><model name='ground_plane'><pose>0.000 0.000 0.000 0.000 -0.000 0.000 </pose><scale>1.000 1.000 1.000</scale><link name='link'><pose>0.00000 0.00000 0.00000 0.00000 -0.00000 0.00000 </pose><velocity>0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 </velocity></link></model></state></sdf>
]]></chunk>--- Press space to continue, 'q' to quit ---

Note that there's no information for the sun or the ground_plane, since they are not moving.

Log filtering

Introduction

State logs are recordings of world state information from Gazebo. State includes pose, velocity, acceleration, and forces applied to all links of all models. Gazebo will only record state information for models that change over time. A state log file contains a header, the initial world description, and a time series of state.

Gazebo Log Command line tool

Gazebo ships with a logging utility that is accessed via the gz log command.

View the help information using:

gz help log

or

gz log -h

Example Usage

Tip: Check out the tutorial on logging and playback for an overview of ways to record a log.

Step 1: Create a state log file

Start by removing old log files

rm -rf ~/.gazebo/log/*

We will use the PR2 world to create a state log file.

Start by running the Gazebo server with the -r command line option

gzserver -r worlds/pr2.world

After a few seconds, stop the server using ctrl-c.

A new time stamped directory should exist in ~/.gazebo/log with one subdirectory and a state.log file. Here is an example

~/.gazebo/log/2013-07-25T07\:29\:05.122275/gzserver/state.log

You can verify this log file by replaying it in Gazebo.

gazebo -p ~/.gazebo/log/*/gzserver/state.log

Step 2: Filter a state log file

The gz log command line tool provides mechanisms for stepping through a log file and echoing the contents of a log file to screen. The echo to screen feature can be combined with a filter to produce a log file that contains specific information such as just the pose of models and links.

Try echoing the recorded state log file to screen.

gz log -e -f ~/.gazebo/log/*/gzserver/state.log

You should see a lot of information scroll by.

Now let's remove all velocity, acceleration, and force information from the log file. This will leave just pose information.

gz log -e -f ~/.gazebo/log/*/gzserver/state.log --filter *.pose/*.pose

The --filter option is a flexible command line argument to extract information from a log file.

It is also possible to filter based on simulation time using a Hz filter. For example, we can output state information at 30 Hz using:

gz log -e -f ~/.gazebo/log/*/gzserver/state.log -z 30

These filters can be combined and piped to a file for playback. This may take some time depending on the size of the state.log.

gz log -e -f ~/.gazebo/log/*/gzserver/state.log -z 30 --filter *.pose/*.pose > /tmp/filtered_state.log

This log file can then be replayed in Gazebo

gazebo -p /tmp/filtered_state.log

Applying Force/Torque

Introduction

This tutorial will explain how to apply force and/or torque to models during simulation using the graphical user interface.

Applying force and torque examples

Let's go through an example of applying force and torque to simple models. Open Gazebo and from the insert tab, insert a Simple Arm into the scene. Then, from the top toolbar, insert a box. Make sure the simulation is not paused.

Apply force to a link

We want to apply force to a specific link in the Simple Arm model. On the World tree, right-click arm_wrist_lift and choose Apply Force/Torque. A dialog will pop up and you'll see a straight arrow and a curved arrow attach to the arm.

On the dialog, write 100 N on the Y field under Force and press Enter, the arm will start rotating slightly. The force was applied in the link's Y direction for a single time-step, which is in the order of milliseconds, thus the need for such a large force.

Apply torque to a link

On Apply to link, select arm_elbow_pan, the arrows will move to this link. Under torque, write 100 Nm on the Z field and press Apply Torque a few times to see the arm rotate slightly.

Apply force with an offset

Now let's apply force to the box. Right-click the box in the scene and choose Apply Force/Torque. A new dialog will pop up.

Under Force, type 1000 N on the X field. Then under Application point, press the up arrow in the Y field until it reaches 1 m, you'll see the arrow moving as you do it. Press Enter a few times to and the box will rotate. Hold Enter to repeatedly apply the force and make the box spin faster.

The interface explained

Note: If you apply force and/or torque while the simulation is paused, they will accumulate and be applied all at once when the simulation is unpaused.

Force

  • X, Y, Z: Each field specifies how much force will be applied on that direction. The frame is fixed to the link.

  • Mag: The total magnitude of the force which will be applied, which is the Euclidean norm of the 3 forces above. Changing the magnitude changes the XYZ fields proportionally, maintaining the force direction.

  • Clear: Pressing this button will zero the XYZ and Mag fields.

  • Application point: By default, force is applied to the link's center of mass. Here you can edit the XY and Z fields to give the force an offset with respect to the link's origin expressed in the link's frame. Select Center of mass again to fill the XYZ fields with its coordinates.

    Tip: Right-click the model and choose View -> Center of mass to see its position. You might want to also make the model transparent for that.

  • Apply Force: Click this to apply only force for one time step. Keep in mind that time steps are in the order of milliseconds, so relatively large forces are needed in order to apply a significant impulse.

Torque

  • X, Y, Z: Each field specifies how much torque will be applied about that axis. The frame is fixed to the link.

  • Mag: The total magnitude of the torque which will be applied, which is the Euclidean norm of the 3 torques above. Changing the magnitude changes the XYZ fields proportionally, maintaining the torque direction.

  • Clear: Pressing this button will zero the XYZ and Mag fields.

  • Apply Torque: Click this to apply only torque for one time step. Keep in mind that time steps are in the order of milliseconds, so relatively large torques are needed in order to apply a significant angular impulse.

    Note: Torque is always applied about the center of mass.

Apply All

Force and torque are applied at the same time, i.e. apply a wrench. Hold enter or click it repeatedly to apply multiple times.

Rotation tool

The arrows directions will always match the directions specified in the dialog. From the dialog, the direction can be changed by editing the numbers on the XYZ fields. From the scene, the direction can be changed by dragging the pink circles around the arrows.

Tip: The pink circles are attached to the highlighted arrow. To rotate the other arrow, first click it to attach the circles to it and then drag them normally.

Instrument HDF5 Datasets

Introduction

Instrument tools are provided to dump physical data into HDF5 format. The datasets, together with the Benchmark Problems for Multibody Dynamis (BPMD) framework are used to compare different methods in solving multibody systems with bilateral joints and unilateral frictional contacts in an unbiased way. These datasets will help researchers to concentrate on analysis of existing methods and construction of more accurate solvers, without worrying about implementation of the whole physics engine.

Example Usage

Install hdf5

sudo apt-get install libhdf5-dev

Build Gazebo

This HDF5 instrument tool requires building Gazebo from source, with the cmake parameter HDF5_INSTRUMENT [default False] as True. Learn how to build Gazebo from source

cd ~/gazebo
mkdir build
cd build
cmake -DHDF5_INSTRUMENT=True ../
make -j4
sudo make install

Collect Datasets

Use only gzserver

./test/integration/INTEGRATION_physics_inertia_ratio

Use the world file

gazebo ~/gazebo/worlds/friction_demo.world

Then a file named ode_frames.hdf5 will be generated at the directory exactly where the above command is run.

View the HDF5 file

hdfvivew is used to open the hdf5 files. You can install it via the terminal:

sudo apt-get install hdfview

Then open the stored file with:

hdfview ode_frames.hdf5

A hierarchical file shows up:

Note: The instrument tool will save hierarchical data for each time step, so it will be slow to write the data into the ode_frames.hdf5 file. Be patient, especially for complex simulation scenarios such as Atlas robots or many body simulation.

Gazebo機器人仿真學習探索筆記(六)工具和实用程序相关推荐

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

    在完成Gazebo7安裝後,需要熟悉Gazebo,方便之後使用. 部分源代碼可以參考:https://bitbucket.org/osrf/gazebo/src/ 如果還沒有安裝請參考之前內容完成安裝 ...

  2. Gazebo機器人仿真學習探索筆記(三)機器人模型

    gazebo_models:https://bitbucket.org/osrf/gazebo_models 模型庫下載,可以參考如下命令: ~/Rob_Soft/Gazebo7$ hg clone ...

  3. Gazebo機器人仿真學習探索筆記(一)安裝與使用

    Gazebo提供了多平臺的安裝和使用支持,大部分主流的linux,Mac以及Windows,這裏結合ROS以Ubuntu爲例進行介紹. 首先是參考資料:http://gazebosim.org/tut ...

  4. Gazebo機器人仿真學習探索筆記(五)環境模型

    環境模型構建可以通過向其中添加模型實現,待之後補充,比較有趣的是建築物模型, 可以編輯多層樓層和房間,加入樓梯,窗戶和牆壁等,具體可以參考附錄,等有空再補充. 起伏地形環境構建可以參考之前內容:在Ga ...

  5. Gazebo機器人仿真學習探索筆記(七)连接ROS

    中文稍后补充,先上官方原版教程.ROS Kinetic 搭配 Gazebo 7 附件----官方教程 Tutorial: ROS integration overview As of Gazebo 1 ...

  6. C# 一些學習小筆記及技巧

    學習及工作中積累了一些零零碎碎的小筆記及技巧(C#),重溫和匯總一下. 1. 類別轉換時,如果你未能確定數值有效,使用TryParse 比 Parse 要更安全, TryParse 不會引發異常. 2 ...

  7. 人工智能 java 坦克机器人系列: 强化学习_人工智能 Java 坦克機器人系列: 強化學習...

    級別:中級 2006 年 7 月13日 本文中,我們將使用強化學習來實現一個機器人.使用強化學習能創建一個自適應的戰斗機器人.這個機器人能在戰斗中根據環境取得最好的策略,並盡力使戰斗行為最佳.並在此過 ...

  8. 機器人學總結(4) —— 逆運動學

    0.前言 逆運動學,是通過操作空間(笛卡爾空間)的位姿,求解關機空間的關節參數的過程.把它放在雅克比後面,是因為有些逆運動學算法需要用到雅克比矩陣.處理逆運動學的方法很多,我們這裡介紹一些常用的方法. ...

  9. 機器人學總結(1) —— 機器人的描述

    0 前言 接觸機器人已經有一定的時間了(其實也不是很長),一直想把這方面的知識和經驗總結一下.主要是想為自己做個整理,如果那裡有錯誤或者有問題的地方,還請大家指正.'指點和交流. 這裡所說的機器人主要 ...

最新文章

  1. 这样出ORACLE的面试题
  2. javascript跳跃式前进(3) - 跳入JSON
  3. 机智云官网用到的库-grid.css我解析
  4. activemq broker集群_17 个方面,综合对比 Kafka、RabbitMQ、RocketMQ、ActiveMQ
  5. nginx 同一个端口支持 http https_Nginx
  6. sqoop/1.4.6/下载
  7. P5666-[CSP-S2019]树的重心【树状数组】
  8. oracle获取一段时间内所有的小时、天、月
  9. JavaScript从入门到放弃-JavaScript历史介绍
  10. 站点信息 统计 内容 概况
  11. 如何关闭子线程?征集析构函数与多线程的讨论!
  12. JavaScript案例一:Window弹窗案例
  13. 面向对象(Python):学习笔记之封装
  14. 关于Volatile
  15. 噪声、白噪声、高斯噪声、高斯白噪声以及加性和乘性噪声
  16. Unity Blend命令
  17. vue 配置 微信SDK wifi功能
  18. 数据库内外连接、自连接
  19. camel标记法是什么方法
  20. MYSQL配置环境变量

热门文章

  1. vxi11协议服务器的实现,基于DSP和VXI-11协议的LXI仪器控制与实现.pdf
  2. vue监听手机返回按键
  3. python 循环播放音乐_基于python实现音乐播放器代码实例
  4. 打印冻结窗格怎么保证每页都有_《excel如何打印标题行》 EXCEL 如何让冻结的窗口 在打印的每页上面显示...
  5. 如何在matlab中建立pid神经网络,神经网络PID控制及其Matlab仿真
  6. 仿驾校一点通android
  7. 谷歌分析中的转化目标设置后,大概多久能显示在Google adwords后台?
  8. win下一些常用的工具软件及网管管理系统
  9. WPF4.0用tablet实现手写输入(更新XP SP3下也能手写输入方法)
  10. cmd批量修改文件名 增加文字_CMD批量修改文件名的批处理方法