px4新建机型文件:新建机型配置文件

px4使用机型配置文件描述特定形式的无人机。配置文件储存在 ROMFS/px4fmu_common/init.d 文件夹中,配置文件需要调用混频文件用于描述系统的物理配置,混频文件储存在ROMFS/px4fmu_common/mixers 文件夹中.

增加一个新机型配置方法:在 init.d/airframes 文件夹中新建一个配置文件并使用一个未被占用的id来命名,并将新机型配置文件名添加到CMakeLists.txt 的相关部分,然后构建并上传。

不想创建新配置的可以使用或修改已有的配置文件并将其放置于sd卡中。

注意

为了决定哪些参数要在配置文件中进行配置,可以先设置一个通用的机型然后调试仪器,之后用 param show-for-airframe 来列出改变的参数

配置文件总览

px4的结构由以下几个主要代码块组成:

  • 机型文档(用于机型描述文档和地面站)
  • 特定机型的参数,包括增益参数
  • 需要气动的控制器和其他应用,eg: 多旋翼/固定翼控制器,着陆检测器等等
  • 系统的物理配置文件,也称为mixer

这些模块多数是独立的,也意味着许多配置文件共享同样的机型布局,同样应用,只是调试增益不同

注意

新机型只有在重新构建的时候才会被编译 (run make clean)

配置文件

一个标准的配置文件如下:

第一段是机型文档,用于生成机型参考文档和地面站机型选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
#
# @name Wing Wing (aka Z-84) Flying Wing
#
# @url https://docs.px4.io/master/en/frames_plane/wing_wing_z84.html
#
# @type Flying Wing
# @class Plane
#
# @output MAIN1 left aileron
# @output MAIN2 right aileron
# @output MAIN4 throttle
#
# @output AUX1 feed-through of RC AUX1 channel
# @output AUX2 feed-through of RC AUX2 channel
# @output AUX3 feed-through of RC AUX3 channel
#
# @maintainer Lorenz Meier <lorenz@px4.io>
#
# @board px4_fmu-v2 exclude
# @board bitcraze_crazyflie exclude
#

下一段列出了机型的特定参数,包括增益:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
. ${R}etc/init.d/rc.fw_defaults

param set-default BAT_N_CELLS 2
param set-default FW_AIRSPD_MAX 15
param set-default FW_AIRSPD_MIN 10
param set-default FW_AIRSPD_TRIM 13
param set-default FW_R_TC 0.3
param set-default FW_P_TC 0.3
param set-default FW_L1_DAMPING 0.74
param set-default FW_L1_PERIOD 16
param set-default FW_LND_ANG 15
param set-default FW_LND_FLALT 5
param set-default FW_LND_HHDIST 15
param set-default FW_LND_HVIRT 13
param set-default FW_LND_TLALT 5
param set-default FW_THR_LND_MAX 0
param set-default FW_PR_FF 0.35
param set-default FW_RR_FF 0.6
param set-default FW_RR_P 0.04

param set-default PWM_MAIN_DISARM 1000

设定机架类型(MAV_TYPE)

1
set MIXER wingwing

配置pwm输出端口(主要是设置电机电调的通道编号,如通道4为电机,会将输出pwm值设置为1000)

1
set PWM_OUT 4

警告

如果想反相一个通道,不要直接在遥控上面设置或者使用 RC1_REV 参数,那样只会在手动模式下实现反向,当切换到自主导航模式时通道仍然是反向的。正确的做法应该是改变 PWM_MAIN_REV1 参数或者在混频文件中改变输出scaling。

混频文件

Note

对于混频的详细介绍,可以参见混频文件的文章

典型的混频文件,文件名中指定了其信息,如 wingwing.main.mix , 包括了机架类型(wingwing), 输出通道类型(.main.aux), 以及混频文件类型(即.mixer)。

混频文件包含数个代码块,每块代码指定了一个输出,如果有两个舵机和一个电调,混频文件应该有至少三个代码块。

Note

舵机和电机的连接顺序取决于混频文件中代码块定义的顺序。

对于MAIN1 为左升降副翼,MAIN2 为右升降副翼,MAIN3为空,MAIN4 为推力电机通道

混频器从编码范围为-10000到10000,对应实际的-1到1

1
2
3
4
M: 2
O: 10000 10000 0 -10000 10000
S: 0 0 -6000 -6000 0 -10000 10000
S: 0 1 6500 6500 0 -10000 10000

从左到右参数的意义:

  • M: 表示该通道混频器接受两个输入

  • O: 表示输出尺度(负向尺度 * 1,正向尺度 * 1),偏置(这里是0),输出范围(这里是-1到1)

    • 如果想反相PWM信号,可以改为下面的写法:

      1
      O:      -10000  -10000      0 -10000  10000
    • 如果是默认形式(如下代码所示),这一行可以不写

      1
      O:      10000  10000   0 -10000  10000
  • S: 表示第一个输入, 从控制组0(飞行控制组)的第一个输入通道(滚转通道,关于控制组及其通道定义参见混频器的描述)获取输入。将输入控制*0.6并反相信号(-0.6在文件中根据尺度放缩为-6000)

  • S: 表示第二个输入,从控制组0的第二个通道(俯仰通道)获取输入,同时将俯仰输入信号乘以尺度因子0.65,无offset,全尺度输出(-1,1)

Note

简单说,混频的输出为 SERVO = ( (滚转输入 * -0.6 + 0) * 1 + (俯仰输入 * 0.65 + 0) * 1 ) * 1 + 0

在当前场景下,对这个飞翼的控制面在滚转时最大可以偏转60%,俯仰控制时最大可以偏转65%

最后附上全部的混频文件代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Delta-wing mixer for PX4FMU
===========================

Designed for Wing Wing Z-84

This file defines mixers suitable for controlling a delta wing aircraft using
PX4FMU. The configuration assumes the elevon servos are connected to PX4FMU
servo outputs 0 and 1 and the motor speed control to output 3. Output 2 is
assumed to be unused.

Inputs to the mixer come from channel group 0 (vehicle attitude), channels 0
(roll), 1 (pitch) and 3 (thrust).

See the README for more information on the scaler format.

Elevon mixers
-------------
Three scalers total (output, roll, pitch).

The scaling factor for roll inputs is adjusted to implement differential travel
for the elevons.

This first block of code is for Servo 0...

M: 2
O: 10000 10000 0 -10000 10000
S: 0 0 -6000 -6000 0 -10000 10000
S: 0 1 6500 6500 0 -10000 10000

And this is for Servo 1...

M: 2
O: 10000 10000 0 -10000 10000
S: 0 0 -6000 -6000 0 -10000 10000
S: 0 1 -6500 -6500 0 -10000 10000

Note that in principle, you could implement left/right wing asymmetric mixing, but in general the two blocks of code will be numerically equal, and just differ by the sign of the third line (S: 0 1), since to roll the plane, the two ailerons must move in OPPOSITE directions.
The signs of the second lines (S: 0 0) are indentical, since to pitch the plane, both servos need to move in the SAME direction.

Output 2
--------
This mixer is empty.

Z:

Motor speed mixer
-----------------
Two scalers total (output, thrust).

This mixer generates a full-range output (-1 to 1) from an input in the (0 - 1)
range. Inputs below zero are treated as zero.

M: 1
O: 10000 10000 0 -10000 10000
S: 0 3 0 20000 -10000 -10000 10000

增加一个新机型组

机型组用于将相似的机型组合起来,便于在地面站进行选择,每个机型组都有一个名字,一个对应的svg格式图片来展示机型的一般形状,电机数量,螺旋桨转向

用于QGC和说明文档的各机型的原始文件是通过一个脚本从机型配置描述部分转换而来的,转换的命令为 make airframe_metadata

对于一个从属于已经存在机型组的新机型,只需要在机型配置文件中提供机型描述部分即可,这部分文件应放置于 ROMFS/px4fmu_common/init.d

如果机型是定义在一个新机型组中,需要额外做的工作是:

  1. 将机型组的svg图像添加到使用指南文档中(如果没有图像可以提供会显示默认图像),指南文档地址: assets/airframes/types

  2. 将新机型组的名字和图像文件名的映射关系添加到 srcparser.py 文件的 GetImageName() 方法,参考如下代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    def GetImageName(self):
    """
    Get parameter group image base name (w/o extension)
    """
    if (self.name == "Standard Plane"):
    return "Plane"
    elif (self.name == "Flying Wing"):
    return "FlyingWing"
    ...
    ...
    return "AirframeUnknown"
  3. 更新QGC:

    • 将该机型组的svg图像添加到src/AutopilotPlugins/Common/images

    • 添加svg图像的索引到 qgcimages.qrc ,参考如下代码:

      1
      2
      3
      4
      5
      6
      7
      <qresource prefix="/qmlimages">
      ...
      <file alias="Airframe/AirframeSimulation">src/AutoPilotPlugins/Common/Images/AirframeSimulation.svg</file>
      <file alias="Airframe/AirframeUnknown">src/AutoPilotPlugins/Common/Images/AirframeUnknown.svg</file>
      <file alias="Airframe/Boat">src/AutoPilotPlugins/Common/Images/Boat.svg</file>
      <file alias="Airframe/FlyingWing">src/AutoPilotPlugins/Common/Images/FlyingWing.svg</file>
      ...

Note

一旦 srcparser.py 更新,已经存在的机型原始文件会自动包含到固件中

调参

参见以下链接

添加新机型到QGC

以下步骤会使新机型在QGC机架选择中可用:

  1. 重新编译代码(先执行 make clean, 再执行 make px4_fmu-v5_default)
  2. 启动QGC选择 Custom firmware file…

你会被要求选择.px4文件到flash(这个文件是一个压缩的JSON文件包含机架原始代码)。

  1. 定位到构建文件夹选择固件文件(PX4-Autopilot/build/px4_fmu-v5_default/px4_fmu-v5_default.px4).
  2. 点击OK开始flash固件
  3. 重启QGC

QGC中可以选择新机型

# ,

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×