当前位置:网站首页>【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的学习,敬请期待。
边栏推荐
- Explore the conversion between PX pixels and Pt pounds, mm and MM
- Learn BeanShell before you dare to say you know JMeter
- Detailed introduction to the usage of Nacos configuration center
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
- Exception handling in kotlin process
- Iptables layer 4 forwarding
- How do browsers render pages?
- The Sandbox阐释对元宇宙平台的愿景
- Comment le chef de file gère - t - il l'équipe en cas d'épidémie? Contributions communautaires
- [Yu Yue education] reference materials of love psychology of China University of mining and technology
猜你喜欢
SPI mechanism
Processing of tree structure data
Learn BeanShell before you dare to say you know JMeter
4. 类和对象
Analysis, use and extension of open source API gateway apisex
基于线程池的生产者消费者模型(含阻塞队列)
可视化yolov5格式数据集(labelme json文件)
udp接收队列以及多次初始化的测试
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
随机推荐
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
How do browsers render pages?
CFdiv2-Fixed Point Guessing-(区间答案二分)
单词单词单词
2022 spring "golden three silver four" job hopping prerequisites: Software Test interview questions (with answers)
The technology boss is ready, and the topic of position C is up to you
Detailed introduction to the deployment and usage of the Nacos registry
Socket programming
stm32F407-------DMA
Recommendation letter of "listing situation" -- courage is the most valuable
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
转载收录6.5大侠写的部分Qt开发经验
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
Analyzing several common string library functions in C language
8 free, HD, copyright free video material download websites are recommended
[Yu Yue education] reference materials of love psychology of China University of mining and technology
Su Shimin: 25 principles of work and life
Groovy, "try with resources" construction alternative
Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
可視化yolov5格式數據集(labelme json文件)