PX4 PID调试指南

PX4基本配置参考: https://blog.csdn.net/qq_42703283/article/details/115214729?spm=1001.2014.3001.5501

本文仅供参考,如有困惑的参阅官方文档

Multicopter PID Tuning Guide (Manual/Advanced): https://docs.px4.io/master/en/config_mc/pid_tuning_guide_multicopter.html

提示

  • All gains should be increased very slowly as large gains may cause dangerous oscillations! Typically increase gains by 20-30% per iteration, reducing to 5-10% for final fine tuning.
  • Land before changing a parameter. Slowly increase the throttle and check for oscillations.
  • Tune the vehicle around the hovering thrust point, and use the thrust curve parameter to account for thrust non-linearities or high-thrust oscillations.
  • Optionally enable the high-rate logging profile with the SDLOG_PROFILE parameter so you can use the log to evaluate the rate and attitude tracking performance (the option can be disabled afterwards).

调PID以及拉力系数前务必关闭MC_AIRMODE,默认应该是关闭的
在这里插入图片描述

1.Rate Controller

务必把角速度环调节到位!!!

建议在特技模式(Acro mode)下进行调试,效果更明显,**若没有太多手飞经验建议还是在Manual/Stabilized模式下进行调试!!!**如果不是需要特别灵敏,Manual/Stabilized模式下调节的都应该够用了

  • 特技模式下飞行器的滚转、俯仰、偏航三个轴的角速率由摇杆偏移角度来控制。
  • 摇杆居中意味着保持当前角度的姿态。
  • 因此特技模式下等于飞控不再帮你参与控制,纯粹靠飞手控制角速率来进行自稳
  • 调试前关闭如下指令映射,设置如下
    • MC_ACRO_EXPO = 0, MC_ACRO_EXPO_Y = 0, MC_ACRO_SUPEXPO = 0, MC_ACRO_SUPEXPOY = 0
    • MC_ACRO_P_MAX = 200, MC_ACRO_R_MAX = 200
    • MC_ACRO_Y_MAX = 100

If the vehicle does not fly at all:

  • If there are strong oscillations when first trying to takeoff (to the point where it does not fly), decrease all P and D gains until it takes off.
  • If the reaction to RC movement is minimal, increase the P gains.

1.1.调试方法

1.1.1.安装flight_review

https://github.com/PX4/flight_review

sudo apt-get install sqlite3 fftw3 libfftw3-dev
# After git clone, enter the directory
git clone --recursive https://github.com/PX4/flight_review.git
cd flight_review/app
pip install -r requirements.txt
# Note: preferably use a virtualenv

打开flight_review

cd app
./serve.py --show

1.1.2.具体调试方法

请先看完这一节再开始调试!!!

1.1.2.1.总体思想
  1. 先调roll和pitch

    1. 迭代调节PD
    2. 根据需要调I,一般为0即可
  2. 调yaw

    1. 同上,不过不需要调D,并将D设置为0

Proportional Gain (P/K)
The proportional gain is used to minimize the tracking error (below we use P to refer to both P or K). It is responsible for a quick response and thus should be set as high as possible, but without introducing oscillations.

If the P gain is too high: you will see high-frequency oscillations.
If the P gain is too low:
the vehicle will react slowly to input changes.
In Acro mode the vehicle will drift, and you will constantly need to correct to keep it level.

Derivative Gain (D)
The D (derivative) gain is used for rate damping. It is required but should be set only as high as needed to avoid overshoots.

If the D gain is too high: the motors become twitchy (and maybe hot), because the D term amplifies noise.
If the D gain is too low: you see overshoots after a step-input.
Typical values are:

standard form (P = 1): between 0.01 (4" racer) and 0.04 (500 size), for any value of K
parallel form (K = 1): between 0.0004 and 0.005, depending on the value of P

Integral Gain (I)
The I (integral) gain keeps a memory of the error. The I term increases when the desired rate is not reached over some time. It is important (especially when flying Acro mode), but it should not be set too high.

If the I gain is too high: you will see slow oscillations.
If the I gain is too low: this is best tested in Acro mode, by tilting the vehicle to one side about 45 degrees, and keeping it like that. It should keep the same angle. If it drifts back, increase the I gain. A low I gain is also visible in a log, when there is an offset between the desired and the actual rate over a longer time.
Typical values are:

standard form (P = 1): between 0.5 (VTOL plane), 1 (500 size) and 8 (4" racer), for any value of K
parallel form (K = 1): between 0.3 and 0.5 if P is around 0.15 The pitch gain usually needs to be a bit higher than the roll gain.

1.1.2.2.具体操作方法

最理想的调试方法是提供一个阶跃输入,即将摇杆快速拨向一边让后让他归零(要避免归零时摇杆抖动)(特级模式下建议逐渐加大拨的幅度,并及时控制好飞机)

  • A well-tuned vehicle in Acro mode will not tilt randomly towards one side, but keeps the attitude for tens of seconds even without any corrections.

因此具体步骤如下:

  1. 打开QGC的PID Tuning

  2. 手飞飞机,稳定情况下,提供一个阶跃输入,安全第一大概飞一下就可以

  3. 降落

  4. 导出log

  5. 传入flight_review查看结果

    1. 	cd flight_review/app
      	./serve.py --pid-analysis -f ./path_to_your_log.ulg
      
    2. 查看角速率跟踪情况,根据前一节pid调节方法进行调整,一般在默认参数情况下,直接调整D即可
    3. Flight_review分析方法https://docs.px4.io/master/zh/log/flight_review.html
  6. 重复实验

Tips:

  • 建议一切系数调节都在默认参数上进行微调
  • 若起飞阶段振动很大:
    • 增大系数D
    • 检查电机是否有问题,通过QGC听每一个电机转动是否正常,合理的电机转动应该丝滑声音不大,若听见有段落的声音需要进行检查
      • 接触不良
      • 短路(即使做了绝缘也有可能因为绝缘不够影响电机)
  • 有动捕反馈的情况下可以使用Position模式进行调节,高校!
  • 飞机抖动较大时,先考虑降低D,有可能是因为噪声导致的抖动!

角速率控制器相关系数

  • Roll rate control (MC_ROLLRATE_P, MC_ROLLRATE_I, MC_ROLLRATE_D, MC_ROLLRATE_K)
  • Pitch rate control (MC_PITCHRATE_P, MC_PITCHRATE_I, MC_PITCHRATE_D, MC_PITCHRATE_K)
  • Yaw rate control (MC_YAWRATE_P, MC_YAWRATE_I, MC_YAWRATE_D, MC_YAWRATE_K)

一个好的结果应该如下所示
在这里插入图片描述
在这里插入图片描述

2.Attitude Controller

Manual/Stabilized模式下飞,理论上不需要怎么调试,调试方法如上

参数

  • Roll control (MC_ROLL_P)
  • Pitch control (MC_PITCH_P)
  • Yaw control (MC_YAW_P)

3.Thrust Curve

不建议调节,需要调节的参考如下链接:
https://docs.px4.io/master/en/config_mc/pid_tuning_guide_multicopter.html#thrust-curve

ALL DONE!
重新打开MC_AIRMODE

番外:Auto-tuning

https://docs.px4.io/master/en/config/autotune.html

自动帮你调PID!
但是要求4到20m,会通过如上的阶跃输入方法进行调整,所以只能在室外进行。
当然如果你有动捕或者可靠的位姿反馈设备,可以利用Takeoff mode 起飞,通过Position mode进行autotune

没尝试过有需要看上面的链接

  • 4
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PX4是一个开源的飞控固件,其PID控制器部分的代码如下: ```c++ void PID::update(float desired, float measured, float dt) { // 计算误差 float error = desired - measured; // 积分误差 _integrator += _ki * error * dt; // 限制积分误差 _integrator = math::constrain(_integrator, -_integrator_saturation, _integrator_saturation); // 计算微分误差 _derivative = (_kd == 0) ? 0 : (_prev_error - error) / dt; // 计算输出 _output = _kp * error + _integrator + _kd * _derivative; // 限制输出 _output = math::constrain(_output, -_output_saturation, _output_saturation); // 更新上一次误差 _prev_error = error; } ``` 该代码实现的是一个标准的PID控制器,其中包含了三个部分,分别是比例控制、积分控制和微分控制。算法流程如下: 1. 计算误差:目标值与实际值之间的差距。 2. 积分误差:将误差累加起来,用于消除稳态误差。 3. 限制积分误差:对积分误差进行限制,防止积分饱和。 4. 计算微分误差:计算误差的变化率,用于抑制超调和减小调节时间。 5. 计算输出:将比例控制、积分控制和微分控制三个部分的输出相加,得到最终的控制输出。 6. 限制输出:对输出进行限制,防止输出过大或过小。 7. 更新上一次误差:将当前误差保存下来,供下一次计算使用。 这段代码的实现比较简单,但是需要注意的是,积分误差和微分误差的计算需要进行限制,否则会出现积分饱和和微分爆炸的问题。此外,PID控制器的参数需要根据具体的控制对象进行调整,以获得更好的控制效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值