kani
Dependencies: 2017NHKpin_config FEP omni_wheel PID R1307 ikarashiMDC
\ ̄\ / ̄/ /l \ \ / / lヽ | ヽ ヽ | | / / | \ ` ‐ヽ ヽ ● ● / / ‐ / \ __ l | ||___|| / l __ / \ \ / \/ /\| 人__人 |/\ <ズワイガニ //\| |/\\ //\| ケガニ |/\\ / . \_____/ \ ┏┓ ┏━┓┏┓ ┏┓ ┏┓┏┓ ┏┓ ┏┓┗┛ ┏┓ ┗┓┃┗┛ ┏┛┗━┓ ┃┃┃┃ ┃┃┏━┛┗┓┏┓┏┛┗━┓┃┃┏┓┏┓┏━━━┓ ┗┓┏━┛ ┃┃┗┛ ┃┃┗━┓┏┛┗┛┗┓┏┓┃┗┛┗┛┃┃┗━━━┛ ┏┛┃┏━┓┃┗━━┓┃┃┏━┛┗┓ ┏┛┃┃┃ ┃┃ ┃┏┛┗━┛┗━━┓┃┃┃┃┏┓┏┛ ┗━┛┃┃ ┃┃┏┓ ┃┃┏━━┓┏━━┛┃┃┃┃┗┛┃ ┏┛┃ ┃┃┃┗━━┓ ┗┛┗━━┛┗━━━┛┗┛┗━━┛ ┗━┛ ┗┛┗━━━┛
bot/PIDcontroller/PID_controller.h@6:fe9767a50891, 2017-09-06 (annotated)
- Committer:
- uchitake
- Date:
- Wed Sep 06 18:39:19 2017 +0900
- Revision:
- 6:fe9767a50891
- Parent:
- 5:16ea97725085
- Child:
- 7:c6acf63088b0
fix coding
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uchitake |
1:845af5425eec | 1 | /** |
uchitake |
1:845af5425eec | 2 | * @file PID_controller.h |
uchitake |
1:845af5425eec | 3 | * @brief コンパスセンサを使ったPIDコントローラ |
uchitake |
1:845af5425eec | 4 | * |
uchitake |
1:845af5425eec | 5 | * Example : |
uchitake |
1:845af5425eec | 6 | * @code |
uchitake |
1:845af5425eec | 7 | * #include "mbed.h" |
uchitake |
1:845af5425eec | 8 | * #include "PID_controller.h" |
uchitake |
1:845af5425eec | 9 | * |
uchitake |
1:845af5425eec | 10 | * PIDC pidc; |
uchitake |
1:845af5425eec | 11 | * |
uchitake |
1:845af5425eec | 12 | * int main() |
uchitake |
1:845af5425eec | 13 | * { |
uchitake |
1:845af5425eec | 14 | * while(1) { |
uchitake |
1:845af5425eec | 15 | * pidc.confirm(); |
uchitake |
1:845af5425eec | 16 | * pc.printf("Hi, %f\r\n", pid.getCo()); |
uchitake |
1:845af5425eec | 17 | * } |
uchitake |
1:845af5425eec | 18 | * } |
uchitake |
1:845af5425eec | 19 | * @endcode |
uchitake |
1:845af5425eec | 20 | */ |
uchitake |
1:845af5425eec | 21 | #ifndef PID_CONTROLLER_H |
uchitake |
1:845af5425eec | 22 | #define PID_CONTROLLER_H |
uchitake |
1:845af5425eec | 23 | |
uchitake |
1:845af5425eec | 24 | #include "mbed.h" |
uchitake |
1:845af5425eec | 25 | #include "pin_config.h" |
uchitake |
1:845af5425eec | 26 | |
uchitake |
1:845af5425eec | 27 | #include "PID.h" |
uchitake |
1:845af5425eec | 28 | #include "HMC6352.h" |
uchitake |
1:845af5425eec | 29 | |
uchitake |
1:845af5425eec | 30 | // const double M_PI = 3.141592653589793; |
uchitake |
5:16ea97725085 | 31 | const double KC = 5.2; |
uchitake |
1:845af5425eec | 32 | const double TI = 0.0; |
uchitake |
5:16ea97725085 | 33 | const double TD = 0.00; |
uchitake |
3:369d9ee17e84 | 34 | const float INTERVAL = 0.01; |
uchitake |
1:845af5425eec | 35 | const float INPUT_LIMIT = 180.0; |
uchitake |
1:845af5425eec | 36 | const float OUTPUT_LIMIT = 0.4; |
uchitake |
1:845af5425eec | 37 | const float BIAS = 0.0; |
uchitake |
6:fe9767a50891 | 38 | const int SENSED_THRESHOLD = 1800; |
uchitake |
1:845af5425eec | 39 | |
uchitake |
1:845af5425eec | 40 | /** |
uchitake |
1:845af5425eec | 41 | * @brief コンパスセンサを使ったPIDコントローラ |
uchitake |
1:845af5425eec | 42 | */ |
uchitake |
1:845af5425eec | 43 | class PIDC : public PID, HMC6352, Ticker |
uchitake |
1:845af5425eec | 44 | { |
uchitake |
1:845af5425eec | 45 | public : |
uchitake |
1:845af5425eec | 46 | /** |
uchitake |
1:845af5425eec | 47 | * @brief defaultコンストラクタ,タイマ割り込みでの計算開始 |
uchitake |
1:845af5425eec | 48 | */ |
uchitake |
1:845af5425eec | 49 | PIDC(); |
uchitake |
1:845af5425eec | 50 | |
uchitake |
1:845af5425eec | 51 | /** |
uchitake |
1:845af5425eec | 52 | * @brief コンストラクタ |
uchitake |
1:845af5425eec | 53 | * @param sda sda HMC6352 |
uchitake |
1:845af5425eec | 54 | * @param scl scl HMC6352 |
uchitake |
1:845af5425eec | 55 | * @param kc KC |
uchitake |
1:845af5425eec | 56 | * @param ti TI |
uchitake |
1:845af5425eec | 57 | * @param td TD |
uchitake |
1:845af5425eec | 58 | * @param interval interval |
uchitake |
1:845af5425eec | 59 | */ |
uchitake |
1:845af5425eec | 60 | PIDC(PinName sda, PinName scl, float kc, float ti, float td, float interval); |
uchitake |
1:845af5425eec | 61 | |
uchitake |
4:1073deb368df | 62 | |
uchitake |
1:845af5425eec | 63 | void confirm(); |
uchitake |
6:fe9767a50891 | 64 | void resetAxisOffset(); |
uchitake |
6:fe9767a50891 | 65 | void resetPlaneOffset(); |
uchitake |
6:fe9767a50891 | 66 | float getCalculationResult() const; |
uchitake |
6:fe9767a50891 | 67 | int getCurrentDegree() const; |
uchitake |
1:845af5425eec | 68 | void calibration(int mode); |
uchitake |
1:845af5425eec | 69 | private : |
uchitake |
1:845af5425eec | 70 | |
uchitake |
1:845af5425eec | 71 | void updateOutput(); |
uchitake |
1:845af5425eec | 72 | |
uchitake |
6:fe9767a50891 | 73 | int axisOffSetDegree; |
uchitake |
6:fe9767a50891 | 74 | int planeOffSetDegree; |
uchitake |
1:845af5425eec | 75 | int turnOverNumber; |
uchitake |
1:845af5425eec | 76 | int beforeDegree; |
uchitake |
1:845af5425eec | 77 | |
uchitake |
1:845af5425eec | 78 | protected : |
uchitake |
5:16ea97725085 | 79 | int rawDegree; |
uchitake |
6:fe9767a50891 | 80 | float calculationResult; |
uchitake |
6:fe9767a50891 | 81 | int axisCurrentDegree; |
uchitake |
6:fe9767a50891 | 82 | int planeCurrentDegree; |
uchitake |
1:845af5425eec | 83 | }; |
uchitake |
1:845af5425eec | 84 | |
uchitake |
1:845af5425eec | 85 | #endif//PID_CONTROLLER_H |