虽然移植完毕,但是不work。需要细调……

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PID_v2.h Source File

PID_v2.h

00001 #ifndef PID_v2_h
00002 #define PID_v2_h
00003 #define LIBRARY_VERSION 1.1.2
00004 
00005 class PID
00006 {
00007 
00008 
00009   public:
00010 
00011   //Constants used in some of the functions below
00012   #define AUTOMATIC 1
00013   #define MANUAL    0
00014   #define DIRECT  0
00015   #define REVERSE  1
00016 
00017   //commonly used functions **************************************************************************
00018     PID(double, double, double, int);     //   Setpoint.  Initial tuning parameters are also set here
00019     
00020     void SetMode(int Mode);               // * sets PID to either Manual (0) or Auto (non-0)
00021 
00022     float Compute(float, float);                       // * performs the PID calculation.  it should be
00023                                           //   called every time loop() cycles. ON/OFF and
00024                                           //   calculation frequency can be set using SetMode
00025                                           //   SetSampleTime respectively
00026 
00027     void SetOutputLimits(double, double); //clamps the output to a specific range. 0-255 by default, but
00028                                           //it's likely the user will want to change this depending on
00029                                           //the application
00030     
00031 
00032     void SetITermLimits(double, double);
00033   //available but not commonly used functions ********************************************************
00034     void SetTunings(double, double,       // * While most users will set the tunings once in the 
00035                     double);              //   constructor, this function gives the user the option
00036                                           //   of changing tunings during runtime for Adaptive control
00037     void SetControllerDirection(int);     // * Sets the Direction, or "Action" of the controller. DIRECT
00038                                           //   means the output will increase when error is positive. REVERSE
00039                                           //   means the opposite.  it's very unlikely that this will be needed
00040                                           //   once it is set in the constructor.
00041     void SetSampleTime(int);              // * sets the frequency, in Milliseconds, with which 
00042                                           //   the PID calculation is performed.  default is 100
00043                                           
00044                                           
00045                                           
00046   //Display functions ****************************************************************
00047     double GetKp();                       // These functions query the pid for interal values.
00048     double GetKi();                       //  they were created mainly for the pid front-end,
00049     double GetKd();                       // where it's important to know what is actually 
00050     int GetMode();                        //  inside the PID.
00051     int GetDirection();                   //
00052 
00053   private:
00054     void Initialize();
00055     
00056     double dispKp;              // * we'll hold on to the tuning parameters in user-entered 
00057     double dispKi;              //   format for display purposes
00058     double dispKd;              //
00059     
00060     double kp;                  // * (P)roportional Tuning Parameter
00061     double ki;                  // * (I)ntegral Tuning Parameter
00062     double kd;                  // * (D)erivative Tuning Parameter
00063 
00064     int controllerDirection;
00065 
00066     float *myInput;              // * Pointers to the Input, Output, and Setpoint variables
00067     float *myOutput;             //   This creates a hard link between the variables and the 
00068     float *mySetpoint;           //   PID, freeing the user from having to constantly tell us
00069                                   //   what these values are.  with pointers we'll just know.
00070               
00071     unsigned long lastTime;
00072     double ITerm, lastInput;
00073 
00074     unsigned long SampleTime;
00075     double outMin, outMax;
00076     double errorMin, errorMax;
00077     bool inAuto;
00078 };
00079 #endif
00080 
00081