mid360+px4+gazebo+egoplanner导航仿真

一、环境准备

这里前期准备默认已经安装并配置好px4等相关无人机依赖,不会的可以参照https://blog.csdn.net/weixin_55944949/article/details/130848009?spm=1001.2014.3001.5502这位博主的教程进行配置

环境介绍:ubuntu20.04,   Px4 V1.14,   mavros,  ros1(noetic),   gazebo11

二、配置mid360

在编译好px4之后可以使用make px4_sitl_default gazebo打开仿真环境,这里默认指定的是iris模型的无人机,接下来也在iris上添加mid360

添加mid360模型

首先px4里面的无人机和传感器的模型都在:

/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models

这个路径下面,这里可以复制一个无人机的模型。下面是iris的模型结构

再修改这个iris.sdf文件,这个文件定义了四旋翼无人机的物理属性(质量、惯性矩阵)、动力系统及传感器(IMU、GPS)等,其中我们是要添加mid360所以看重传感器接口这一部分,在sdf中添加下面代码引入Mid360:

    <include>
      <uri>model://Mid360</uri>
      <pose>0 0 0.05 0 0 0</pose>
    </include>

    <joint name="lidar_joint" type="fixed">
      <child>Mid360::livox_base</child>
      <parent>base_link</parent>
      <axis>
        <xyz>0 0 1</xyz>
        <limit>
          <upper>0</upper>
          <lower>0</lower>
        </limit>
      </axis>
    </joint>

加入复制的模型里面有雷达传感器的话记得得注释掉。

这样无人机的模型里面就有雷达参数了,但是这样会报错应为只是include了。接下来把整个的模型文件放到这里面来让include能够正确的找到模型文件。

先在models文件夹下创建Mid360文件夹,在里面定义好下面几个文件:

livox_avia.sdf:

<sdf version='1.6'>
  <model name='livox_avia'>
    <link name='livox_base'>
      <pose frame=''>0 0 0 0 -0 0</pose>
      <inertial>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <mass>0.2</mass>
        <inertia>
          <ixx>0.02</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.02</iyy>
          <iyz>0</iyz>
          <izz>0.02</izz>
        </inertia>
      </inertial>
      <collision name='livox_base_collision'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/livox_mid40.dae</uri>
          </mesh>
        </geometry>
      </collision>
      <visual name='livox_base_visual'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/livox_mid40.dae</uri>
          </mesh>
        </geometry>
      </visual>
      <gravity>1</gravity>
      <velocity_decay/>
      <sensor name='laser_livox' type='ray'>
        <visualize>1</visualize>
        <update_rate>10</update_rate>
        <plugin name='gazebo_ros_laser_controller' filename='liblivox_laser_simulation.so'>
          <ray>
            <scan>
              <horizontal>
                <samples>100</samples>
                <resolution>1</resolution>
                <min_angle>-0.614355377778</min_angle>
                <max_angle>0.614355377778</max_angle>
              </horizontal>
              <vertical>
                <samples>50</samples>
                <resolution>1</resolution>
                <min_angle>-0.673696522222</min_angle>
                <max_angle>0.673696522222</max_angle>
              </vertical>
            </scan>
            <range>
              <min>0.1</min>
              <max>200.0</max>
              <resolution>0.002</resolution>
            </range>
            <noise>
              <type>gaussian</type>
              <mean>0.0</mean>
              <stddev>0.01</stddev>
            </noise>
          </ray>
          <visualize>1</visualize>
          <samples>10000</samples>
          <downsample>1</downsample>
          <csv_file_name>package://livox_mid40/scan_mode/mid360.csv</csv_file_name>
          <ros_topic>scan</ros_topic>
        </plugin>
        <pose frame=''>0 0 0 0 -0 0</pose>
      </sensor>
    </link>
  </model>
</sdf>

livox_mid70.sdf:

<sdf version='1.6'>
  <model name='iris_livox70'>
    <link name='link'>
      <pose frame=''>0 0 0 0 -0 0</pose>
      <inertial>
        <pose frame=''>-0.066667 0 0.10095 0 -0 0</pose>
        <mass>1.2</mass>
        <inertia>
          <ixx>0.535575</ixx>
          <ixy>6.98779e-07</ixy>
          <ixz>0.02038</ixz>
          <iyy>1.06224</iyy>
          <iyz>-2.70401e-08</iyz>
          <izz>1.04667</izz>
        </inertia>
      </inertial>
      <collision name='link_fixed_joint_lump__oasis_300_collision'>
        <pose frame=''>0 0 0.1 0 -0 1.57079</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/standardrobots.STL</uri>
          </mesh>
        </geometry>
        <surface>
          <contact>
            <ode/>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <collision name='link_fixed_joint_lump__livox_base_collision_1'>
        <pose frame=''>-0.4 1e-06 0.3557 0 -0 3.14149</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/livox_mid40.dae</uri>
          </mesh>
        </geometry>
      </collision>
      <visual name='link_fixed_joint_lump__oasis_300_visual'>
        <pose frame=''>0 0 0.1 0 -0 1.57079</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/standardrobots.STL</uri>
          </mesh>
        </geometry>
        <material>
          <script>
            <name>Gazebo/White</name>
            <uri>file://media/materials/scripts/gazebo.material</uri>
          </script>
        </material>
      </visual>
      <visual name='link_fixed_joint_lump__livox_base_visual_1'>
        <pose frame=''>-0.4 1e-06 0.3557 0 -0 3.14149</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/livox_mid40.dae</uri>
          </mesh>
        </geometry>
      </visual>
      <velocity_decay/>
      <gravity>1</gravity>
      <velocity_decay/>
      <sensor name='laser_livox' type='ray'>
        <visualize>1</visualize>
        <update_rate>10</update_rate>
        <plugin name='gazebo_ros_laser_controller' filename='liblivox_laser_simulation.so'>
          <ray>
            <scan>
              <horizontal>
                <samples>100</samples>
                <resolution>1</resolution>
                <min_angle>-0.614355377778</min_angle>
                <max_angle>0.614355377778</max_angle>
              </horizontal>
              <vertical>
                <samples>50</samples>
                <resolution>1</resolution>
                <min_angle>-0.614355377778</min_angle>
                <max_angle>0.614355377778</max_angle>
              </vertical>
            </scan>
            <range>
              <min>0.1</min>
              <max>200.0</max>
              <resolution>0.002</resolution>
            </range>
            <noise>
              <type>gaussian</type>
              <mean>0.0</mean>
              <stddev>0.01</stddev>
            </noise>
          </ray>
          <visualize>1</visualize>
          <samples>10000</samples>
          <downsample>1</downsample>
          <csv_file_name>model://livox_mid40/scan_mode/mid70.csv</csv_file_name>
           <robotNamespace></robotNamespace>
        <topicName>/livox</topicName>
        <frameName>laser_3d</frameName>
        </plugin>
        <pose frame=''>-0.4 1e-06 0.3557 0 -0 3.14149</pose>
      </sensor>
    </link>
  </model>
</sdf>

Mid360.sdf:

<sdf version='1.6'>
  <model name='Mid360'>
    <link name='livox_base'>
      <pose frame=''>0 0 0 0 -0 0</pose>
      <inertial>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <mass>0.2</mass>
        <inertia>
          <ixx>0.02</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.02</iyy>
          <iyz>0</iyz>
          <izz>0.02</izz>
        </inertia>
      </inertial>
      <collision name='livox_base_collision'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/livox_mid40.dae</uri>
          </mesh>
        </geometry>
      </collision>
      <visual name='livox_base_visual'>
        <pose frame=''>0 0 0 0 -0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://livox_mid40/meshes/mid360.dae</uri>
          </mesh>
        </geometry>
      </visual>
      <gravity>1</gravity>
      <velocity_decay/>
      <sensor name='laser_livox' type='ray'>
        <visualize>1</visualize>
        <update_rate>10</update_rate>
        <always_on>1</always_on>
        <plugin name='gazebo_ros_laser_controller' filename='/home/nuc/lib_livox_sim/devel/lib/liblivox_laser_simulation.so'>
          <ray>
			  <scan>
				  <horizontal>
				    <samples>100</samples>
				    <resolution>1</resolution>
				    <min_angle>0</min_angle>
            			    <max_angle>6.28</max_angle>
				  </horizontal>
				  <vertical>
				    <samples>360</samples>
				    <resolution>1</resolution>
				    <min_angle>-0.0561995544444</min_angle>
           			    <max_angle>0.981223276667</max_angle>
				  </vertical>
			  </scan>
			  <range>
				  <min>0.1</min>
				  <max>30</max>
				  <resolution>0.02</resolution>
			  </range>
			  <noise>
				  <type>gaussian</type>
				  <mean>0.0</mean>
				  <stddev>0.0</stddev>
			  </noise>
			  </ray>
          <visualize>1</visualize>
          <samples>24000</samples>
          <downsample>1</downsample>
          <csv_file_name>/home/nuc/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/livox_mid40/scan_mode/mid360.csv</csv_file_name>
          <ros_topic>/scan</ros_topic>
        </plugin>
        <pose frame=''>-0.005 0.005 0.047 0 -0 0</pose>
      </sensor>
    </link>
  </model>
</sdf>

model.config:

<?xml version="1.0"?>

<model>
  <name>Mid360</name>
  <version>1.0</version>
  <sdf version="1.6">Mid360.sdf</sdf>
  <author>
    <name>wangbaochuan</name>
    <email>3220145682@qq.com</email>
  </author>

  <description>
		 3D lidar 32
  </description>

</model>

这里注意了因为在Mid360.sdf中引入了别的文件夹下面的东西但是很明显现在我们是没有这两个东西的。

<uri>model://livox_mid40/meshes/livox_mid40.dae</uri>
<uri>model://livox_mid40/meshes/mid360.dae</uri>

所以先记住这个位置

随后修改一下<csv_fille_name>的路径信息:

<csv_file_name>/home/nuc/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/livox_mid40/scan_mode/mid360.csv</csv_file_name>

这里如果你得注意相关路径是否正确。

最后把前面要用到的livox_mid40文件夹(这个文件夹包括mid360我已经上传到我的github上了可以去下载链接:https://github.com/October-Vision/uav_nav.git)整个放进来:

文件结构如图所示。

最后在launch文件夹下新建一个launch启动文件来启动我们改好的新模型,这里我的命名为:iris_mid360.launch ;复制mavros_posix_sitl.launch文件夹下的内容,修改模型指向位置指向我们的新模型位置,最后如下面所示:

<?xml version="1.0"?>
<launch>
    <!-- MAVROS posix SITL environment launch script -->
    <!-- launches MAVROS, PX4 SITL, Gazebo environment, and spawns vehicle -->
    <!-- vehicle pose -->
    <arg name="x" default="0"/>
    <arg name="y" default="0"/>
    <arg name="z" default="0"/>
    <arg name="R" default="0"/>
    <arg name="P" default="0"/>
    <arg name="Y" default="0"/>
    <!-- vehicle model and world -->
    <arg name="est" default="ekf2"/>
    <arg name="vehicle" default="iris"/>
    <arg name="world" default="$(find mavlink_sitl_gazebo)/worlds/empty.world"/>
    <!-- 这里指向模型 -->
    <arg name="sdf" default="$(find mavlink_sitl_gazebo)/models/iris_3d_lidar/iris.sdf"/>

    <!-- gazebo configs -->
    <arg name="gui" default="true"/>
    <arg name="debug" default="false"/>
    <arg name="verbose" default="false"/>
    <arg name="paused" default="false"/>
    <arg name="respawn_gazebo" default="false"/>
    <!-- MAVROS configs -->
    <arg name="fcu_url" default="udp://:14540@localhost:14557"/>
    <arg name="respawn_mavros" default="false"/>
    <!-- PX4 configs -->
    <arg name="interactive" default="true"/>
    <!-- PX4 SITL and Gazebo -->
    <include file="$(find px4)/launch/posix_sitl.launch">
        <arg name="x" value="$(arg x)"/>
        <arg name="y" value="$(arg y)"/>
        <arg name="z" value="$(arg z)"/>
        <arg name="R" value="$(arg R)"/>
        <arg name="P" value="$(arg P)"/>
        <arg name="Y" value="$(arg Y)"/>
        <arg name="world" value="$(arg world)"/>
        <arg name="vehicle" value="$(arg vehicle)"/>
        <arg name="sdf" value="$(arg sdf)"/>
        <arg name="gui" value="$(arg gui)"/>
        <arg name="interactive" value="$(arg interactive)"/>
        <arg name="debug" value="$(arg debug)"/>
        <arg name="verbose" value="$(arg verbose)"/>
        <arg name="paused" value="$(arg paused)"/>
        <arg name="respawn_gazebo" value="$(arg respawn_gazebo)"/>
    </include>
    <!-- MAVROS -->
    <include file="$(find mavros)/launch/px4.launch">
        <!-- GCS link is provided by SITL -->
        <arg name="gcs_url" value=""/>
        <arg name="fcu_url" value="$(arg fcu_url)"/>
        <arg name="respawn_mavros" value="$(arg respawn_mavros)"/>
    </include>
</launch>

写完之后启动launch文件:

roslaunch px4 iris_mid360.launch

可以看到如图:

正常来说是没有这个蓝色的线条的,不过如果你之前有配置过liblivox_laser_simulation和livox的驱动的话是会有这个蓝色的线条的。假如已经有蓝色的线条了就可以先到查看话题信息的部分看是否有数据,假如有数据可以跳过下面安装驱动的步骤。

Livox Mid360传感器配置

注意:记住如果雷达话题有数据了话真的可以跳过这个步骤,除非到时候fastlio建图时需要CustomMsg消息格式的时候再直接看安装livox_laser_simulation的部分就行不用删除之前的库,不过删除了也没有关系。

安装雷达驱动:

cd ~/工作空间/src/
git clone https://github.com/Livox-SDK/livox_ros_driver2.git
git clone https://github.com/Livox-SDK/Livox-SDK2.git
 
cd ./Livox-SDK2/
mkdir build
cd build
cmake .. && make -j
sudo make install
 
cd ../livox_ros_driver2
source /opt/ros/noetic/setup.sh
./build.sh ROS1

如果出现了这个报错,那就先给livox_laser_simulation删了,或者移到其他地方。

安装livox_laser_simulation雷达仿真库

cd ~/工作空间/src
git clone https://github.com/Luchuanzhao/Livox_simulation_customMsg
mv Livox_simulation_customMsg livox_laser_simulation
#修改激光雷达文件路径
cd ~/工作空间/src/livox_laser_simulation/src
code livox_points_plugin.cpp
#将第54行的内容改为自己电脑实际的csv文件路径
#例如:std::string file_name = "/home/nuc/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/livox_mid40/scan_mode/mid360.csv";
 
#将101行改为自己需要的点云格式:0->PointCloud;1/2->PointCloud2;3->CustomMsg
#如果后续要使用Faster-LIO,需使用CustomMsg
 
还需注释掉340、341行的坐标变换代码,要不然rviz中得不到图像
//tfBroadcaster->sendTransform(
//   tf::StampedTransform(tf, ros::Time::now(), raySensor->ParentName(), raySensor->Name()));
 
#编译
cd ~/catkin_ws
catkin_make

到这里编译大概率是会报错的,说livox_ros_driver找不到,这里需要开始修改文件了把livox_laser_simulation中src里面所有的livox_ros_driver全部改称livox_ros_driver2比如:

等包括cmakelist等地方。

这里安装好了之后给电脑内有多个livox_laser_simulation库的朋友讲一下,不管是不经意间安装的多个livox_laser_simulation库还是工程需要,多个库时可能会出现打不开雷达的问题,如果有请修改mid360.sdf中的41行:

<plugin name='gazebo_ros_laser_controller' filename='/home/nuc/lib_livox_sim/devel/lib/liblivox_laser_simulation.so'>

把路径改为上面这个雷达仿真库.so的位置。

测试

查看是否成功:

启动仿真环境

roslaunch px4 iris_mid360.launch

使用rostopic list看一下有没有上面定义的雷达话题。雷达话题定义在mid360.sdf中的

<csv_file_name>/home/nuc/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/livox_mid40/scan_mode/mid360.csv</csv_file_name>
<ros_topic>/scan</ros_topic>

rostopic这里,看是否话题对应的上,然后rostopic echo /scan看一下有没有数据。如果有就是安装成功了。

三、导航仿真

前面已经配置好了gazebo的仿真环境,现在可以开始导航了

我的github仓库:https://github.com/October-Vision/uav_nav.git可以直接git下来,最近会补充相关的环境配置内容详情请看readme.md

下载好了之后重点需要关注下面几个地方:

src/FAST_LIO_SLAM/FAST-LIO/config/mid360.config

这里面的

lid_topic换成自己的雷达话题,imu_topic如果有实机的mid360可以改为livox/imu如果没有就用这个就行。

启动测试:

// 先启动仿真
roslaunch px4 iris_mid360.launch

//启动建图节点
roslaunch fast_lio mapping_mid360.launch 

//启动消息转换节点
roslaunch livox2pointcloud livox2pointcloud.launch 

//启动ego_planner
roslaunch ego_planner single_run_in_exp.launch

//启动控制器这里可以用px4crtl不过我觉得不好用用的别的控制器
//px4crtl启动
roslaunch px4ctrl run_ctrl.launch

//启动rviz发送点位
roslaunch ego_planner rviz.launch

打开rviz后在上面发送目标点位即可。

后续更新中.....

MID360 是一款由 Livox 推出的高性能固态激光雷达,广泛应用于机器人无人机(如 PX4 无人机)以及自动驾驶系统中,用于环境感知、SLAM(同步定位与地图构建)、避障和导航等任务。在仿真环境中对 MID360 进行设置和测试是开发过程中的重要环节,有助于验证算法性能并优化系统配置。 ### 仿真平台选择 通常使用 **Gazebo** 或 **ROS2(Robot Operating System 2)** 配合其插件机制来模拟 MID360 的数据输出。Livox 提供了专门的 ROS2 插件支持 Gazebo 经典版本,用于仿真 Livox 系列 LiDAR 设备的数据流[^3]。该插件能够生成类似于真实设备的点云数据,便于开发者在虚拟环境中测试感知与导航算法。 ### MID360 仿真设置流程 1. 安装 ROS2 和 Gazebo:确保系统中已安装 ROS2 Foxy/Humble 及其配套工具,并安装 Gazebo Classic。 2. 获取仿真插件:从开源项目 `livox_laser_simulation_RO2` 下载适用于 ROS2 的 Gazebo 插件包。 3. 配置模型描述文件:在 URDF 或 SDF 文件中添加 MID360 的传感器模型,并指定插件参数,包括扫描频率、角度范围、分辨率等。 4. 启动仿真:使用 `roslaunch` 或 `ros2 launch` 命令启动仿真环境,观察点云数据是否正常发布到 `/livox/lidar` 等话题。 5. 验证数据质量:通过 RVIZ 或其他可视化工具查看点云数据,并结合 SLAM 或定位算法进行进一步处理。 例如,在 ROS2 中启动 MID360 仿真的基本命令如下: ```bash ros2 launch livox_laser_simulation_RO2 mid360_simulation.launch.py ``` ### 数据采集与处理 在仿真过程中,可以通过订阅 `/livox/lidar` 主题获取点云数据。以下是一个简单的 Python 示例代码,展示如何接收并打印点云信息: ```python import rclpy from rclpy.node import Node from sensor_msgs.msg import PointCloud2 class MID360Subscriber(Node): def __init__(self): super().__init__('mid360_subscriber') self.subscription = self.create_subscription( PointCloud2, '/livox/lidar', self.listener_callback, 10) self.subscription # prevent unused variable warning def listener_callback(self, msg): self.get_logger().info('Received point cloud data with %d points' % (len(msg.data))) def main(args=None): rclpy.init(args=args) mid360_subscriber = MID360Subscriber() rclpy.spin(mid360_subscriber) rclpy.shutdown() if __name__ == '__main__': main() ``` ### 应用场景 MID360仿真中的应用涵盖多个领域: - **无人机自主导航**:结合 FAST-LIO 等紧耦合惯性里程计与激光雷达融合算法实现高精度定位与建图[^1]。 - **自动驾驶感知**:用于障碍物检测、车道线识别及多模态融合感知系统开发[^2]。 - **机器人路径规划**:提供精确的环境地图信息,辅助路径规划与避障策略设计。 ### 注意事项 - 确保仿真环境中的物理引擎(如 ODE、Bullet)与真实硬件的行为一致。 - 调整点云噪声参数以更贴近真实传感器输出,提升算法鲁棒性[^4]。 - 使用 TF 树管理坐标变换,确保传感器数据在全局坐标系中正确表示。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值