前言:
最近一直弄yolo算法改进,这个东西大多数都要付费,东西不是很多,下一次出教程记录我艰辛的Yolo改进之旅,越改指标越下降。
重温一下仿真吧,查了网上好多教程,发现有些真的不适用呀,还得自己去研究
mid360安装
现在还是仿真阶段,mid360找的是网上博客的资料。把需要的文件附在下方
这里安装无人机搭载mid360模型,可以参考之前的其他无人机模型,将里面的模型换成mid360
主要是这个livox的仿真目前是ROS1版本没有mid360,我按照网上博客去安装发现之后rviz显示不出来点云,同时gazebo环境也没有蓝色雷达扫描线。
这一步我一直卡着,最后u翻看原来avia雷达记录发现还是可以用ros1的livox的SDK和livox_ros_driver的,之后实物的话就可以使用ros2那个版本的,现在还是用仿真需要适配(我自己的想法)
如果使用ros2那个版本,livox_laser_simulation就需要修改
参考了这个博主
https://blog.csdn.net/qq_53015543/article/details/150934916?fromshare=blogdetail&sharetype=blogdetail&sharerId=150934916&sharerefer=PC&sharesource=m0_56093217&sharefrom=from_link这个博主里面有其他博主的一些资料,感谢
但是这个是有转换的,我发现这个里面的雷达仿真话题是/scan,这个是pointcloud,我修改了这个脚本
#! /usr/bin/python3""" 将 /scan(CustomMsg)转换为 PointCloud2 并发布"""importrospyimportstruct from sensor_msgs.msgimportPointCloud2, PointField from livox_ros_driver.msgimportCustomMsgimportnumpy as np def custommsg_to_pointcloud2(custom_msg):""" 将 CustomMsg 转换为 PointCloud2"""# 创建 PointCloud2 消息cloud_msg=PointCloud2()# 设置 headercloud_msg.header=custom_msg.header cloud_msg.header.stamp=rospy.Time.now()# 设置点云字段cloud_msg.fields=[PointField(name='x',offset=0,datatype=PointField.FLOAT32,count=1), PointField(name='y',offset=4,datatype=PointField.FLOAT32,count=1), PointField(name='z',offset=8,datatype=PointField.FLOAT32,count=1), PointField(name='intensity',offset=12,datatype=PointField.FLOAT32,count=1), PointField(name='tag',offset=16,datatype=PointField.UINT8,count=1), PointField(name='line',offset=17,datatype=PointField.UINT8,count=1)]cloud_msg.height=1cloud_msg.width=len(custom_msg.points)cloud_msg.is_bigendian=False cloud_msg.point_step=18# 4*4 + 1 + 1 = 18 字节cloud_msg.row_step=cloud_msg.point_step * cloud_msg.width cloud_msg.is_dense=True# 转换数据data=bytearray()forpointincustom_msg.points:# 打包数据:x, y, z, intensity, tag, linedata.extend(struct.pack('ffffBB', point.x, point.y, point.z, point.reflectivity /255.0,# 转换为 0-1 范围point.tag, point.line))cloud_msg.data=bytes(data)returncloud_msg def scan_handler(scan_msg):""" 处理 /scan 话题的消息""" try:# 转换为 PointCloud2pc2_msg=custommsg_to_pointcloud2(scan_msg)# 发布 PointCloud2pub_pc2.publish(pc2_msg)rospy.logdebug(f"Converted {len(scan_msg.points)} points to PointCloud2")except Exception as e: rospy.logwarn(f"Error converting message: {e}")def main(): global pub_pc2# 初始化节点rospy.init_node('scan_to_pointcloud2',anonymous=True)rospy.loginfo("Starting /scan to PointCloud2 converter")# 创建发布者 - 发布 PointCloud2pub_pc2=rospy.Publisher('/livox/pointcloud2', PointCloud2,queue_size=10)# 订阅 /scan 话题rospy.Subscriber('/scan', CustomMsg, scan_handler,queue_size=10)rospy.loginfo("Subscribed to /scan, publishing to /livox/pointcloud2")rospy.loginfo("Waiting for data...")# 保持运行rospy.spin()if__name__=='__main__':try: main()except rospy.ROSInterruptException: rospy.loginfo("Node shutdown")except Exception as e: rospy.logerr(f"Fatal error: {e}")当使用这个博主的步骤,可以参考我这个脚本,亲测这样订阅话题rviz是有点云显示的哈哈
但是这个我感觉操作步骤有点麻烦了,所以我还是ros1的流程来
#livox程序修改
找到livox_points_plugin.cpp
这里大概52行改成自己的csv路径
voidLivoxPointsPlugin::Load(gazebo::sensors::SensorPtr _parent,sdf::ElementPtr sdf){std::vector<std::vector<double>>datas;std::string file_name="/home/mmq/PX4_Firmware/Tools/sitl_gazebo/models/livox_mid40/scan_mode/mid360.csv";ROS_INFO_STREAM("load csv file name:"<<file_name);if(!CsvReader::ReadCsvFile(file_name,datas)){ROS_INFO_STREAM("cannot get csv file!"<<file_name<<"will return !");return;}101行这里我选择了2,1是pointcloud,2是pointcloud2,3是CustomMsg,这是自带的。
publishPointCloudType=2;ros::init(argc,argv,curr_scan_topic);rosNode.reset(newros::NodeHandle);switch(publishPointCloudType){caseSENSOR_MSG_POINT_CLOUD:rosPointPub=rosNode->advertise<sensor_msgs::PointCloud>(curr_scan_topic,5);break;caseSENSOR_MSG_POINT_CLOUD2_POINTXYZ:caseSENSOR_MSG_POINT_CLOUD2_LIVOXPOINTXYZRTL:rosPointPub=rosNode->advertise<sensor_msgs::PointCloud2>(curr_scan_topic,5);break;caseLIVOX_ROS_DRIVER_CUSTOM_MSG:rosPointPub=rosNode->advertise<livox_ros_driver::CustomMsg>(curr_scan_topic,5);break;default:break;}在rviz里一直不显示点云,考虑这个坐标系,选择laser_livox或者是其他,然后添加话题/scan
这里选择1,2,3,点云格式不一样
rostopicecho/scan可以发现格式的问题
接下来的操作就好处理了,主要是好久没仿真,卡在这个驱动上了
注意
还有一个问题,考虑工作空间的问题,我之前把Livox驱动和fast-lio2放在不同工作空间,运行发现没有这个驱动,这个应该可以在cmake那里修改位置,我是直接放在一起了
链接: https://pan.baidu.com/s/1y4eCHzE_0pzkzkBibqXB9A?pwd=u7fi 提取码: u7fi --来自百度网盘超级会员v6的分享