news 2026/6/20 16:13:25

XTDrone mid360+gazebo仿真

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
XTDrone mid360+gazebo仿真

前言:

最近一直弄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的分享
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/19 17:56:10

算法革新驱动AI训练效率革命:从技术原理到工程实践

算法革新驱动AI训练效率革命&#xff1a;从技术原理到工程实践 【免费下载链接】modded-nanogpt GPT-2 (124M) quality in 5B tokens 项目地址: https://gitcode.com/GitHub_Trending/mo/modded-nanogpt 在人工智能飞速发展的今天&#xff0c;训练效率已成为制约AI技术规…

作者头像 李华
网站建设 2026/6/20 4:14:03

无人直播资源合集(第二辑)

无人直播助眠项目 文件大小: -内容特色: 零人值守搭建助眠直播间&#xff0c;附脚本与工具包适用人群: 想副业创收或做无人直播的运营/自媒体人核心价值: 低成本挂机变现&#xff0c;24h持续流量与礼物收益下载链接: https://pan.quark.cn/s/0f7c3b56420e 【08052】抖音无人直…

作者头像 李华
网站建设 2026/6/18 20:09:40

终极方案:Expo蓝牙开发完整指南15分钟:从概念到生产部署

终极方案&#xff1a;Expo蓝牙开发完整指南15分钟&#xff1a;从概念到生产部署 【免费下载链接】expo An open-source platform for making universal native apps with React. Expo runs on Android, iOS, and the web. 项目地址: https://gitcode.com/GitHub_Trending/ex/…

作者头像 李华
网站建设 2026/6/20 5:58:11

3.10 Elasticsearch-结果可解释性:explain=true 与 Lucene explain 日志

3.10 Elasticsearch-结果可解释性&#xff1a;explaintrue 与 Lucene explain 日志 3.10.1 为什么需要“看得见”的打分 搜索排序一旦上线&#xff0c;业务方最常见的追问是&#xff1a;“为什么 A 排在 B 前面&#xff1f;” 如果没有量化依据&#xff0c;只能靠“BM25 公式…

作者头像 李华
网站建设 2026/6/19 6:00:38

15分钟精通神经网络可视化:PlotNeuralNet终极入门指南

15分钟精通神经网络可视化&#xff1a;PlotNeuralNet终极入门指南 【免费下载链接】PlotNeuralNet Latex code for making neural networks diagrams 项目地址: https://gitcode.com/gh_mirrors/pl/PlotNeuralNet 还在为论文中的神经网络结构图而烦恼吗&#xff1f;手动…

作者头像 李华
网站建设 2026/6/15 13:56:40

深度定制Electronic WeChat:打造专属macOS微信工作环境

深度定制Electronic WeChat&#xff1a;打造专属macOS微信工作环境 【免费下载链接】electronic-wechat :speech_balloon: A better WeChat on macOS and Linux. Built with Electron by Zhongyi Tong. 项目地址: https://gitcode.com/gh_mirrors/el/electronic-wechat …

作者头像 李华