当前位置:网站首页>[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 ./xxxandcd 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 .

边栏推荐
- Gbase 8C system table PG_ collation
- Redis: simple use of redis
- The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
- Su Shimin: 25 principles of work and life
- 詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
- 微服务组件Sentinel (Hystrix)详细分析
- Hard core observation 547 large neural network may be beginning to become aware?
- es6 filter() 数组过滤方法总结
- 8 free, HD, copyright free video material download websites are recommended
- RestCloud ETL 跨库数据聚合运算
猜你喜欢

easyPOI

返回一个树形结构数据
![[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)](/img/e7/915404743d6639ac359bb4e7f7fbb7.jpg)
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)

Visual yolov5 format data set (labelme JSON file)

Trial setup and use of idea GoLand development tool

SPI机制

详细些介绍如何通过MQTT协议和华为云物联网进行通信

线程安全的单例模式

Solution for processing overtime orders (Overtime unpaid)

y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
随机推荐
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
GBase 8c系统表-pg_auth_members
Awk from getting started to being buried (2) understand the built-in variables and the use of variables in awk
Su Shimin: 25 principles of work and life
深度学习笔记(持续更新中。。。)
Basic operation of view
Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
5. File operation
Summary of ES6 filter() array filtering methods
Gbase 8C system table PG_ collation
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
[codeforces] cf1338a - Powered addition [binary]
8 free, HD, copyright free video material download websites are recommended
Use go language to realize try{}catch{}finally
GBase 8c触发器(三)
Storage basic operation
Unrecognized SSL message, plaintext connection?
awk从入门到入土(3)awk内置函数printf和print实现格式化打印
Cfdiv2 fixed point guessing- (interval answer two points)
Producer consumer model based on thread pool (including blocking queue)