PX4模块设计之一:SITL & HITL模拟框架

基于PX4开源软件框架简明简介的框架设计,逐步分析内部模块功能设计。

PX4整个解决方案与BetaFlight飞控代码两者解决的问题是完全不一样的。为什么这么说,因为BetaFlight只是飞控代码,主要是用在飞控端(而且更多采用的是手动和FPV功能),应用领域大体是竞赛、穿越航拍等特殊场景;而PX4从设计上是一个定位专业级自动导航的系统。

1. 模拟框架

因此,PX4的设计上有两种模拟框架(Paparazzi也有类似模拟框架),用来模拟飞控在真实环境中的行为。

  • Software In the Loop (SITL) simulation
  • Hardware In the Loop (HITL) simulation

1.1 SITL模拟框架

Software In the Loop (SITL) simulation:飞控栈代码跑在PC上,然后通过UDP端口与模拟器相连,针对模拟器模拟的物理传感参数,进行飞控行为的仿真。

SITL

1.2 HITL模拟框架

Hardware In the Loop (HITL) simulation:飞控栈代码跑在真实飞控硬件上,然后通过USB端口与模拟器相连,根据模拟器模拟硬件传感数据,进行飞控行为的仿真。

HITL

2. 模拟器类型

模拟器的种类和支持机型详见下面列表:

模拟器机型支持
GazeboQuad (Iris and Solo, Hex (Typhoon H480), Generic quad delta VTOL, Tailsitter, Plane, Rover, Submarine
FlightGearPlane, Autogyro, Rover
JSBSimPlane, Quad, Hex
jMAVSimQuad
AirSimIris (MultiRotor model and a configuration for PX4 QuadRotor in the X configuration).
Simulation-In-Hardware (SIH)Plane, Quad, Tailsitter
Ignition GazeboQuad

3. MAVLink API

通过第1章节,可以看到连接Simulator和PX4飞控栈的是mavlink API软件接口。

Flight stack & Simulator

消息方向描述
HIL_ACTUATOR_CONTROLSPX4 to SimPX4 control outputs (to motors, actuators).
HIL_SENSORSim to PX4Simulated IMU readings in SI units in NED body frame.
HIL_GPSSim to PX4The simulated GPS RAW sensor value.
HIL_OPTICAL_FLOWSim to PX4Simulated optical flow from a flow sensor (e.g. PX4FLOW or optical mouse sensor)
HIL_STATE_QUATERNIONSim to PX4Contains the actual “simulated” vehicle position, attitude, speed etc. This can be logged and compared to PX4’s estimates for analysis and debugging (for example, checking how well an estimator works for noisy (simulated) sensor inputs).
HIL_RC_INPUTS_RAWSim to PX4The RAW values of the RC channels received

A SITL build of PX4 uses simulator_mavlink.cpp to handle these messages while a hardware build in HIL mode uses mavlink_receiver.cpp. Sensor data from the simulator is written to PX4 uORB topics. All motors / actuators are blocked, but internal software is fully operational.

4. 总结

关于具体如何应用这两种模拟场景,具体的操作命令、配置方法,在参考资料里面我们会给出,有兴趣的朋友可以再深入了解。

通过前面PX4开源软件框架简明简介和关于模拟仿真框架的讨论,期望能够从高维度设计层面思考,完整解决方案设计需要考虑的方方面面。

【1】Software In the Loop (SITL) simulation
【2】Hardware In the Loop (HITL) simulation

### 如何在PX4 GAZEBO仿真中为无人机模型添加相机传感器 为了在PX4 Gazebo仿真环境中成功为无人机模型添加相机传感器,需遵循特定的配置流程。此过程涉及修改SDF文件来引入新的传感器组件。 #### 修改无人机模型的SDF文件 通常情况下,在Gazebo中定义新传感器意味着编辑描述飞行器物理特性的SDF (Simulation Description Format) 文件。对于希望加入视觉能力的情况,则是在该文件内指定<sensor>标签并设置其属性以匹配所需的摄像机参数[^1]。 ```xml <!-- 插入到model.sdf --> <plugin name="camera_plugin" filename="libgazebo_ros_camera.so"> <alwaysOn>true</alwaysOn> <updateRate>30.0</updateRate> <cameraName>front_cam</cameraName> <imageTopicName>/drone/front/image_raw</imageTopicName> <cameraInfoTopicName>/drone/front/camera_info</cameraInfoTopicName> <frameName>front_cam_link</frameName> <hackBaseline>0.07</hackBaseline> <distortionK1>0.0</distortionK1> <distortionK2>0.0</distortionK2> <distortionK3>0.0</distortionK3> <distortionT1>0.0</distortionT1> <distortionT2>0.0</distortionT2> </plugin> <link name='front_cam'> <!-- 定义link的位置和其他特性 --> </link> ``` 上述XML片段展示了如何向现有的无人机模型添加一个名为`front_cam`的新摄像设备,并指定了图像数据发布的主题路径以及关联的信息元数据发布地址。同时设置了帧名称用于ROS节点间通信时识别消息源。 #### 更新launch文件调用自定义模型 完成硬件描述之后,还需调整启动脚本以便加载含有新增加部件后的版本。这一步骤可能涉及到创建或更改`.world`世界场景文件中的引用对象,也可能是直接改动原有的`.launch`发射文件,确保能够正确实例化带有改进过的视觉系统的虚拟机体[^4]。 例如: ```xml <include file="$(find px4)/launch/multi_uav_mavros_sitl.launch"> <arg name="flock_name" value="my_drone"/> <arg name="vehicle_count" value="1"/> <arg name="sdf" value="$(find my_package)/models/my_custom_quadrotor/model.sdf"/> </include> ``` 这里假设已经有一个包含了定制化内容的SDF文档存放在个人工作空间内的某个包里;通过传递`sdf`参数给multi_uav_mavros_sitl.launch,可以让系统知道要使用哪一个具体的机型设计来进行模拟实验。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值