运行系统:Ubuntu18.04
运行环境:python2.7.17
ROS初学者—记录
问题描述:初学ROS,用自己的激光雷达点云bag文件跑无人驾驶汽车系统入门(二十四)——激光雷达的地面-非地面分割和pcl_ros实践中的代码时发现RVIZ中有节点的选项,但节点输出的内容好像啥都没有??记录一下自己的解决方法!!
问题分析:ROS中节点的数据输入接口在哪个文件中写入了?
观察全部代码,好像都没有给出原始数据接口,仔细观察ros的回调函数:
PclTestCore::PclTestCore(ros::NodeHandle &nh){
sub_point_cloud_ = nh.subscribe("/velodyne_points",10, &PclTestCore::point_cb, this);
pub_filtered_points_ = nh.advertise<sensor_msgs::PointCloud2>("/filtered_points", 10);
ros::spin();
}
ROS中Publisher的主要作用是针对指定话题发布特定数据类型的消息,上述/filtered_points即为发布过滤后的点云数据类型,在可视化工具RVIZ中可以收到。
而Subscriber的主要作用为订阅Publisher发布的节点信息,在bag文件中自带topic,用rosbag info xxxx.bag即可查看,用 Publisher订阅bag文件中的话题数据即可作为节点输入,再调用回调函数处理该数据。
ryy@ryy-VivoBook-S14-X411UF:~/desktop/pcl_ws$ rosbag info data.bag path: data.bag version: 2.0 duration: 7.8s start: Sep 26 2011 13:02:44.33 (1317013364.33) end: Sep 26 2011 13:02:52.16 (1317013372.16) size: 417.3 MB messages: 1078 compression: none [308/308 chunks] types: geometry_msgs/TwistStamped [98d34b0043a2093cf9d9345ab6eef12e] sensor_msgs/CameraInfo [c9a58c1b0b154e0e6da7578cb991d214] sensor_msgs/Image [060021388200f6f0f447d0fcd9c64743] sensor_msgs/Imu [6a62c6daae103f4ff57a132d6f95cec2] sensor_msgs/NavSatFix [2d3a8cd499b9b4a0249fb98fd05cfa48] sensor_msgs/PointCloud2 [1158d486dd51d683ce2f1be655c3c181] tf2_msgs/TFMessage [94810edda583a504dfda3829e70d7eec] topics: /kitti/camera_color_left/camera_info 77 msgs : sensor_msgs/CameraInfo /kitti/camera_color_left/image_raw 77 msgs : sensor_msgs/Image /kitti/camera_color_right/camera_info 77 msgs : sensor_msgs/CameraInfo /kitti/camera_color_right/image_raw 77 msgs : sensor_msgs/Image /kitti/camera_gray_left/camera_info 77 msgs : sensor_msgs/CameraInfo /kitti/camera_gray_left/image_raw 77 msgs : sensor_msgs/Image /kitti/camera_gray_right/camera_info 77 msgs : sensor_msgs/CameraInfo /kitti/camera_gray_right/image_raw 77 msgs : sensor_msgs/Image /kitti/oxts/gps/fix 77 msgs : sensor_msgs/NavSatFix /kitti/oxts/gps/vel 77 msgs : geometry_msgs/TwistStamped /kitti/oxts/imu 77 msgs : sensor_msgs/Imu /kitti/velo/pointcloud 77 msgs : sensor_msgs/PointCloud2 /tf 77 msgs : tf2_msgs/TFMessage /tf_static 77 msgs : tf2_msgs/TFMessage
问题解决:上述pointcloud数据即为待处理的数据,这时只需将sub_point_cloud_ 中的"/velodyne_points"改为"/kitti/velo/pointcloud "重新编译即可得到节点输出的结果。
PclTestCore::PclTestCore(ros::NodeHandle &nh){
sub_point_cloud_ = nh.subscribe("/kitti/velo/pointcloud ",10, &PclTestCore::point_cb, this);
pub_filtered_points_ = nh.advertise<sensor_msgs::PointCloud2>("/filtered_points", 10);
ros::spin();
}
###############希望能够对遇到同样问题的小伙伴有所帮助!!######################