标题: arduino PID库文件下载 [打印本页]

作者: xiaoyan6hao    时间: 2019-1-10 17:26
标题: arduino PID库文件下载
arduinoPID库文件


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

  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. }
复制代码



作者: ecpc    时间: 2019-1-12 12:52
没有解压密码

作者: muelfox    时间: 2019-1-14 19:17
谢谢分享
作者: HeiZu    时间: 2019-5-4 01:27
感谢分享
作者: kb_001    时间: 2019-7-14 21:24

感谢分享
作者: Markus0010    时间: 2019-11-1 17:26
谢谢分享
作者: 雷一刀    时间: 2020-2-5 22:58
感谢分享
作者: way42    时间: 2024-1-17 16:08
楼主,请问为什么PID定义那里编译不过呢?会是什么原因?




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1