Kazushi Yamanobe
/
R-ciliatable_4
latest version 9/26
pid.h@0:0d02a451e79d, 2021-10-10 (annotated)
- Committer:
- Yamanobe
- Date:
- Sun Oct 10 04:47:14 2021 +0000
- Revision:
- 0:0d02a451e79d
slave program (at 9/26)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yamanobe | 0:0d02a451e79d | 1 | /********************************************* |
Yamanobe | 0:0d02a451e79d | 2 | PID library |
Yamanobe | 0:0d02a451e79d | 3 | |
Yamanobe | 0:0d02a451e79d | 4 | PositionPid : 位置型 |
Yamanobe | 0:0d02a451e79d | 5 | SpeedPid : 速度型 |
Yamanobe | 0:0d02a451e79d | 6 | |
Yamanobe | 0:0d02a451e79d | 7 | setup(float Kp, float Ki, float Kd, float dt) |
Yamanobe | 0:0d02a451e79d | 8 | パラメータ、制御周期の設定 |
Yamanobe | 0:0d02a451e79d | 9 | Kp : Pゲイン |
Yamanobe | 0:0d02a451e79d | 10 | Ki : Iゲイン |
Yamanobe | 0:0d02a451e79d | 11 | Kd : Dゲイン |
Yamanobe | 0:0d02a451e79d | 12 | dt : 制御周期[s] |
Yamanobe | 0:0d02a451e79d | 13 | |
Yamanobe | 0:0d02a451e79d | 14 | calculate(float target, float nowValue) |
Yamanobe | 0:0d02a451e79d | 15 | PIDの計算をする |
Yamanobe | 0:0d02a451e79d | 16 | target : 目標値 |
Yamanobe | 0:0d02a451e79d | 17 | nowValue : 現在値 |
Yamanobe | 0:0d02a451e79d | 18 | |
Yamanobe | 0:0d02a451e79d | 19 | duty() |
Yamanobe | 0:0d02a451e79d | 20 | 計算結果を-1~1で返す |
Yamanobe | 0:0d02a451e79d | 21 | *********************************************/ |
Yamanobe | 0:0d02a451e79d | 22 | |
Yamanobe | 0:0d02a451e79d | 23 | #ifndef MBED_PID_H |
Yamanobe | 0:0d02a451e79d | 24 | #define MBED_PID_H |
Yamanobe | 0:0d02a451e79d | 25 | |
Yamanobe | 0:0d02a451e79d | 26 | #include "mbed.h" |
Yamanobe | 0:0d02a451e79d | 27 | |
Yamanobe | 0:0d02a451e79d | 28 | class PositionPid |
Yamanobe | 0:0d02a451e79d | 29 | { |
Yamanobe | 0:0d02a451e79d | 30 | public : |
Yamanobe | 0:0d02a451e79d | 31 | void setup(float Kp, float Ki, float Kd, float dt); |
Yamanobe | 0:0d02a451e79d | 32 | |
Yamanobe | 0:0d02a451e79d | 33 | void calculate(float target, float nowValue); |
Yamanobe | 0:0d02a451e79d | 34 | |
Yamanobe | 0:0d02a451e79d | 35 | float duty(); |
Yamanobe | 0:0d02a451e79d | 36 | |
Yamanobe | 0:0d02a451e79d | 37 | private : |
Yamanobe | 0:0d02a451e79d | 38 | float kp, ki, kd, |
Yamanobe | 0:0d02a451e79d | 39 | time, frequency, |
Yamanobe | 0:0d02a451e79d | 40 | old, now, |
Yamanobe | 0:0d02a451e79d | 41 | p, i, d, result; |
Yamanobe | 0:0d02a451e79d | 42 | }; |
Yamanobe | 0:0d02a451e79d | 43 | |
Yamanobe | 0:0d02a451e79d | 44 | class SpeedPid |
Yamanobe | 0:0d02a451e79d | 45 | { |
Yamanobe | 0:0d02a451e79d | 46 | public : |
Yamanobe | 0:0d02a451e79d | 47 | void setup(float Kp, float Ki, float Kd, float dt); |
Yamanobe | 0:0d02a451e79d | 48 | |
Yamanobe | 0:0d02a451e79d | 49 | void calculate(float target, float nowValue); |
Yamanobe | 0:0d02a451e79d | 50 | |
Yamanobe | 0:0d02a451e79d | 51 | float duty(); |
Yamanobe | 0:0d02a451e79d | 52 | |
Yamanobe | 0:0d02a451e79d | 53 | private : |
Yamanobe | 0:0d02a451e79d | 54 | float kp, ki, kd, |
Yamanobe | 0:0d02a451e79d | 55 | time, frequency, |
Yamanobe | 0:0d02a451e79d | 56 | e, e1, e2, |
Yamanobe | 0:0d02a451e79d | 57 | p, i, d, result; |
Yamanobe | 0:0d02a451e79d | 58 | }; |
Yamanobe | 0:0d02a451e79d | 59 | |
Yamanobe | 0:0d02a451e79d | 60 | #endif |