当前位置:网站首页>[advanced ROS] Lesson 6 recording and playback in ROS (rosbag)
[advanced ROS] Lesson 6 recording and playback in ROS (rosbag)
2022-07-03 02:18:00 【Life is like Zhaoxu】
【ROS Advanced 】 About 6 ROS Recording and playback in (rosbag)
List of articles
Preface
In advanced ROS tutorial , We plan to introduce and use some functional components , In the previous blog, we had a deep appreciation TF2 How to use the function pack , It has laid a foundation for robot learning in the future , This article is relatively easy , Emphasis on the ROS Finish in Tools for data recording and playback :rosbag.
One 、 Tool is introduced
- Concept :ROS Used in the system to realize Recording and playback ROS topic of conversation The toolset of ;
- The essence :rosbag It's essentially one ROS Subscribe or publish nodes ;
Record data : Subscribe to topic information in real time and write data to files ,
Playback data : Read the file , Publish the data information in the file .
effect : Data reuse , That is, collecting data is convenient for delaying analysis and debugging , It is useful for the analysis of sensor data in the future ;
Reference website :ROS Wiki ROSBAG
Two 、 Common command line instructions
- According to the recording and playback steps :
- Prepare the work environment :
Create a recording file directory :mkdir ./xxx
andcd xxx
- Start recording :
rosbag record -a -O Target file
- see file :
rosbag info file name
- Playback file :
rosbag play file name
3、 ... and 、 Programming to realize
This section mainly introduces the use of C++ Language programming implementation rosbag Recording and playback process :
- Admission rosbag file :
#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;
// establish bag object
rosbag::Bag bag;
// open
bag.open("/home/rosdemo/demo/test.bag",rosbag::BagMode::Write);
// 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);
// close
bag.close();
return 0;
}
- Read rosbag file :
/* Read bag file : */
#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;
// establish bag object
rosbag::Bag bag;
// open bag file
bag.open("/home/rosdemo/demo/test.bag",rosbag::BagMode::Read);
// Reading data
for (rosbag::MessageInstance const m : rosbag::View(bag))
{
std_msgs::String::ConstPtr p = m.instantiate<std_msgs::String>();
if(p != nullptr){
ROS_INFO(" Read data :%s",p->data.c_str());
}
}
// Close file stream
bag.close();
return 0;
}
summary
- Statement : The blog section of this section refers to CSDN User zhaoxuzuo ROS course , From the next blog ROS The advanced tutorial will first turn to the study of some knowledge of robots , After mastering the establishment method of basic robot model , On the one hand, bloggers will introduce some knowledge about quadruped robots , On the other hand, it will start from URDF Document and GAZEBO Start with simulation , Continue to complete for ROS Learning from , Coming soon .
边栏推荐
- [Yu Yue education] Jiujiang University material analysis and testing technology reference
- 力扣(LeetCode)183. 从不订购的客户(2022.07.02)
- How to deal with cache hot key in redis
- awk从入门到入土(1)awk初次会面
- Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
- Apple releases MacOS 11.6.4 update: mainly security fixes
- GBase 8c 函数/存储过程定义
- RestCloud ETL 跨库数据聚合运算
- 【教程】chrome关闭跨域策略cors、samesite,跨域带上cookie
- stm32F407-------IIC通讯协议
猜你喜欢
[Flutter] dart: class;abstract class;factory;类、抽象类、工厂构造函数
Return a tree structure data
[shutter] pull the navigation bar sideways (drawer component | pageview component)
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
Trial setup and use of idea GoLand development tool
返回一个树形结构数据
内存池(内核角度理解new开辟空间的过程)
使用Go语言实现try{}catch{}finally
Deep learning notes (constantly updating...)
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
随机推荐
Awk from getting started to being buried (2) understand the built-in variables and the use of variables in awk
Gbase 8C system table PG_ collation
各国Web3现状与未来
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
Qt之QComboBox添加QCheckBox(下拉列表框插入复选框,含源码+注释)
5. File operation
es6 filter() 数组过滤方法总结
Cfdiv2 fixed point guessing- (interval answer two points)
String replace space
Socket编程
File class (check)
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
单词单词单词
Depth (penetration) selector:: v-deep/deep/ and > > >
Machine learning notes (constantly updating...)
GBase 8c触发器(三)
Su Shimin: 25 principles of work and life
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
GBase 8c系统表-pg_amproc
Explore the conversion between PX pixels and Pt pounds, mm and MM