Arduino 控制理论(3)- 如何在 Arduino 中调节 PID 控制器

How to adjust a PID controller in Arduino

We continue with this mini-series of posts dedicated to control systems in Arduino. The most feared moment for many arrives, making the adjustment or tuning of the PID.

In previous posts, we have seen what a controller is, hysteresis control, and we have introduced the powerful PID controller. We emphasize that, without being the perfect controller, the PID is popular for being relatively simple and achieving good behavior in a large number of plants, without knowing their nature.

我们继续这一系列关于 Arduino 控制系统的文章。 在之前的文章中,我们已经了解了什么是控制器、滞后控制,并介绍了功能强大的 PID 控制器。 我们要强调的是,PID 虽然不是完美的控制器,但却因其相对简单、可在不了解植物性质的情况下对大量植物进行良好控制而广受欢迎。

We also said that the response of a PID depends on the parameters K, Ki, and Kd of the controller. And that these depend on the plant we are controlling, that is, there are no "magic values" that always make it work well.

Depending on the value we put on the parameters, we will obtain a good response, or a slow response, or oscillating, or even ... remember, death, destruction, dismissal.

To make it more complicated, the effect of the factors in the response is not independent. Their contribution mixes and intertwines. So we cannot adjust the parameters "one by one".

The goodness and success of our controller depends entirely on the adjustment. Therefore, it is important that we know the characteristics and effects of each factor on the system's response.

我们还说过,PID 的响应取决于控制器的参数 K、Ki 和 Kd。 而这些参数取决于我们所控制的系统,也就是说,并没有一个 "神奇的值 "能让控制器始终运行良好。 根据我们为参数设定的值,我们将获得良好的响应,或缓慢的响应,或振荡,甚至...记住,死亡、毁灭、解雇。 更为复杂的是,各因素对响应的影响并不是独立的。 它们的作用是混合和交织在一起的。 因此,我们不能 "一个一个 "地调整参数,控制器的好坏和成功与否完全取决于调整。 因此,我们必须了解每个因素的特性及其对系统响应的影响。

Summary of the effects of the PID

Summarizing what we saw in the previous post, as a cheat sheet:

总结一下我们在上一篇文章中看到的内容,作为小抄:

Proportional Component

  • Low K, slow response:K 值低,反应慢
  • High K, overshoot, oscillation, and even instability:高 K 值、过冲、振荡甚至不稳定
  • It does not eliminate the steady-state error:它不能消除稳态误差

Integral

  • Eliminates the steady-state error:消除稳态误差
  • Too much Ki, oscillation and instability:Ki 过大,振荡和不稳定:

Derivative

  • Improves the overall performance:提高整体性能:
  • Too much Kd, "weird" behavior in the output:Kd 过多,输出中出现 "奇怪 "的行为:
  • Very sensitive to noise:对噪音非常敏感:
  • Very sensitive to sudden changes in the error (disturbances or setpoint changes):对误差的突然变化非常敏感(干扰或设定点变化)

On the other hand, with an oscillating input, we will get an oscillating response. It is important to know

另一方面,如果输入振荡,我们就会得到振荡响应。 重要的是要知道

  • The effect caused by K, has the same frequency;由 K 引起的效果具有相同的频率;
  • The effect caused by Ki, has a different frequency:由 Ki 引起的效果具有不同的频率: Ki 的频率越高,效果越明显。

Adjusting the PID

There are many ways to adjust a PID, some more or less theoretical. Let's take a brief look.

调整 PID 的方法有很多,有些或多或少是理论性的。 让我们简单了解一下。

Plant characterization

It consists of determining the transfer function of the plant. Common practices are to apply a step or frequency input, and analyze the characteristics of the output.

Then we can operate mathematically to make an exact calculation of the controller for the required response

它包括确定系统的传递函数。 通常的做法是应用阶跃或频率输入,并分析输出特性。 然后,我们可以通过数学运算,对控制器进行精确计算,以获得所需的响应

Application of tuning rules

Similarly, it consists of applying a certain input to the system, and measuring the output. Then, one of the many tuning rules is applied (famous example, Ziegler-Nichols rules) to obtain the PID parameters.

同样,它包括对系统施加一定的输入,并测量输出。 然后,应用众多调整规则中的一种(例如著名的齐格勒-尼科尔斯规则)来获得 PID 参数。

Auto tuning

Similar to the previous one, but carried out automatically by the controller. PID controllers have advanced a lot and, currently, many have great auto-tuning algorithms.

Precisely, this auto-tuning capability is one of the reasons for the commercial success of PID controllers.

与前者类似,但由控制器自动执行。 PID 控制器已经取得了长足的进步,目前,许多控制器都有很好的自动调整算法。 确切地说,这种自动调整能力是 PID 控制器在商业上取得成功的原因之一。

Manual adjustment

Finally, we have the "manual" adjustment. Which, although it sounds terrible, is a very valid and very popular option. On many occasions, a human operator can achieve an adjustment as good (or even better) than a generic Auto tuning.

And that's what we're going to focus on in this post, because it is much less theoretical and more appropriate for #maker projects (robots, light control, etc) that are frequently done with Arduino.

最后是 "手动 "调整。 虽然听起来很糟糕,但这是一个非常有效和流行的选择。 在很多情况下,人工操作可以实现与普通自动调整一样好(甚至更好)的调整效果。 这就是我们在本篇文章中要重点讨论的内容,因为它的理论性更低,更适合经常使用 Arduino 完成的创客项目(机器人、灯光控制等)。

Manual PID adjustment

To adjust the PID manually, we must be able to act on the system input, on the PID parameters, and visualize the response. And here, "visualize" does not necessarily mean using an oscilloscope. In the case of a motor, for example, we can "see" the system response simply by looking at how it turns (or sounds).

If you look for tutorials on the internet, you will mainly see two "schools".

要手动调整 PID,我们必须能够对系统输入和 PID 参数进行操作,并将响应可视化。 这里的 "可视化 "并不一定是指使用示波器。 以电机为例,我们只需观察它的转动(或声音),就能 "看到 "系统的响应。 如果您在互联网上查找相关教程,主要会看到两个 "流派"。

Proportional/integral/derivative adjustment

  • Adjust K until the system overshoots or starts to oscillate

  • Adjust Ki to eliminate steady-state error

  • Increase Kd until weird things start to happen

  • 调整 K,直到系统超调或开始振荡

  • 调整 Ki,消除稳态误差

  • 增加 Kd,直到开始出现怪异现象

Proportional/derivative/integral adjustment

  • Adjust K until the system overshoots or starts to oscillate

  • Increase Kd until weird things start to happen

  • Adjust Ki to eliminate steady-state error

  • 调整 K 直到系统超调或开始振荡

  • 增加 Kd 直到怪异现象开始出现

  • 调整 Ki 以消除稳态误差

With both, you will achieve similar results, ultimately. Personally, I recommend the first one and I do not understand why they insist on explaining the second one.

The reason is that the derivative term is very sensitive to measurement noise and, therefore, it is difficult to adjust in a real case. But, you can try it for yourselves.

And to practice manual parameter adjustment, here is a PID simulator, with a generic plant that has a little bit of everything (it is a second-order with a bit of pure delay).

两种方法最终都能获得相似的结果。 我个人推荐第一种方法,我不明白他们为什么坚持解释第二种方法,原因是导数项对测量噪声非常敏感,因此在实际情况下很难调整。 为了练习手动调整参数,这里有一个 PID 模拟器,其中有一个什么都有的普通系统(这是一个带点纯延迟的二阶系统)。

Move the Kp, Ki, and Kd sliders to see the changes in the controller response.

观看模拟

You can play with the different methods to adjust the PID until you get an adequate response. (hint, around K = 2.5, Ki = 0.02, Kd = 12 looks good)

Of course, the parameters depend on the response you want. Do we accept exceeding the setpoint a bit in exchange for more speed? Do we prefer it to be slower, but with less effort in the motor? It depends on your design criteria.

And we have finished the topic of PID adjustment. In the next post, we will see how to implement a PID control in Arduino.

您可以使用不同的方法来调整 PID,直到获得适当的响应。 (提示,K = 2.5、Ki = 0.02、Kd = 12 左右看起来不错)当然,参数取决于您想要的响应。 我们是否可以接受稍稍超出设定点以换取更快的速度? 我们是否更希望速度更慢,但电机消耗更少? 这取决于您的设计标准。 PID 调节的话题到此结束。 在下一篇文章中,我们将了解如何在 Arduino 中实现 PID 控制。

相关推荐
不脱发的程序猿3 个月前
MATLAB实现PID参数自动整定
matlab·pid
教练、我想打篮球3 个月前
53 mysql pid 文件的创建
mysql·pid·start·stop
不知道是谁24 个月前
控制程序确定执行步长,也就是输出信号更新频率
算法·控制·pid·现代控制理论·自动控制原理
Mr.Cssust4 个月前
【研发日记】Matlab/Simulink技能解锁(十)——PID调参技巧
仿真·pid·嵌入式软件·matlab/simulink·嵌入式处理器·ecu控制器·基于模型开发
东方.既白4 个月前
PID控制
pid
TENET-5 个月前
串级PID控制算原理及法详解
嵌入式硬件·算法·pid
shadow3D5 个月前
嵌入式PID算法总结
嵌入式·pid·电机控制·cmsis-dsp·温度控制
幻想时刻@5 个月前
杂项——编码器控制小车走固定距离(stm32)
stm32·单片机·嵌入式硬件·pid
程序员洲洲5 个月前
【Linux】The server quit without updating PID file的几种解决方案
linux·运维·服务器·pid