当前位置:网站首页>【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
2022-07-03 02:15:00 【生如昭诩】
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
前言
在进阶篇的ROS教程中,我们计划推出对于一些功能组件的介绍与使用,在之前的博客我们重新深入领略了TF2功能包的使用方法,为今后机器人的学习奠定了基础,本篇则相对轻松,重点介绍ROS中完成数据记录与回放的工具:rosbag。
一、工具介绍
- 概念:ROS系统中用于实现录制和回放ROS话题的工具集;
- 本质:rosbag其实本质上就是一个ROS订阅或发布节点;
记录数据:实时订阅话题信息并将数据写入文件,
回放数据:读取文件,发布文件中的数据信息.
作用:数据复用,即采集数据方便延后分析调试,对于未来传感器数据的分析有益;
参考网站:ROS Wiki ROSBAG
二、常用命令行指令
- 根据录制及回放步骤介绍:
- 准备工作环境:
创建录制文件目录:mkdir ./xxx
和cd xxx
- 开始录制:
rosbag record -a -O 目标文件
- 查看文件:
rosbag info 文件名
- 回放文件:
rosbag play 文件名
三、编程实现
本节内容主要介绍使用C++语言编程实现rosbag的录制与回放过程:
- 录取rosbag文件:
#include "ros/ros.h"
#include "rosbag/bag.h"
#include "std_msgs/String.h"
int main(int argc, char *argv[])
{
ros::init(argc,argv,"bag_write");
ros::NodeHandle nh;
//创建bag对象
rosbag::Bag bag;
//打开
bag.open("/home/rosdemo/demo/test.bag",rosbag::BagMode::Write);
//写
std_msgs::String msg;
msg.data = "hello world";
bag.write("/chatter",ros::Time::now(),msg);
bag.write("/chatter",ros::Time::now(),msg);
bag.write("/chatter",ros::Time::now(),msg);
bag.write("/chatter",ros::Time::now(),msg);
//关闭
bag.close();
return 0;
}
- 读取rosbag文件:
/* 读取 bag 文件: */
#include "ros/ros.h"
#include "rosbag/bag.h"
#include "rosbag/view.h"
#include "std_msgs/String.h"
#include "std_msgs/Int32.h"
int main(int argc, char *argv[])
{
setlocale(LC_ALL,"");
ros::init(argc,argv,"bag_read");
ros::NodeHandle nh;
//创建 bag 对象
rosbag::Bag bag;
//打开 bag 文件
bag.open("/home/rosdemo/demo/test.bag",rosbag::BagMode::Read);
//读数据
for (rosbag::MessageInstance const m : rosbag::View(bag))
{
std_msgs::String::ConstPtr p = m.instantiate<std_msgs::String>();
if(p != nullptr){
ROS_INFO("读取的数据:%s",p->data.c_str());
}
}
//关闭文件流
bag.close();
return 0;
}
总结
- 声明:本节博客部分参考了CSDN用户赵虚左的ROS教程,从下篇博客起ROS进阶篇的教程将会首先转入机器人的一些知识学习,在掌握基本机器人模型的建立方法后,博主一方面将会介绍一些关于四足机器人的知识,另一方面则会从URDF文件和GAZEBO仿真入手,继续完成对于ROS的学习,敬请期待。
边栏推荐
- Job object of collaboration in kotlin
- Su Shimin: 25 principles of work and life
- stm32F407-------ADC
- The technology boss is ready, and the topic of position C is up to you
- MySQL learning 03
- PyTorch 卷积网络正则化 DropBlock
- Machine learning process and method
- 缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
- [camera topic] complete analysis of camera dtsi
- Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
猜你喜欢
Visualisation de l'ensemble de données au format yolov5 (fichier labelme json)
Asian Games countdown! AI target detection helps host the Asian Games!
Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
可视化yolov5格式数据集(labelme json文件)
[camera topic] complete analysis of camera dtsi
Recommendation letter of "listing situation" -- courage is the most valuable
[camera topic] how to save OTP data in user-defined nodes
LabVIEW安装第三方VISA软件后NI VISA失效
Button button adaptive size of wechat applet
随机推荐
Asian Games countdown! AI target detection helps host the Asian Games!
MySQL学习03
基于线程池的生产者消费者模型(含阻塞队列)
CFdiv2-Fixed Point Guessing-(區間答案二分)
ByteDance data Lake integration practice based on Hudi
Current situation and future of Web3 in various countries
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
PyTorch 卷积网络正则化 DropBlock
Redis:Redis的简单使用
Reprint some Qt development experience written by great Xia 6.5
MySQL learning 03
RestCloud ETL 跨库数据聚合运算
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
机器学习笔记(持续更新中。。。)
详细些介绍如何通过MQTT协议和华为云物联网进行通信
Processing of tree structure data
Redis: simple use of redis
Exception handling in kotlin process
[camera topic] turn a drive to light up the camera
Unrecognized SSL message, plaintext connection?