资源简介
解压到arduino-1.6.5-windows\arduino-1.6.5\libraries里面
代码片段和文件信息
/**********************************************************************************************
* Arduino PID Library - Version 1.1.1
* by Brett Beauregard brettbeauregard.com
*
* This Library is licensed under a GPLv3 License
**********************************************************************************************/
#if ARDUINO >= 100
#include “Arduino.h“
#else
#include “WProgram.h“
#endif
#include
/*Constructor (...)*********************************************************
* The parameters specified here are those for for which we can‘t set up
* reliable defaults so we need to have the user set them.
***************************************************************************/
PID::PID(double* Input double* Output double* Setpoint
double Kp double Ki double Kd int ControllerDirection)
{
myOutput = Output;
myInput = Input;
mySetpoint = Setpoint;
inAuto = false;
PID::SetOutputLimits(0 255); //default output limit corresponds to
//the arduino pwm limits
SampleTime = 100; //default Controller Sample Time is 0.1 seconds
PID::SetControllerDirection(ControllerDirection);
PID::SetTunings(Kp Ki Kd);
lastTime = millis()-SampleTime;
}
/* Compute() **********************************************************************
* This as they say is where the magic happens. this function should be called
* every time “void loop()“ executes. the function will decide for itself whether a new
* pid Output needs to be computed. returns true when the output is computed
* false when nothing has been done.
**********************************************************************************/
bool PID::Compute()
{
if(!inAuto) return false;
unsigned long now = millis();
unsigned long timeChange = (now - lastTime);
if(timeChange>=SampleTime)
{
/*Compute all the working error variables*/
double input = *myInput;
double error = *mySetpoint - input;
ITerm+= (ki * error);
if(ITerm > outMax) ITerm= outMax;
else if(ITerm < outMin) ITerm= outMin;
double dInput = (input - lastInput);
/*Compute PID Output*/
double output = kp * error + ITerm- kd * dInput;
if(output > outMax) output = outMax;
else if(output < outMin) output = outMin;
*myOutput = output;
/*Remember some variables for next time*/
lastInput = input;
lastTime = now;
return true;
}
else return false;
}
/* SetTunings(...)*************************************************************
* This function allows the controller‘s dynamic performance to be adjusted.
* it‘s called automatically from the constructor but tunings can also
* be adjusted on the fly during normal operation
******************************************************************************/
void PID::SetTunings(double Kp double Ki double Kd)
{
if (Kp<0 || Ki<0 || Kd<0) return;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-05-10 18:38 Arduino-PID-Library-master\
文件 6918 2015-05-10 18:38 Arduino-PID-Library-master\PID_v1.cpp
文件 3454 2015-05-10 18:38 Arduino-PID-Library-master\PID_v1.h
文件 532 2015-05-10 18:38 Arduino-PID-Library-master\README.txt
目录 0 2015-05-10 18:38 Arduino-PID-Library-master\examples\
目录 0 2015-05-10 18:38 Arduino-PID-Library-master\examples\PID_AdaptiveTunings\
文件 1535 2015-05-10 18:38 Arduino-PID-Library-master\examples\PID_AdaptiveTunings\PID_AdaptiveTunings.ino
目录 0 2015-05-10 18:38 Arduino-PID-Library-master\examples\PID_Basic\
文件 737 2015-05-10 18:38 Arduino-PID-Library-master\examples\PID_Basic\PID_Basic.ino
目录 0 2015-05-10 18:38 Arduino-PID-Library-master\examples\PID_RelayOutput\
文件 1809 2015-05-10 18:38 Arduino-PID-Library-master\examples\PID_RelayOutput\PID_RelayOutput.ino
文件 743 2015-05-10 18:38 Arduino-PID-Library-master\keywords.txt
文件 549 2015-05-10 18:38 Arduino-PID-Library-master\library.json
文件 392 2015-05-10 18:38 Arduino-PID-Library-master\library.properties
- 上一篇:实验1组建简单以太网
- 下一篇:unity开发基础教程,全面
评论
共有 条评论