Arduino PID整定

Arduino PID整定

Tuning an Arduino PID


Introduction to Tuning an Arduino PID

例如,我们可能想把一箱水加热到华氏 100 度。 我们需要能够在不同的条件下实现这一目标,例如房间的环境(周围)温度。 此外,我们可能会不时将冷水放入水箱,或将热水取出。 我们需要控制器作出反应,使温度尽快恢复到设定点,并保持在设定点。 我们不希望出现波动。 一个简单的温度开关就可以做到这一点。 请记住,我们的目标是提供足够的输出,将温度保持在我们想要的位置。 在本文,我们将以加热过程为例。 这将是一个使用独立(传统)PID 公式的前向作用过程。) 我们将使用启发式方法进行调整,对于大多数使用 Arduino 的人来说,这通常是最简单的方法。

PID Terminology

At this point, let’s discuss the different terms you need to be familiar with when tuning a PID loop.现在,让我们来讨论一下在调整 PID 循环时需要熟悉的不同术语。

General Termiology

Process Varialble (Input) — This is the feedback we get from the system. This could be temperature or pressure, etc, depending on the process. The feedback can provide anywhere from 0 to 5 volts to an analog input pin. We just need to know the scaling. For example: 0v might represent a temperature of 50 degrees. Likewise, 5v might represent a temperature of 150 degrees. In this example, our input will be A0 (Analog Input 0). In the Arduino, a 0v signal will give us a 0 on the analog input channel. 5v will give us a value of 1023. In other words, with this setup, a value of 0 to 1023 represents the value of 50 to 150 degrees.

Control Variable (Output) — This is the output that the Arduino sends from a PWM pin. If you need a true analog output, you will need to set up a low pass filter with a capacitor and resistor. Basically, if you convert the pin to true analog output, then the Arduino will send a value of 0 to the output to get 0v through the low pass filter. A value of 255 would give you 5v out of the low pass filter.

过程变量(输入)–这是我们从系统中获得的反馈。这可能是温度或压力等,具体取决于过程。反馈可为模拟输入引脚提供 0 至 5 伏的电压。我们只需要知道比例。例如:0 伏可能代表 50 度的温度。同样,5 伏可能代表 150 度的温度。在这个例子中,我们的输入将是 A0(模拟输入 0)。在 Arduino 中,0V 信号将在模拟输入通道上显示 0。5v 信号将产生 1023 的值。换句话说,在这种设置下,0 至 1023 的值代表 50 至 150 度。 控制变量(输出) - 这是 Arduino 从 PWM 引脚发送的输出。如果需要真正的模拟输出,则需要用电容器和电阻器设置一个低通滤波器。基本上,如果您将引脚转换为真正的模拟输出,那么 Arduino 将向输出发送一个 0 值,以便通过低通滤波器获得 0 伏电压。如果数值为 255,则低通滤波器的输出电压为 5V。

SetPoint — This is the value we desire the process variable (input) to be.

Error — This is the difference between the SetPoint and the Process Variable (Input). In other words, this is the difference between where we are, and where we want to be.设定点 - 我们希望过程变量(输入)达到的值。 误差 - 设定点与过程变量(输入)之间的差值。 换句话说,这就是我们所处的位置与我们希望达到的位置之间的差值。

P, I, and D Terminology

Proportional

We base the output from proportional solely on the amount of error (and our gain). The higher our gain is, the more output we will have for a given error. If we are at the set point, then there is no error. Therefore, there is no output. In a non-integrating process, this means that your process variable will drop. The process variable will continue to drop until there is enough error to provide enough output to make up for your losses.我们的比例输出完全基于误差量(和我们的增益)。 增益越高,给定误差下的输出就越大。 如果我们处于设定点,则没有误差。 因此,也就没有输出。 在非积分过程中,这意味着过程变量将下降。 过程变量将继续下降,直到有足够的误差来提供足够的输出以弥补损失。

Integral

We calculate integral based on time and error. Let’s say, we set the Ki tuning parameter to 0.1 repeats per second. For the time being, let’s also assume that we have 10% error. To understand this easier, let’s also say that the process variable is not changing. Our error remains at 10% for now regardless of the output.

Since we have 0.1 repeats per second, after 10 seconds, we will have 1 full repeat. Remember, our error remained at 10. In other words after 10 seconds, we will add 10% to the output. If we assume we started with Kp=1, then the output from proportional is 10% also. Basically, this means that after 10 seconds, our output would increase to 20%. After 20 Seconds, our output would be 30%, and so on. If our setting was .05 repeats per second, then we make the integral less aggressive. After 20 seconds, we would only have 1 full repeat, which means it takes 20 seconds to get to a total of 30% output (counting proportional).

我们根据时间和误差计算积分。 比方说,我们将 Ki 调整参数设置为每秒重复 0.1 次。 同时,假设误差为 10%。 为了更容易理解,我们也假设过程变量没有变化。 由于每秒重复 0.1 次,10 秒后我们将有 1 次完整的重复。 请记住,我们的误差仍然是 10。 换句话说,10 秒后,我们的输出将增加 10%。 如果我们假设开始时 Kp=1,那么比例输出也是 10%。 基本上,这意味着 10 秒后,我们的输出将增加到 20%。 20 秒后,我们的输出将达到 30%,以此类推。 如果我们的设置是每秒重复 0.05 次,那么积分的强度就会降低。 20 秒后,我们将只有 1 次完整的重复,这意味着需要 20 秒才能达到总输出的 30%(按比例计算)。

Derivative

Finally, we have derivative. We base derivative on the rate of change of error. However, since most input values are a bit noisy, we don’t use derivative most of the time. This would cause excessive control action. The derivative setting is how far we look into the future to expect the error to be for a given slope. You can think of derivative as opposition to a change in the process variable. Keep in mind though, this opposition is in both directions. Derivative tries to prevent the process variable from falling so much, but also resists the process variable coming back up to the set point.

最后是导数。 我们的导数基于误差变化率。 不过,由于大多数输入值都有一定的噪声,我们在大多数情况下都不使用导数。 这会导致过度的控制动作。 导数设置是指在给定斜率的情况下,我们对未来误差的预期。 您可以将导数视为过程变量变化的对立面。 但请记住,这种对立是双向的。 导数试图阻止过程变量大幅下降,但同时也阻止过程变量回升到设定点。

Begin Tuning an Arduino PID

At this point, let’s take a look at a simple sketch that I put into the Arduino. Attached to the Arduino, I have a PID simulator that I put together with another Arduino build.现在,让我们来看看我在 Arduino 中安装的一个简单草图。 我在 Arduino 上安装了一个 PID 模拟器,这是我用另一个 Arduino 制作的。

/********************************************************
 * PID Basic Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_v1.h>

#define PIN_INPUT 0
#define PIN_OUTPUT 3

long CurrentMillis = 0;
long LastMillis = 0;
//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp = 5, Ki = 0, Kd = 0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

void setup() {
  //initialize the variables we're linked to
  Input = analogRead(PIN_INPUT);
  Setpoint = 400;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  Serial.begin(9600);
}

void loop() {
  CurrentMillis = millis();
  Input = analogRead(PIN_INPUT);
  myPID.Compute();
  analogWrite(PIN_OUTPUT, Output);

  // Serial Plotter Data
  if ((CurrentMillis - LastMillis) > 500){
      Serial.print("Input:");
      Serial.print(Input);
      Serial.print(",");
      Serial.print("Output:");
      Serial.println(Output);
      Serial.print(",");
      Serial.print("MinValue:");
      Serial.print(0);
      Serial.print(",");
      Serial.print("MaxValue:");
      Serial.print(600);
      Serial.print(",");
      LastMillis = CurrentMillis;
    }
}

As you can see, Kp is 5, and I’ve set the other values at 0 for Ki and Kd temporarily.

Tuning the Arduino PID for Proportional

First, we need to find out the minimum value of Kp causes instability. The loop is unstable when it continues to oscillate. Let’s look at this on the serial plotter.首先,我们需要找出导致不稳定的 Kp 最小值。 当环路持续振荡时,它就是不稳定的。 让我们在串行绘图仪上看看这个问题。

img

As you can see, the loop is unstable, and the output is saturating at 255, which is the max value. Let’s reduce Kp to 2.正如您所看到的,环路不稳定,输出在最大值 255 时达到饱和。 让我们将 Kp 降为 2。

img
That helped, but we’re still unstable, and saturating again at times. Let’s try 1.这有所帮助,但我们仍然不稳定,有时会再次饱和。 让我们试试 1.
img

We’re fairly stable at 1, so let’s try 1.5:

img

As you can see, we went into constant oscillation. You can narrow this down further if you like, but we’ll run with this value. The definition of instability is when the process variable continues to oscillate with the same amplitude, or gets worse.

At this point, we need to write down the amount of time peak to peak, or trough to trough. It looks like this will be about 10 seconds.Additionally, since Kp is unstable at 1.5, we need to cut this in half. Our new Kp will be .75. Let’s see what our chart looks like with this new Kp.

如您所见,我们进入了持续振荡状态。 如果您愿意,还可以进一步缩小范围,但我们将使用这个值。 不稳定性的定义是过程变量以相同的振幅持续振荡,或振幅越来越大。 此时,我们需要写下峰值到峰值或谷值到谷值的时间。 此外,由于 Kp 在 1.5 时不稳定,我们需要将其减半。 新的 Kp 将是 0.75。 让我们看看使用新 Kp 后的图表效果。

img

Tuning an Arduino PID for Integral

Now that we found the value for Kp, the Integral is easy. For Ki, we’ll just take Kp divided by the natural period. This will be 0.75 / 10 seconds. Let’s try a Ki with 0.075, and let’s see if we get up to the setpoint.

Remember, our Set Point was 400.现在我们找到了 Kp 的值,积分就很容易了。 对于 Ki,我们只需用 Kp 除以自然周期。 这将是 0.75 / 10 秒。 记住,我们的设定点是 400。

img

Looks like we landed it!

Tuning an Arduino PID for Derivative

Now that we are confident, let’s see what will happen if we add derivative. To calculate derivative, we’ll take Kp * (1/8th of the natural period). In this case, that will be 0.75 * 1.25. Therefore, let’s try a Kd of 0.938.现在我们有信心了,让我们看看如果加上导数会发生什么。 计算导数时,我们取 Kp *(自然周期的 1/8)。 在这种情况下,就是 0.75 * 1.25。 因此,让我们试试 0.938 的 Kd 值。
img

As you can see, we did achieve the set point, and it appears to be stable. However, we do see a lot more control action, although small. If this was a valve, you would be performing more maintenance on the valve due to the constant control action. One solution is to dampen the PV by using an average. However, by doing this, you also simulate more process lag, and cannot tune your loop quite as tight.如您所见,我们确实达到了设定点,而且似乎很稳定。 不过,我们确实看到了更多的控制动作,尽管很小。 如果这是一个阀门,由于持续的控制动作,您需要对阀门进行更多的维护。 一种解决方案是使用平均值来抑制 PV。 不过,这样做也会模拟出更多的过程滞后,无法将环路调整得非常紧凑。

Summary

In short, increase Kp until your loop becomes unstable. At that point, record the natural period. Cut Kp in half, then use Kp / natural period for your Ki variable. If you use derivative, it will be Kp * (1/8th of the natural period). Please provide your feedback and corrections below. I’m sure there are some details of this post that need refined! There are other tuning methods out there using different procedures. You can just do a google search to find them, and choose whichever method works best for you!

For more information, visit the intermediate Arduino Page!

简而言之,增大 Kp 直到回路变得不稳定。此时,记录自然周期。将 Kp 减半,然后使用 Kp / 自然周期作为 Ki 变量。如果使用导数,则为 Kp *(自然周期的 1/8)。请在下面提供反馈和更正。我相信这篇文章中还有一些细节需要改进!还有其他使用不同程序的调谐方法。您只需在谷歌上搜索即可找到,然后选择最适合您的方法!如欲了解更多信息,请访问 Arduino 中级页面! - Ricky Bryce

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/797682.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

WPF学习(6) -- WPF命令和通知

一 、WPF命令 1.ICommand代码 创建一个文件夹和文件 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input;namespace 学习.Command {public class MyCommand : ICommand{Acti…

无损音乐播放器推荐:Audirvana for Mac 中文激活版

udirvana 是一款高品质的音乐播放软件&#xff0c;专为Mac操作系统设计。它被设计来提供音频播放的最高标准&#xff0c;支持多种音频格式&#xff0c;包括高达32位/192kHz的高分辨率音频。Audirvana Plus 是其高级版本&#xff0c;提供了更多的功能和优化&#xff0c;例如音频…

LabVIEW远程实验数据采集系统

随着科学研究的不断发展&#xff0c;实验室对远程数据采集和监控的需求越来越高。传统的数据采集方式往往需要实验人员亲临现场&#xff0c;费时费力&#xff0c;且数据实时性较差。为了解决这些问题&#xff0c;基于LabVIEW开发了一套远程实验数据采集系统&#xff0c;实现对实…

【深度学习入门篇 ⑤ 】PyTorch网络模型创建

【&#x1f34a;易编橙&#xff1a;一个帮助编程小伙伴少走弯路的终身成长社群&#x1f34a;】 大家好&#xff0c;我是小森( &#xfe61;ˆoˆ&#xfe61; ) &#xff01; 易编橙终身成长社群创始团队嘉宾&#xff0c;橙似锦计划领衔成员、阿里云专家博主、腾讯云内容共创官…

0/1背包

0/1背包 背包问题是DP最经典的类型之一&#xff0c;而0/1背包是最经典最基础的背包问题。 一个背包体积为 v v v&#xff0c;现有 n n n种物品&#xff0c;第 i i i个物品对应体积为 c i c_i ci​&#xff0c;价值为 w i w_i wi​&#xff0c;每件物品最多可放1次&#xff0c;…

初识影刀:EXCEL根据部门筛选低值易耗品

第一次知道这个办公自动化的软件还是在招聘网站上&#xff0c;了解之后发现对于办公中重复性的工作还是挺有帮助的&#xff0c;特别是那些操作非EXCEL的重复性工作&#xff0c;当然用在EXCEL上更加方便&#xff0c;有些操作比写VBA便捷。 下面就是一个了解基本操作后&#xff…

如何追踪ping连接中的所有路由器的数量和IP

如何快速判断ping连接经过的路由器个数和IP&#xff1f; 方法一&#xff1a; ping命令会返回一个TTL&#xff0c;TTL&#xff08;Time To Live&#xff09;存活时间&#xff0c;一般初始值为64&#xff0c;每经过一个路由器就减一&#xff0c;当TTL为0时丢弃网络包&#xff0…

【深度学习】PyTorch深度学习笔记01-Overview

参考学习&#xff1a;B站视频【《PyTorch深度学习实践》完结合集】-刘二大人 ------------------------------------------------------------------------------------------------------- 1. 基于规则的深度学习 2. 经典的机器学习——手动提取一些简单的特征 3. 表示学习…

Linux问题解决

1、打开VMware Workstation&#xff0c;开启需要安装VMware Tools的虚拟机&#xff0c;在顶部选择菜单栏的虚拟机选项卡&#xff0c;点击“安装VMware Tools(T&#xff09;”。 或者有时在底部会弹出提示框安装tools&#xff0c;点击安装也可以。 2、进入ubuntu系统后&#xff…

《Linux系统编程篇》vim的使用 ——基础篇

引言 上节课我们讲了&#xff0c;如何将虚拟机的用户目录映射到自己windows的z盘&#xff0c;虽然这样之后我们可以用自己的编译器比如说Visual Studio Code&#xff0c;或者其他方式去操作里面的文件&#xff0c;但是这是可搭建的情况下&#xff0c;在一些特殊情况下&#xf…

【Linux】数据流重定向

数据流重定向&#xff08;redirect&#xff09;由字面上的意思来看&#xff0c;好像就是将【数据给它定向到其他地方去】的样子&#xff1f; 没错&#xff0c;数据流重定向就是将某个命令执行后应该要出现在屏幕上的数据&#xff0c;给它传输到其他的地方&#xff0c;例如文件或…

4G LTE 教程 物理通道结构

https://www.artizanetworks.com/resources/tutorials/phy_cha.html 下行物理信道&#xff1a; 物理下行链路共享信道 (PDSCH) 承载 DL-SCH 和 PCH。DL-SCH 包含实际用户数据。物理下行链路控制信道 (PDCCH) 通知UEPCH和DL-SCH的资源分配情况&#xff0c;以及DL-SCH相关的HARQ…

tongweb8 使用命令行对应用进行操作(by lqw)

文章目录 声明思路和概念新增应用更新应用启动应用停止应用删除应用 声明 本帖只是做一些简单的应用查看&#xff0c;新增&#xff0c;启动&#xff0c;停止&#xff0c;删除操作&#xff0c;仅供参考&#xff0c;详细内容建议参考TongwebV8.0 命令行工具参考&#xff0c;生产…

InjectFix 热更新解决方案

简介 今天来谈一谈&#xff0c;项目种的客户端热更新解决方案。InjectFix是腾讯xlua团队出品的一种用于Unity中C#代码热更新热修复的解决方案。支持Unity全系列&#xff0c;全平台。与xlua的思路类似&#xff0c;InjectFix解决的痛点主要在于Unity中C#代码写的逻辑在发包之后无…

Python爬虫:基础爬虫架构及爬取证券之星全站行情数据!

爬虫成长之路&#xff08;一&#xff09;里我们介绍了如何爬取证券之星网站上所有A股数据&#xff0c;主要涉及网页获取和页面解析的知识。爬虫成长之路&#xff08;二&#xff09;里我们介绍了如何获取代理IP并验证&#xff0c;涉及了多线程编程和数据存储的知识。此次我们将在…

深度学习LSTM之预测光伏发电

代码一&#xff1a;训练LSTM模型 代码逐段分析 import numpy as np import pandas as pd import tensorflow.keras as tk from tensorflow.keras import layers首先&#xff0c;导入了必要的库&#xff1a;numpy用于数值计算&#xff0c;pandas用于数据处理&#xff0c;tenso…

k8s record 20240710 监控

不是adaptor 是opetator 案例 监控有了&#xff0c;日志搜集呢&#xff1f; 一、kubelet 的小弟 kubelet — 负责维护容器的生命周期&#xff0c;节点和集群其他部分通信 cAdvisor 集成在 Kubernetes 的 kubelet 中&#xff0c;能够自动发现和监控集群中所有的容器。dockers…

尚硅谷Vue3入门到实战,最新版vue3+TypeScript前端开发教程

Vue3 编码规范 创建vue3工程 基于vite创建 快速上手 | Vue.js (vuejs.org) npm create vuelatest 在nodejs环境下运行进行创建 按提示进行创建 用vscode打开项目 安装依赖 源文件有src 内有main.ts App.vue 简单分析 编写src vue2语法在三中适用 vue2中的date metho…

java《ArrayList篇》--ArrayList全套知识点总结及其配套习题逐语句分析(附带全套源代码)

一、前言 来不及悼念字符串了&#xff0c;接下来登场的是集合&#xff0c;集合和数组的用法差不多&#xff0c;不同之处就在于存储的内容&#xff0c;数组是固定的长度的&#xff0c;集合的长度不固定。学习的过程中可以参照数组 今天已经是学习java的第八天了&#xff0c;接下…

vue3 vite+gojs 2.3.14 去除水印

引用vue2的做法&#xff1a;http://t.csdnimg.cn/Yrz8n 自定义vite插件&#xff0c;插件中apply 分两种模式&#xff0c;如果打包请选择build&#xff0c;记得强制刷新浏览器清缓存采能看到最新的gojs界面 export default function createGojsWaterMaker() {return {name:rem…