0 引言
使用设备及环境:虚拟机Ubuntu20.04+gazebo11+pcl1.10
1 仿真Mid360点云
接之前的ZD550仿真Mid360平台,之前的点云格式为pointcloud,而FastLio算法所需雷达点云格式为大疆自定义点云类型-CustomMsg,需要对之前的驱动文件进行修改,即对livox_laser_simulation/src下面的livox_points_plugin.cpp进行修改。
livox_points_plugin.cpp:
int argc = 0;
char **argv = nullptr;
auto curr_scan_topic = sdf->Get<std::string>("ros_topic");
ROS_INFO_STREAM("ros topic name:" << curr_scan_topic);
ros::init(argc, argv, curr_scan_topic);
rosNode.reset(new ros::NodeHandle);
rosPointPub = rosNode->advertise<sensor_msgs::PointCloud>("/scan", 5);
raySensor = _parent;
auto sensor_pose = raySensor->Pose();
可以看到代码中:rosPointPub = rosNode->advertise<sensor_msgs::PointCloud>("/scan", 5);仅发布了sensor_msgs::PointCloud类型的点云数据。
分别查看pointcloud和customMsg类型的点云数据格式
sensor_msgs/pointcloud:
std_msgs/Header header
geometry_msgs/Point32[] points
sensor_msgs/ChannelFloat32[] channels
livox_ros_driver/CustomMsg:
std_msgs/Header header
uint32 seq
time stamp
string frame_id
uint64 timebase
uint32 point_num
uint8 lidar_id
uint8[3] rsvd
livox_ros_driver/CustomPoint[] points
uint32 offset_time
float32 x
float32 y
float32 z
uint8 reflectivity
uint8 tag
uint8 line
为了能够发布 livox_ros_driver/CustomMsg类型点云,这部分代码主要参考其他博客:点云格式转换:将 ros PointCloud2格式数据转为livox CustomMsg格式-CSDN博客
修改代码如下:
(1)首先定义话题发布方livox_pub:
livox_pub = rosNode->advertise<livox_ros_driver::CustomMsg>(curr_scan_topic, 5);