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