找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6357|回复: 7
打印 上一主题 下一主题
收起左侧

arduino PID库文件下载

  [复制链接]
跳转到指定楼层
楼主
arduinoPID库文件


3个文件下载(仅供参考,有错误请指出):
PID_v1.rar (6.84 KB, 下载次数: 136)

  1. /********************************************************
  2. * PID RelayOutput Example
  3. * Same as basic example, except that this time, the output
  4. * is going to a digital pin which (we presume) is controlling
  5. * a relay.  the pid is designed to Output an analog value,
  6. * but the relay can only be On/Off.
  7. *
  8. *   to connect them together we use "time proportioning
  9. * control"  it's essentially a really slow version of PWM.
  10. * first we decide on a window size (5000mS say.) we then
  11. * set the pid to adjust its output between 0 and that window
  12. * size.  lastly, we add some logic that translates the PID
  13. * output into "Relay On Time" with the remainder of the
  14. * window being "Relay Off Time"

  15. PID继电器输出范例
  16. 与基本范例相同,这一次输出是一个数字引脚控制的继电器。PID被设计成
  17. 输出一个模拟值,但是继电器只有开关状态。
  18. 为了联系上两者,我们使用时间比例控制,它本质上是一个很慢的PWM。
  19. 首先我们决定一个窗口时间(比如5000ms)。
  20. 然后设置PID适应它的输出在0到窗口时间的范围。
  21. 最后我们添加一些逻辑,把PID输出转换成“继电器接通时间”和剩余的
  22. “继电器断开时间”
  23. ********************************************************/

  24. #include <PID_v1.h>
  25. #define RelayPin 8
  26. // 定义我们将要使用的变量
  27. //Define Variables we'll be connecting to
  28. double Setpoint, Input, Output;
  29. //指定链接和最初的调优参数
  30. //Specify the links and initial tuning parameters
  31. PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

  32. int WindowSize = 2000;
  33. unsigned long windowStartTime;
  34. void setup()
  35. {
  36.   windowStartTime = millis();
  37.   //初始化变量
  38.   //initialize the variables we're linked to
  39.   Setpoint = 100;
  40.   //告诉PID在从0到窗口大小的范围内取值
  41.   //tell the PID to range between 0 and the full window size
  42.   myPID.SetOutputLimits(0, WindowSize);
  43.   //开启PID
  44.   //turn the PID on
  45.   myPID.SetMode(AUTOMATIC);
  46. }

  47. void loop()
  48. {
  49.   Input = analogRead(0);
  50.   myPID.Compute();

  51.   /************************************************
  52.    * turn the output pin on/off based on pid output 基于PID输出,打开或关闭端口输出
  53.    ************************************************/
  54.   if(millis() - windowStartTime>WindowSize)
  55.   { //time to shift the Relay Window 继电器窗口时间
  56.     windowStartTime += WindowSize;
  57.   }
  58.   if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
  59.   else digitalWrite(RelayPin,LOW);

  60. }
复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏6 分享淘帖 顶 踩
回复

使用道具 举报

沙发
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黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表