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