ROSbag(ROSbag)

ROSbag

简介

  • rosbag是一套用于记录和回放ROS话题的工具。它旨在提高性能,并避免消息的反序列化和重新排序。rosbag package提供了命令行工具和代码API,可以用C++或者python来编写包。而且rosbag命令行工具和代码API是稳定的,始终保持向后的兼容性
  • .bag文件可以保存ros系统运行过程中产生的话题和服务数据,并可以播放出来以供其他系统使用,有种仿真器的感觉,在使用别人数据集的过程中十分有用
  • bag提供了一个途径,工作原理便是将正在运行的ROS系统中的数据记录到一个.bag文件中,然后回放这些数据,以在运行的系统中产生类似的数据流

常见命令

  • rosbag 工具可以录制一个包、从一个或多个包中重新发布消息、查看一个包的基本信息、检查一个包的消息定义,基于 Python 表达式过滤一个包的消息,压缩和解压缩一个包以及重建一个包的索引
命令 作用
cheak 确定一个包是否可以在当前系统中运行,或者是否可以迁移
decompress 解压缩一个或多个包文件
compress 压缩一个或多个包文件
fix 在包文件中修复消息,以便在当前系统中回放
help 获取相关命令指示帮助信息
info 显示一个或多个包文件的内容
play 以一种时间同步的方式回放一个或多个包文件的内容
record 用指定话题的内容记录一个包文件
reindex 重新索引一个或多个损坏的包文件
cheak
decompress
compress
fix
help
info
play
record
reindex

录制数据(创建bag文件)

  • 录制所有发布的话题
rosbag record -a
# -a表明所有发布的话题都应该积累在一个bag文件中
  • 录制指定话题,设置bag包名
rosbag record -O bag_name.bag /topic1_name /topic2_name
# -O参数告诉rosbag record将数据记录到名为bag_name.bag的文件中
  • 不设置包名(默认是以年份、日期和时间开头且扩展名是.bag的文件)
rosbag record /topic1_name /topic2_name

回放bag文件

  • 直接回放,基于全局时间间隔回放
rosbag play record.bag
  • 以暂停的方式启动,防止跑掉数据,按空格继续
rosbag play --pause record.bag
  • 以特定频率回放
rosbag play -r 0.5 record.bag
# 以0.5倍速回放

修复损坏的bag文件

  • 重新读取消息数据并重建索引
rosbag reindex *.bag
  • 强制覆盖备份文件
rosbag reindex -f *.bag

注意,每个 bag 文件(扩展名为 .orig.bag)在重新索引 bag 之前都会进行备份。 如果备份文件已存在(并且未指定 -f 选项),则该工具将不会重新索引该文件

其他

rosbag info

rosbag info

rosbag info 显示bag文件中的可读摘要,包括开始和结束时间,话题的名称及其类型,消息数量、频率以及压缩统计信息

  • 显示一个 bag 包的信息
rosbag info bag_name.bag

例如:

$ rosbag info foo.bag
path:        foo.bag
version:     2.0
duration:    1:38s (98s)
start:       Dec 10 2014 20:08:35.83 (1418270915.83)
end:         Dec 10 2014 20:10:14.38 (1418271014.38)
size:        865.0 KB
messages:    12471
compression: none [1/1 chunks]
types:       geometry_msgs/Twist [9f195f881246fdfa2798d1d3eebca84a]
             rosgraph_msgs/Log   [acffd30cd6b6de30f120938c17c593fb]
             turtlesim/Color     [353891e354491c51aabe32df673fb446]
             turtlesim/Pose      [863b248d5016ca62ea2e895ae5265cf9]
topics:      /rosout                    4 msgs    : rosgraph_msgs/Log   (2 connections)
             /turtle1/cmd_vel         169 msgs    : geometry_msgs/Twist
             /turtle1/color_sensor   6149 msgs    : turtlesim/Color
             /turtle1/pose           6149 msgs    : turtlesim/Pose
  • 查看常用命令
rosbag info -h
  • 输出YAML格式的信息
rosbag info -y bag_name.bag
  • 输出 bag 中指定域的信息,比如只显示持续时间
rosbag info -y -k duration bag_name.bag

rosbag compresss

rosbag compresss

rosbag compress 是一个用于压缩bag文件的命令行工具。在压缩bag文件之前备份每个bag文件(扩展名为 .orig.bag)。 如果备份文件已存在(并且未指定 -f 选项),则该工具将不会压缩该文件。目前支持两种格式:BZ2 和 LZ4。 默认选择 BZ2

  • 默认BZ2
rosbag compress *.bag
  • 使用LZ4
rosbag compress --lz4 *.bag

rosbag decompress

rosbag decompress

rosbag decompress 是一个用于解压缩bag文件的命令行工具。 它会自动确定bag使用的压缩格式。每个bag文件(扩展名为 .orig.bag)在被解压之前进行备份。 如果备份文件已存在(并且未指定 -f 选项),则该工具将不会解压缩该文件

  • 解压缩
rosbag decompress *.bag

拾遗

更多关于ROSbag的信息,可以看看这里

————————

ROSbag

brief introduction

  • Rosbag is a set of tools for recording and playing back ROS topics. It is designed to improve performance and avoid deserialization and reordering of messages. Rosbag package provides command-line tools and code APIs, which can be written in C + + or python. Moreover, the rosbag command-line tool and code API are stable and always maintain backward compatibility
  • The. Bag file can save the topics and service data generated during the operation of the ROS system, and can be played out for use by other systems. It has the feeling of an emulator and is very useful in the process of using other people’s data sets
  • Bag provides a way. The working principle is to record the data in the running ROS system into a. Bag file, and then play back these data to generate a similar data stream in the running system

Common commands

  • Rosbag tool can record a package, republish messages from one or more packages, view the basic information of a package, check the message definition of a package, filter the messages of a package based on Python expressions, compress and decompress a package, and rebuild the index of a package
命令 作用
cheak 确定一个包是否可以在当前系统中运行,或者是否可以迁移
decompress 解压缩一个或多个包文件
compress 压缩一个或多个包文件
fix 在包文件中修复消息,以便在当前系统中回放
help 获取相关命令指示帮助信息
info 显示一个或多个包文件的内容
play 以一种时间同步的方式回放一个或多个包文件的内容
record 用指定话题的内容记录一个包文件
reindex 重新索引一个或多个损坏的包文件
cheak
decompress
compress
fix
help
info
play
record
reindex

Record data (create bag file)

  • Record all published topics
rosbag record -a
# -a表明所有发布的话题都应该积累在一个bag文件中
  • Record the specified topic and set the bag package name
rosbag record -O bag_name.bag /topic1_name /topic2_name
# -O参数告诉rosbag record将数据记录到名为bag_name.bag的文件中
  • Do not set the package name (the default is a file that starts with year, date and time and has a. Bag extension)
rosbag record /topic1_name /topic2_name

Playback bag file

  • Direct playback, playback based on global time interval
rosbag play record.bag
  • Start in pause mode to prevent running data, and press space to continue
rosbag play --pause record.bag
  • Playback at a specific frequency
rosbag play -r 0.5 record.bag
# 以0.5倍速回放

Repair damaged bag files

  • Reread the message data and rebuild the index
rosbag reindex *.bag
  • Force overwrite of backup files
rosbag reindex -f *.bag

Note that each bag file (with the extension. Orig. Bag) is backed up before re indexing the bag. If the backup file already exists (and the – f option is not specified), the tool will not re index the file

other

rosbag info

rosbag info

Rosbag info displays the readable summary in the bag file, including the start and end times, the name and type of topic, the number and frequency of messages, and compression statistics

  • Displays information about a bag package
rosbag info bag_name.bag

For example:

$ rosbag info foo.bag
path:        foo.bag
version:     2.0
duration:    1:38s (98s)
start:       Dec 10 2014 20:08:35.83 (1418270915.83)
end:         Dec 10 2014 20:10:14.38 (1418271014.38)
size:        865.0 KB
messages:    12471
compression: none [1/1 chunks]
types:       geometry_msgs/Twist [9f195f881246fdfa2798d1d3eebca84a]
             rosgraph_msgs/Log   [acffd30cd6b6de30f120938c17c593fb]
             turtlesim/Color     [353891e354491c51aabe32df673fb446]
             turtlesim/Pose      [863b248d5016ca62ea2e895ae5265cf9]
topics:      /rosout                    4 msgs    : rosgraph_msgs/Log   (2 connections)
             /turtle1/cmd_vel         169 msgs    : geometry_msgs/Twist
             /turtle1/color_sensor   6149 msgs    : turtlesim/Color
             /turtle1/pose           6149 msgs    : turtlesim/Pose
  • View common commands
rosbag info -h
  • Output information in yaml format
rosbag info -y bag_name.bag
  • Output the information of the domain specified in the bag, for example, only the duration is displayed
rosbag info -y -k duration bag_name.bag

rosbag compresss

rosbag compresss

Rosbag compress is a command line tool for compressing bag files. Back up each bag file (extension. Orig. Bag) before compressing the bag file. If the backup file already exists (and the – f option is not specified), the tool will not compress the file. Currently, two formats are supported: bz2 and lz4. Bz2 is selected by default

  • Default bz2
rosbag compress *.bag
  • Use lz4
rosbag compress --lz4 *.bag

rosbag decompress

rosbag decompress

Rosbag decompress is a command line tool for decompressing bag files. It will automatically determine the compression format used by the bag. Each bag file (with the extension. Orig. Bag) is backed up before being unzipped. If the backup file already exists (and the – f option is not specified), the tool will not unzip the file

  • decompression
rosbag decompress *.bag

Gleaning

More information about rosbag can be found here