单片机教程网
电脑版
提示:
原网页
已由神马搜索转码, 内容由
www.51hei.com
提供.
51单片机
24小时必答区
单片机教程
单片机DIY制作
STM32
更多导航↓
Cortex M3
模数电子
电子DIY制作
音响/功放
拆机乐园
Arduino
嵌入式OS
程序设计
论坛
嵌入式/单片机论坛
Arduino
arduino PID库文件下载
查看:
7141
|
回复:
7
arduino PID库文件下载
[复制链接]
电梯直达
楼主
ID:466008
发表于 2019-1-10 17:26
|
只看该作者
|
只看大图
arduinoPID库文件
3个文件下载(仅供参考,有错误请指出):
PID_v1.rar
(6.84 KB, 下载次数: 145)
/********************************************************
* PID RelayOutput Example
* Same as basic example, except that this time, the output
* is going to a digital pin which (we presume) is controlling
* a relay. the pid is designed to Output an analog value,
* but the relay can only be On/Off.
*
* to connect them together we use "time proportioning
* control" it's essentially a really slow version of PWM.
* first we decide on a window size (5000mS say.) we then
* set the pid to adjust its output between 0 and that window
* size. lastly, we add some logic that translates the PID
* output into "Relay On Time" with the remainder of the
* window being "Relay Off Time"
PID继电器输出范例
与基本范例相同,这一次输出是一个数字引脚控制的继电器。PID被设计成
输出一个模拟值,但是继电器只有开关状态。
为了联系上两者,我们使用时间比例控制,它本质上是一个很慢的PWM。
首先我们决定一个窗口时间(比如5000ms)。
然后设置PID适应它的输出在0到窗口时间的范围。
最后我们添加一些逻辑,把PID输出转换成“继电器接通时间”和剩余的
“继电器断开时间”
********************************************************/
#include< PID_v1.h>
#define RelayPin 8
// 定义我们将要使用的变量
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//指定链接和最初的调优参数
//Specify the links and initial tuning parameters
PID myPID(&Input,& Output,& Setpoint,2,5,1, DIRECT);
int WindowSize = 2000;
unsigned long windowStartTime;
void setup()
{
windowStartTime = millis();
//初始化变量
//initialize the variables we're linked to
Setpoint = 100;
//告诉PID在从0到窗口大小的范围内取值
//tell the PID to range between 0 and the full window size
myPID.SetOutputLimits(0, WindowSize);
//开启PID
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = analogRead(0);
myPID.Compute();
/************************************************
* turn the output pin on/off based on pid output 基于PID输出,打开或关闭端口输出
************************************************/
if(millis() - windowStartTime>WindowSize)
{ //time to shift the Relay Window 继电器窗口时间
windowStartTime += WindowSize;
}
if(Output< millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
else digitalWrite(RelayPin,LOW);
}
复制代码
评分
参与人数
1
黑币
+50
收起
理由
admin
+ 50
共享资料的黑币奖励!
查看全部评分
收藏
7
淘帖
顶
踩
回复
沙发
ID:277190
发表于 2019-1-12 12:52
|
只看该作者
没有解压密码
回复
板凳
ID:384581
发表于 2019-1-14 19:17
|
只看该作者
谢谢分享
回复
地板
ID:371304
发表于 2019-5-4 01:27
|
只看该作者
感谢分享
回复
5
#
ID:341924
发表于 2019-7-14 21:24
|
只看该作者
感谢分享
回复
6
#
ID:632293
发表于 2019-11-1 17:26
|
只看该作者
谢谢分享
回复
7
#
ID:280686
发表于 2020-2-5 22:58
|
只看该作者
感谢分享
回复
8
#
ID:873833
发表于 2024-1-17 16:08
|
只看该作者
楼主,请问为什么PID定义那里编译不过呢?会是什么原因?
回复
返回列表
手机版
|
小黑屋
|
51黑电子论坛
|
管理员QQ:125739409;技术交流QQ群281945664
Powered by
单片机教程网