rosbag录制和回放

本文档介绍了如何使用rosbag在ROS环境中录制和回放数据,特别是关注于关节状态数据。首先通过rosbag record命令录制所有话题,然后通过rosbag play回放数据,重现机械臂的运动过程。此外,还提到了如何指定录制特定话题以及在复杂系统中处理大量数据的策略。
摘要由CSDN通过智能技术生成

rosbag录制和回放

本博客参照一位大佬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 详细使用教程!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值