rosbag录制和回放

  • 1. 录制
  • 2. 回放
  • 3. 参考

本博客参照一位大佬YongqiangGao的博客实现仿真环境中一个 7 轴机械臂画圆时的 joint_states 数据,在此记录以供自己加深印象以及回顾,主要总结了如何通过rosbag将ROS系统运行过程中的数据录制到 .bag 文件中,然后通过回放数据重现相似的运行过程。

1. 录制

分别在三个终端中执行以下命令:
启动 roscore

roscore

运行我的仿真环境

roslaunch xmate7_moveit_config_new demo_gazebo.launch

看当前系统中发布的话题

rostopic list -v

其中就有我想录制下来的 /joint_states 话题,因为只有消息被发布了才可以被录制,所以上面发布的话题部分列出的话题消息是唯一可以被录制到文件中的话题消息。

打开新窗口,先创建文件夹 bagfiles 然后进入并执行命令开始录制:

mkdir ~/bagfiles
cd bagfiles
rosbag record -a

-a 选项表示将当前发布的所有话题数据都录制保存到一个bag文件中,然而此时没有发布实质性的 joint_states 数据,还需要运行这个节点发布一些轨迹数据,让机械臂执行运动

rosrun xmate7_demo moveit_circle_demo

此时,rosbag 就已经在记录有用的数据了,待这个节点运行完毕,在运行rosbag record命令的窗口中按 Ctrl-C 退出该命令。现在查看 ~/bagfiles 文件夹下的内容,会看到一个bag文件,它包含 rosbag record 运行期间所有节点发布的话题。
现在已经录制好了我的 bag 包,接下来可以使用 rodbag info查看 bag 包相关信息

rosbag info 2021-04-12-15-04-14.bag

这些信息展示bag文件中所包含话题的名称、类型和消息数量。

hjs@hjs:~/bagfiles$ rosbag info 2021-04-12-15-04-14.bag
path:        2021-04-12-15-04-14.bag
version:     2.0
duration:    24.0s
start:       Jan 01 1970 09:34:35.98 (5675.98)
end:         Jan 01 1970 09:34:59.96 (5699.96)
size:        38.0 MB
messages:    76614
compression: none [50/50 chunks]
types:       actionlib_msgs/GoalStatusArray                   [8b2b82f13216d0a8ea88bd3af735e619]control_msgs/FollowJointTrajectoryActionFeedback [d8920dc4eae9fc107e00999cce4be641]control_msgs/FollowJointTrajectoryActionGoal     [cff5c1d533bf2f82dd0138d57f4304bb]control_msgs/FollowJointTrajectoryActionResult   [c4fb3b000dc9da4fd99699380efcc5d9]control_msgs/JointTrajectoryControllerState      [10817c60c2486ef6b33e97dcd87f4474]dynamic_reconfigure/Config                       [958f16a05573709014982821e6822580]dynamic_reconfigure/ConfigDescription            [757ce9d44ba8ddd801bb30bc456f946f]gazebo_msgs/LinkStates                           [48c080191eb15c41858319b4d8a609c2]gazebo_msgs/ModelStates                          [48c080191eb15c41858319b4d8a609c2]moveit_msgs/DisplayTrajectory                    [c3c039261ab9e8a11457dac56b6316c8]moveit_msgs/ExecuteTrajectoryActionFeedback      [12232ef97486c7962f264c105aae2958]moveit_msgs/ExecuteTrajectoryActionGoal          [36f350977c67bc94e8cd408452bad0f0]moveit_msgs/ExecuteTrajectoryActionResult        [8aaeab5c1cdb613e6a2913ebcc104c0d]moveit_msgs/MotionPlanRequest                    [c3bec13a525a6ae66e0fc57b768fdca6]moveit_msgs/MoveGroupActionFeedback              [12232ef97486c7962f264c105aae2958]moveit_msgs/MoveGroupActionGoal                  [df11ac1a643d87b6e6a6fe5af1823709]moveit_msgs/MoveGroupActionResult                [6ee8682a508d60603228accdc4a2b30b]moveit_msgs/PlanningScene                        [89aac6d20db967ba716cba5a86b1b9d5]rosgraph_msgs/Clock                              [a9c97c1d230cfc112e270351a944ee47]rosgraph_msgs/Log                                [acffd30cd6b6de30f120938c17c593fb]sensor_msgs/JointState                           [3066dcd76a6cfaef579bd0f34173e9fd]tf2_msgs/TFMessage                               [94810edda583a504dfda3829e70d7eec]visualization_msgs/InteractiveMarkerInit         [d5f2c5045a72456d228676ab91048734]visualization_msgs/InteractiveMarkerUpdate       [710d308d0a9276d65945e92dd30b3946]
topics:      /clock                                                                                             23987 msgs    : rosgraph_msgs/Clock                             /execute_trajectory/feedback                                                                           2 msgs    : moveit_msgs/ExecuteTrajectoryActionFeedback     /execute_trajectory/goal                                                                               1 msg     : moveit_msgs/ExecuteTrajectoryActionGoal         /execute_trajectory/result                                                                             1 msg     : moveit_msgs/ExecuteTrajectoryActionResult       /execute_trajectory/status                                                                           122 msgs    : actionlib_msgs/GoalStatusArray                  /gazebo/link_states                                                                                23844 msgs    : gazebo_msgs/LinkStates                          /gazebo/model_states                                                                               23760 msgs    : gazebo_msgs/ModelStates                         /gazebo/parameter_descriptions                                                                         1 msg     : dynamic_reconfigure/ConfigDescription           /gazebo/parameter_updates                                                                              1 msg     : dynamic_reconfigure/Config                      /joint_states                                                                                       1433 msgs    : sensor_msgs/JointState                           (2 connections)/move_group/display_planned_path                                                                       5 msgs    : moveit_msgs/DisplayTrajectory                   /move_group/feedback                                                                                  12 msgs    : moveit_msgs/MoveGroupActionFeedback             /move_group/goal                                                                                       3 msgs    : moveit_msgs/MoveGroupActionGoal                 /move_group/monitored_planning_scene                                                                  95 msgs    : moveit_msgs/PlanningScene                       /move_group/motion_plan_request                                                                        4 msgs    : moveit_msgs/MotionPlanRequest                   /move_group/ompl/parameter_descriptions                                                                1 msg     : dynamic_reconfigure/ConfigDescription           /move_group/ompl/parameter_updates                                                                     1 msg     : dynamic_reconfigure/Config                      /move_group/plan_execution/parameter_descriptions                                                      1 msg     : dynamic_reconfigure/ConfigDescription           /move_group/plan_execution/parameter_updates                                                           1 msg     : dynamic_reconfigure/Config                      /move_group/planning_scene_monitor/parameter_descriptions                                              1 msg     : dynamic_reconfigure/ConfigDescription           /move_group/planning_scene_monitor/parameter_updates                                                   1 msg     : dynamic_reconfigure/Config                      /move_group/result                                                                                     3 msgs    : moveit_msgs/MoveGroupActionResult               /move_group/sense_for_plan/parameter_descriptions                                                      1 msg     : dynamic_reconfigure/ConfigDescription           /move_group/sense_for_plan/parameter_updates                                                           1 msg     : dynamic_reconfigure/Config                      /move_group/status                                                                                   125 msgs    : actionlib_msgs/GoalStatusArray                  /move_group/trajectory_execution/parameter_descriptions                                                1 msg     : dynamic_reconfigure/ConfigDescription           /move_group/trajectory_execution/parameter_updates                                                     1 msg     : dynamic_reconfigure/Config                      /pickup/status                                                                                       120 msgs    : actionlib_msgs/GoalStatusArray                  /place/status                                                                                        120 msgs    : actionlib_msgs/GoalStatusArray                  /rosout                                                                                               76 msgs    : rosgraph_msgs/Log                                (8 connections)/rosout_agg                                                                                           44 msgs    : rosgraph_msgs/Log                               /rviz_hjs_21789_3243602816799377856/motionplanning_planning_scene_monitor/parameter_descriptions       1 msg     : dynamic_reconfigure/ConfigDescription           /rviz_hjs_21789_3243602816799377856/motionplanning_planning_scene_monitor/parameter_updates            1 msg     : dynamic_reconfigure/Config                      /rviz_moveit_motion_planning_display/robot_interaction_interactive_marker_topic/update                48 msgs    : visualization_msgs/InteractiveMarkerUpdate      /rviz_moveit_motion_planning_display/robot_interaction_interactive_marker_topic/update_full            1 msg     : visualization_msgs/InteractiveMarkerInit        /tf                                                                                                 1193 msgs    : tf2_msgs/TFMessage                              /tf_static                                                                                             1 msg     : tf2_msgs/TFMessage                              /xmate_arm_controller/follow_joint_trajectory/feedback                                               271 msgs    : control_msgs/FollowJointTrajectoryActionFeedback/xmate_arm_controller/follow_joint_trajectory/goal                                                     4 msgs    : control_msgs/FollowJointTrajectoryActionGoal    /xmate_arm_controller/follow_joint_trajectory/result                                                   4 msgs    : control_msgs/FollowJointTrajectoryActionResult  /xmate_arm_controller/follow_joint_trajectory/status                                                 129 msgs    : actionlib_msgs/GoalStatusArray                  /xmate_arm_controller/state                                                                         1192 msgs    : control_msgs/JointTrajectoryControllerState

另外,运行一个复杂的系统时,会有几百个话题被发布,有些话题会发布大量数据(比如包含摄像头图像流的话题)。在这种系统中,要想把所有话题都录制保存到硬盘上的单个bag文件中是不切实际的。rosbag record 命令支持只录制某些特别指定的话题到单个bag文件中,这样就允许用户只录制感兴趣的话题。

rosbag record -o subset /joint_states

上述命令中 -o 参数告诉 rosbag record 将数据记录保存到名为subset.bag的文件中,同时后面的话题参数告诉 rosbag record 只能录制 /joint_states 这个指定的话题。

2. 回放

回放bag文件可以再现系统运行过程,在终端中bag文件所在目录下运行以下命令:

rosbag play 2021-04-12-15-04-14.bag

默认模式下,rosbag play命令在公告每条消息后会等待一小段时间(0.2秒)后才真正开始发布bag文件中的内容。等待一段时间的过程可以通知消息订阅器消息已经公告了消息数据可能会马上到来。如果rosbag play在公告消息后立即发布,订阅器可能会接收不到几条最先发布的消息。等待时间可以通过-d选项来指定。

3. 参考

【参考资料】
ROS总结——录制和回放数据
ros学习(一)——rosbag使用
ROS 机器人技术 - rosbag 详细使用教程!

rosbag录制和回放相关推荐

  1. ROS入门(十五)录制与回放数据

    文章目录 录制数据(通过创建一个bag文件) 录制所有发布的话题 检查并回放bag文件 录制数据子集 rosbag record/play 命令的局限性 录制数据(通过创建一个bag文件) 本小节将教 ...

  2. 终端的录制、回放与实时共享

    为什么80%的码农都做不了架构师?>>>    在<linux shell 脚本攻略>一书中,看到可以通过 script / scriptreplay 命令进行终端的录制 ...

  3. 神策数据王磊:如何用 JS 实现页面录制与回放

    本文根据神策数据资深前端研发工程师王磊<如何用 JS 实现页面录制与回放>的直播整理而成.以下为正文: 一.业务背景 对于研发来说,总是需要处理一些线上问题.To B 和 To C 企业在 ...

  4. Android自动化测试之MonkeyRunner录制和回放脚本

    Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...

  5. linux 终端会话连接,如何在 Linux 中使用 Asciinema 进行录制和回放终端会话

    简介 Asciinema 是一个轻量并且非常高效的终端会话录制器.使用它可以录制.回放和分享 JSON 格式的终端会话记录.与一些桌面录制器,比如 Recordmydesktop.Simplescre ...

  6. .NET Core剪裁器升级瘦身引擎,并支持剪裁计划的录制和回放

    上周,我发布了对.NET Core程序进行瘦身的开源软件Zack.DotNetTrimmer,与.NET Core内置的剪裁器相比,Zack.DotNetTrimmer不仅对程序的剪裁效果更好,而且还 ...

  7. 关于脚本录制和回放终端会话(script、scriptreplay)使用

    script和scriptreplay命令在绝大多数GNU/linux都有发行版上都有. 使用这两个命令可以用于终端会话的录制和回放,制作视频供大家分享. 1.开始录制 #script -t 2> ...

  8. 脚本录制和回放终端会话(script、scriptreplay)使用

    script和scriptreplay命令在绝大多数GNU/linux都有发行版上都有. 使用这两个命令可以用于终端会话的录制和回放,制作视频供大家分享. 1.开始录制 #script -t 2> ...

  9. rosbag录制数据与解包

    文章目录 一.rosbag录制数据 二.bag数据播放 三.bag解包出图像数据(三种方式) 1.ROS Wiki提供的roslaunch文件解包 2.python解包 3.用kalibr的一个工具解 ...

最新文章

  1. arduino nano 蓝牙_探索 Golang 云原生游戏服务器开发,5 分钟上手 Nano 游戏服务器框架...
  2. iOS 设置button文字过长而显示省略号的解决办法
  3. 项目管理沙龙第七次聚会纪要
  4. flink 写入到es_《从0到1学习Flink》—— Flink 写入数据到 Kafka
  5. 计算机专业的吸引力,计算机专业文献翻译-面向对象编程具有多方面的吸引力.doc...
  6. matlab变压器损耗仿真,基于Matlab的变压器运行特性仿真专题报告.docx
  7. c语言负数左移右移_C语言 位运算符的运算规则
  8. node.js mongodb ReplSet
  9. 金融数据分析与挖掘实战练习2.5-2.9
  10. jpa oracle 传参int类型判空_企业级Java开发之图解JPA核心构件
  11. 前后落差大用什么词语_在海边拍婚纱照,需要准备什么东西呢?海景婚纱摄影这些要注意...
  12. tfs 2013 access deny
  13. 源码:Java集合源码之:哈希表(二)
  14. matlab R2021b 激活错误
  15. 常用背景色RGB配色如下:
  16. 建立数据库模型:从业务模型、概念模型到逻辑模型
  17. dragonfly数据库
  18. 容器部署在物理机还是虚拟机上?
  19. HTML canvas 输入文字,关于Canvas写字
  20. 织梦网站如何上传服务器还原,网站转移教程:织梦系统数据库备份和还原的方法步骤...

热门文章

  1. 机器学习算法---K近邻算法
  2. 如何通过cmd命令行切换所在目录
  3. 第9章:群体类和群体数据的组织
  4. 利用小程序实现AI识字,把纸质内容转换成数字内容,手写文字转换成word
  5. mysql 查看 分区_Mysql表分区状态查询
  6. 全程复制粘贴,无需露脸,新手做短视频自媒体每天200+
  7. 国内可用的API合集
  8. 电脑鼠标左右键不灵敏?看我的!
  9. 软件学院软件工程学费_为什么我不去软件工程学院
  10. linux sga_max_size 作用,SGA的管理_LinuxOracle的技术博客_51CTO博客