Merge dd51ba7349
into 9b4ca0e5b6
This commit is contained in:
commit
3df9c635dc
44
PID_v1.cpp
44
PID_v1.cpp
@ -1,5 +1,5 @@
|
||||
/**********************************************************************************************
|
||||
* Arduino PID Library - Version 1.2.1
|
||||
* Arduino Makeblock PID Library - Version 0.0.1
|
||||
* by Brett Beauregard <br3ttb@gmail.com> brettbeauregard.com
|
||||
*
|
||||
* This Library is licensed under the MIT License
|
||||
@ -14,10 +14,10 @@
|
||||
#include <PID_v1.h>
|
||||
|
||||
/*Constructor (...)*********************************************************
|
||||
* The parameters specified here are those for for which we can't set up
|
||||
* The parameters specified here are those 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,
|
||||
PID2::PID2(double* Input, double* Output, double* Setpoint,
|
||||
double Kp, double Ki, double Kd, int POn, int ControllerDirection)
|
||||
{
|
||||
myOutput = Output;
|
||||
@ -25,13 +25,13 @@ PID::PID(double* Input, double* Output, double* Setpoint,
|
||||
mySetpoint = Setpoint;
|
||||
inAuto = false;
|
||||
|
||||
PID::SetOutputLimits(0, 255); //default output limit corresponds to
|
||||
PID2::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, POn);
|
||||
PID2::SetControllerDirection(ControllerDirection);
|
||||
PID2::SetTunings(Kp, Ki, Kd, POn);
|
||||
|
||||
lastTime = millis()-SampleTime;
|
||||
}
|
||||
@ -41,9 +41,9 @@ PID::PID(double* Input, double* Output, double* Setpoint,
|
||||
* to use Proportional on Error without explicitly saying so
|
||||
***************************************************************************/
|
||||
|
||||
PID::PID(double* Input, double* Output, double* Setpoint,
|
||||
PID2::PID2(double* Input, double* Output, double* Setpoint,
|
||||
double Kp, double Ki, double Kd, int ControllerDirection)
|
||||
:PID::PID(Input, Output, Setpoint, Kp, Ki, Kd, P_ON_E, ControllerDirection)
|
||||
:PID2::PID2(Input, Output, Setpoint, Kp, Ki, Kd, P_ON_E, ControllerDirection)
|
||||
{
|
||||
|
||||
}
|
||||
@ -55,7 +55,7 @@ PID::PID(double* Input, double* Output, double* Setpoint,
|
||||
* pid Output needs to be computed. returns true when the output is computed,
|
||||
* false when nothing has been done.
|
||||
**********************************************************************************/
|
||||
bool PID::Compute()
|
||||
bool PID2::Compute()
|
||||
{
|
||||
if(!inAuto) return false;
|
||||
unsigned long now = millis();
|
||||
@ -99,7 +99,7 @@ bool PID::Compute()
|
||||
* 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, int POn)
|
||||
void PID2::SetTunings(double Kp, double Ki, double Kd, int POn)
|
||||
{
|
||||
if (Kp<0 || Ki<0 || Kd<0) return;
|
||||
|
||||
@ -124,14 +124,14 @@ void PID::SetTunings(double Kp, double Ki, double Kd, int POn)
|
||||
/* SetTunings(...)*************************************************************
|
||||
* Set Tunings using the last-rembered POn setting
|
||||
******************************************************************************/
|
||||
void PID::SetTunings(double Kp, double Ki, double Kd){
|
||||
void PID2::SetTunings(double Kp, double Ki, double Kd){
|
||||
SetTunings(Kp, Ki, Kd, pOn);
|
||||
}
|
||||
|
||||
/* SetSampleTime(...) *********************************************************
|
||||
* sets the period, in Milliseconds, at which the calculation is performed
|
||||
******************************************************************************/
|
||||
void PID::SetSampleTime(int NewSampleTime)
|
||||
void PID2::SetSampleTime(int NewSampleTime)
|
||||
{
|
||||
if (NewSampleTime > 0)
|
||||
{
|
||||
@ -151,7 +151,7 @@ void PID::SetSampleTime(int NewSampleTime)
|
||||
* want to clamp it from 0-125. who knows. at any rate, that can all be done
|
||||
* here.
|
||||
**************************************************************************/
|
||||
void PID::SetOutputLimits(double Min, double Max)
|
||||
void PID2::SetOutputLimits(double Min, double Max)
|
||||
{
|
||||
if(Min >= Max) return;
|
||||
outMin = Min;
|
||||
@ -172,12 +172,12 @@ void PID::SetOutputLimits(double Min, double Max)
|
||||
* when the transition from manual to auto occurs, the controller is
|
||||
* automatically initialized
|
||||
******************************************************************************/
|
||||
void PID::SetMode(int Mode)
|
||||
void PID2::SetMode(int Mode)
|
||||
{
|
||||
bool newAuto = (Mode == AUTOMATIC);
|
||||
if(newAuto && !inAuto)
|
||||
{ /*we just went from manual to auto*/
|
||||
PID::Initialize();
|
||||
PID2::Initialize();
|
||||
}
|
||||
inAuto = newAuto;
|
||||
}
|
||||
@ -186,7 +186,7 @@ void PID::SetMode(int Mode)
|
||||
* does all the things that need to happen to ensure a bumpless transfer
|
||||
* from manual to automatic mode.
|
||||
******************************************************************************/
|
||||
void PID::Initialize()
|
||||
void PID2::Initialize()
|
||||
{
|
||||
outputSum = *myOutput;
|
||||
lastInput = *myInput;
|
||||
@ -200,7 +200,7 @@ void PID::Initialize()
|
||||
* know which one, because otherwise we may increase the output when we should
|
||||
* be decreasing. This is called from the constructor.
|
||||
******************************************************************************/
|
||||
void PID::SetControllerDirection(int Direction)
|
||||
void PID2::SetControllerDirection(int Direction)
|
||||
{
|
||||
if(inAuto && Direction !=controllerDirection)
|
||||
{
|
||||
@ -216,9 +216,9 @@ void PID::SetControllerDirection(int Direction)
|
||||
* functions query the internal state of the PID. they're here for display
|
||||
* purposes. this are the functions the PID Front-end uses for example
|
||||
******************************************************************************/
|
||||
double PID::GetKp(){ return dispKp; }
|
||||
double PID::GetKi(){ return dispKi;}
|
||||
double PID::GetKd(){ return dispKd;}
|
||||
int PID::GetMode(){ return inAuto ? AUTOMATIC : MANUAL;}
|
||||
int PID::GetDirection(){ return controllerDirection;}
|
||||
double PID2::GetKp(){ return dispKp; }
|
||||
double PID2::GetKi(){ return dispKi;}
|
||||
double PID2::GetKd(){ return dispKd;}
|
||||
int PID2::GetMode(){ return inAuto ? AUTOMATIC : MANUAL;}
|
||||
int PID2::GetDirection(){ return controllerDirection;}
|
||||
|
||||
|
8
PID_v1.h
8
PID_v1.h
@ -1,8 +1,8 @@
|
||||
#ifndef PID_v1_h
|
||||
#define PID_v1_h
|
||||
#define LIBRARY_VERSION 1.2.1
|
||||
#define LIBRARY_VERSION 1.2.2
|
||||
|
||||
class PID
|
||||
class PID2
|
||||
{
|
||||
|
||||
|
||||
@ -17,11 +17,11 @@ class PID
|
||||
#define P_ON_E 1
|
||||
|
||||
//commonly used functions **************************************************************************
|
||||
PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
|
||||
PID2(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
|
||||
double, double, double, int, int);// Setpoint. Initial tuning parameters are also set here.
|
||||
// (overload for specifying proportional mode)
|
||||
|
||||
PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
|
||||
PID2(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
|
||||
double, double, double, int); // Setpoint. Initial tuning parameters are also set here
|
||||
|
||||
void SetMode(int Mode); // * sets PID to either Manual (0) or Auto (non-0)
|
||||
|
@ -1,5 +1,5 @@
|
||||
***************************************************************
|
||||
* Arduino PID Library - Version 1.2.1
|
||||
* Arduino Makeblock PID Library - Version 0.0.1
|
||||
* by Brett Beauregard <br3ttb@gmail.com> brettbeauregard.com
|
||||
*
|
||||
* This Library is licensed under the MIT License
|
||||
|
@ -1,4 +1,4 @@
|
||||
#######################################
|
||||
####################################### PID2 0.0.1
|
||||
# Syntax Coloring Map For PID Library
|
||||
#######################################
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "PID",
|
||||
"name": "PID2",
|
||||
"keywords": "PID, controller, signal",
|
||||
"description": "A PID controller seeks to keep some input variable close to a desired setpoint by adjusting an output. The way in which it does this can be 'tuned' by adjusting three parameters (P,I,D).",
|
||||
"url": "http://playground.arduino.cc/Code/PIDLibrary",
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=PID
|
||||
version=1.2.1
|
||||
name=PID2
|
||||
version=0.0.1
|
||||
author=Brett Beauregard
|
||||
maintainer=Brett Beauregard
|
||||
maintainer=r2d2orc2po@yahoo.com
|
||||
sentence=PID controller
|
||||
paragraph=A PID controller seeks to keep some input variable close to a desired setpoint by adjusting an output. The way in which it does this can be 'tuned' by adjusting three parameters (P,I,D).
|
||||
category=Signal Input/Output
|
||||
category=Input/Output
|
||||
url=http://playground.arduino.cc/Code/PIDLibrary
|
||||
architectures=*
|
||||
|
Loading…
Reference in New Issue
Block a user