用ros一个节点封装成类实现topic收发
2020.07.16~2020.07.17
1.任务
已有一个 filename.bag,其中有多个topic信息
点云 - topic名为 xxxx, 要求接收点云,发出点云的size (std_msgs/UInt32)
用一个类实现
2.环境 & 工具
ubuntu16.04
ROS kinetic
C++
git
3.准备工作
1)新建工作空间,新建包
$ source /opt/ros/kinetic/setup.bash
$ mkdir -p ~/catkin_ws/src
$ catkin_create_pkg pkg_name std_msgs rospy roscpp
2)vscode配置
#查看隐藏文件 ctrl + H
#工程文件夹路径下去生成.vscode文件夹,里面的c_cpp_properties.json
#配置完后的头文件报错点击vscode智能提示小灯泡解决
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/kinetic/include/**",
"/usr/include/**",
"/usr/local/include/**",
"/opt/ros/kinetic/include",
"${workspaceFolder}/src/serial_writer/include"
],
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
3)在filename.bag文件所在路径打开新的终端,查看点云的topic类型,然后查这个类型的成员变量有哪些,写代码会用到
$ rosbag info filename.bag
4.代码
//main.cpp
#include "points_size.h"
int main(int argc, c