Source: https://gist.github.com/bradley219/5373998 Include serial output
Dependencies: mbed
Dependents: DC_Stepper_Controller_Lib
pid.h@0:845ccddeede5, 2021-05-24 (annotated)
- Committer:
- ftppr
- Date:
- Mon May 24 14:46:32 2021 +0000
- Revision:
- 0:845ccddeede5
pid
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ftppr | 0:845ccddeede5 | 1 | /** |
ftppr | 0:845ccddeede5 | 2 | * Copyright 2019 Bradley J. Snyder <snyder.bradleyj@gmail.com> |
ftppr | 0:845ccddeede5 | 3 | * |
ftppr | 0:845ccddeede5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
ftppr | 0:845ccddeede5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
ftppr | 0:845ccddeede5 | 6 | * in the Software without restriction, including without limitation the rights |
ftppr | 0:845ccddeede5 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
ftppr | 0:845ccddeede5 | 8 | * copies of the Software, and to permit persons to whom the Software is |
ftppr | 0:845ccddeede5 | 9 | * furnished to do so, subject to the following conditions: |
ftppr | 0:845ccddeede5 | 10 | * |
ftppr | 0:845ccddeede5 | 11 | * The above copyright notice and this permission notice shall be included in |
ftppr | 0:845ccddeede5 | 12 | * all copies or substantial portions of the Software. |
ftppr | 0:845ccddeede5 | 13 | * |
ftppr | 0:845ccddeede5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
ftppr | 0:845ccddeede5 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
ftppr | 0:845ccddeede5 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
ftppr | 0:845ccddeede5 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
ftppr | 0:845ccddeede5 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ftppr | 0:845ccddeede5 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
ftppr | 0:845ccddeede5 | 20 | * THE SOFTWARE. |
ftppr | 0:845ccddeede5 | 21 | */ |
ftppr | 0:845ccddeede5 | 22 | |
ftppr | 0:845ccddeede5 | 23 | #ifndef _PID_H_ |
ftppr | 0:845ccddeede5 | 24 | #define _PID_H_ |
ftppr | 0:845ccddeede5 | 25 | |
ftppr | 0:845ccddeede5 | 26 | class PIDImpl; |
ftppr | 0:845ccddeede5 | 27 | class PID |
ftppr | 0:845ccddeede5 | 28 | { |
ftppr | 0:845ccddeede5 | 29 | public: |
ftppr | 0:845ccddeede5 | 30 | // Kp - proportional gain |
ftppr | 0:845ccddeede5 | 31 | // Ki - Integral gain |
ftppr | 0:845ccddeede5 | 32 | // Kd - derivative gain |
ftppr | 0:845ccddeede5 | 33 | // dt - loop interval time |
ftppr | 0:845ccddeede5 | 34 | // max - maximum value of manipulated variable |
ftppr | 0:845ccddeede5 | 35 | // min - minimum value of manipulated variable |
ftppr | 0:845ccddeede5 | 36 | PID( double dt, double max, double min, double Kp, double Kd, double Ki ); |
ftppr | 0:845ccddeede5 | 37 | |
ftppr | 0:845ccddeede5 | 38 | // Returns the manipulated variable given a setpoint and current process value |
ftppr | 0:845ccddeede5 | 39 | double calculate( double setpoint, double pv ); |
ftppr | 0:845ccddeede5 | 40 | ~PID(); |
ftppr | 0:845ccddeede5 | 41 | |
ftppr | 0:845ccddeede5 | 42 | private: |
ftppr | 0:845ccddeede5 | 43 | PIDImpl *pimpl; |
ftppr | 0:845ccddeede5 | 44 | }; |
ftppr | 0:845ccddeede5 | 45 | |
ftppr | 0:845ccddeede5 | 46 | #endif |