自動投射のみです。(手動用にチューニングしました)
Dependencies: HCSR04 PID QEI mbed
Fork of Lets_move_Seki2018_ver2 by
main.cpp@0:f73c1b076ae4, 2018-07-10 (annotated)
- Committer:
- yuron
- Date:
- Tue Jul 10 13:40:10 2018 +0000
- Revision:
- 0:f73c1b076ae4
- Child:
- 1:62b321f6c9c3
B??????????????????(2018/07/10??); PID???????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yuron | 0:f73c1b076ae4 | 1 | /* タイマ割り込みを使用して回転数(RPS)を取得し表示するプログラム */ |
yuron | 0:f73c1b076ae4 | 2 | /* これまでの計算手順では回転数が取得できないことが判明し、改善済である */ |
yuron | 0:f73c1b076ae4 | 3 | /* 具体的には取得したパルス数を分解能で割り算→掛け算でRPSへ変換から */ |
yuron | 0:f73c1b076ae4 | 4 | /* 取得したパルス数を掛け算→分解能で割ってRPSへ変換としている。 */ |
yuron | 0:f73c1b076ae4 | 5 | /* ロリコンにはTIM2~TIM5がいいらしい(Nucleo_F401re) */ |
yuron | 0:f73c1b076ae4 | 6 | /* TIM2(CH1: NC, CH2: D3(PB_3), CH3: D6(PB_10), CH4: NC) */ |
yuron | 0:f73c1b076ae4 | 7 | /* TIM3(CH1: D5(PB_4), CH2: D9(PC_7), CH3: NC, CH4: NC) */ |
yuron | 0:f73c1b076ae4 | 8 | /* TIM4(CH1: D10(PB_6), CH2: NC, CH3: NC, CH4: NC) */ |
yuron | 0:f73c1b076ae4 | 9 | /* TIM5(CH1: NC, CH2: NC, CH3: NC, CH4: NC) */ |
yuron | 0:f73c1b076ae4 | 10 | /* 2018/6/9追記 */ |
yuron | 0:f73c1b076ae4 | 11 | /* ついに回転数の!PI制御を実現できました。 */ |
yuron | 0:f73c1b076ae4 | 12 | /* タイマ割込みで角速度を取得してみようと思います。 */ |
yuron | 0:f73c1b076ae4 | 13 | |
yuron | 0:f73c1b076ae4 | 14 | #include "mbed.h" |
yuron | 0:f73c1b076ae4 | 15 | #include "math.h" |
yuron | 0:f73c1b076ae4 | 16 | #include "QEI.h" |
yuron | 0:f73c1b076ae4 | 17 | #include "PID.h" |
yuron | 0:f73c1b076ae4 | 18 | #define PI 3.14159265359 |
yuron | 0:f73c1b076ae4 | 19 | |
yuron | 0:f73c1b076ae4 | 20 | PID controller(0.7, 0.7, 0.0, 0.001); |
yuron | 0:f73c1b076ae4 | 21 | PID RF(0.5, 0.3, 0.0, 0.001); |
yuron | 0:f73c1b076ae4 | 22 | PID RB(0.5, 0.3, 0.0, 0.001); |
yuron | 0:f73c1b076ae4 | 23 | PID LF(0.5, 0.3, 0.0, 0.001); |
yuron | 0:f73c1b076ae4 | 24 | PID LB(0.5, 0.3, 0.0, 0.001); |
yuron | 0:f73c1b076ae4 | 25 | I2C i2c(PB_3, PB_10); //SDA, SCL |
yuron | 0:f73c1b076ae4 | 26 | //Serial pc(USBTX, USBRX); |
yuron | 0:f73c1b076ae4 | 27 | DigitalOut emergency(PA_13); |
yuron | 0:f73c1b076ae4 | 28 | |
yuron | 0:f73c1b076ae4 | 29 | /* 以下446基板用 */ |
yuron | 0:f73c1b076ae4 | 30 | QEI wheel_LB(PA_1, PA_0, NC, 624); |
yuron | 0:f73c1b076ae4 | 31 | QEI wheel_RB(PB_6, PB_7, NC, 624); |
yuron | 0:f73c1b076ae4 | 32 | QEI wheel_LF(PB_4, PB_5, NC, 624); |
yuron | 0:f73c1b076ae4 | 33 | QEI wheel_RF(PC_8, PC_9, NC, 624); |
yuron | 0:f73c1b076ae4 | 34 | |
yuron | 0:f73c1b076ae4 | 35 | Ticker get_RPS; |
yuron | 0:f73c1b076ae4 | 36 | Ticker print_RPS; |
yuron | 0:f73c1b076ae4 | 37 | |
yuron | 0:f73c1b076ae4 | 38 | int rps_RF; |
yuron | 0:f73c1b076ae4 | 39 | int rps_RB; |
yuron | 0:f73c1b076ae4 | 40 | int rps_LF; |
yuron | 0:f73c1b076ae4 | 41 | int rps_LB; |
yuron | 0:f73c1b076ae4 | 42 | |
yuron | 0:f73c1b076ae4 | 43 | int rpm_RF; |
yuron | 0:f73c1b076ae4 | 44 | int rpm_RB; |
yuron | 0:f73c1b076ae4 | 45 | int rpm_LF; |
yuron | 0:f73c1b076ae4 | 46 | int rpm_LB; |
yuron | 0:f73c1b076ae4 | 47 | |
yuron | 0:f73c1b076ae4 | 48 | int pulse_RF; |
yuron | 0:f73c1b076ae4 | 49 | int pulse_RB; |
yuron | 0:f73c1b076ae4 | 50 | int pulse_LF; |
yuron | 0:f73c1b076ae4 | 51 | int pulse_LB; |
yuron | 0:f73c1b076ae4 | 52 | |
yuron | 0:f73c1b076ae4 | 53 | int counter_RF; |
yuron | 0:f73c1b076ae4 | 54 | int counter_RB; |
yuron | 0:f73c1b076ae4 | 55 | int counter_LF; |
yuron | 0:f73c1b076ae4 | 56 | int counter_LB; |
yuron | 0:f73c1b076ae4 | 57 | |
yuron | 0:f73c1b076ae4 | 58 | double a_v; /* 角速度 */ |
yuron | 0:f73c1b076ae4 | 59 | double n_v; /* 速度(秒速) */ |
yuron | 0:f73c1b076ae4 | 60 | double h_v; /* 速度(時速) */ |
yuron | 0:f73c1b076ae4 | 61 | double n_a; /* 加速度 */ |
yuron | 0:f73c1b076ae4 | 62 | |
yuron | 0:f73c1b076ae4 | 63 | char send_data[1]; |
yuron | 0:f73c1b076ae4 | 64 | char true_send_data[1]; |
yuron | 0:f73c1b076ae4 | 65 | |
yuron | 0:f73c1b076ae4 | 66 | char RF_data[1]; |
yuron | 0:f73c1b076ae4 | 67 | char RB_data[1]; |
yuron | 0:f73c1b076ae4 | 68 | char LF_data[1]; |
yuron | 0:f73c1b076ae4 | 69 | char LB_data[1]; |
yuron | 0:f73c1b076ae4 | 70 | char true_RF_data[1]; |
yuron | 0:f73c1b076ae4 | 71 | char true_RB_data[1]; |
yuron | 0:f73c1b076ae4 | 72 | char true_LF_data[1]; |
yuron | 0:f73c1b076ae4 | 73 | char true_LB_data[1]; |
yuron | 0:f73c1b076ae4 | 74 | |
yuron | 0:f73c1b076ae4 | 75 | /* ロリコン処理関数 */ |
yuron | 0:f73c1b076ae4 | 76 | void flip(); |
yuron | 0:f73c1b076ae4 | 77 | /* RPS表示関数 */ |
yuron | 0:f73c1b076ae4 | 78 | void flip2(); |
yuron | 0:f73c1b076ae4 | 79 | |
yuron | 0:f73c1b076ae4 | 80 | void flip(){ |
yuron | 0:f73c1b076ae4 | 81 | |
yuron | 0:f73c1b076ae4 | 82 | pulse_RF = wheel_RF.getPulses(); |
yuron | 0:f73c1b076ae4 | 83 | pulse_RB = wheel_RB.getPulses(); |
yuron | 0:f73c1b076ae4 | 84 | pulse_LF = wheel_LF.getPulses(); |
yuron | 0:f73c1b076ae4 | 85 | pulse_LB = wheel_LB.getPulses(); |
yuron | 0:f73c1b076ae4 | 86 | |
yuron | 0:f73c1b076ae4 | 87 | /* *rps変換 */ |
yuron | 0:f73c1b076ae4 | 88 | /*10ms*100 = 1s |
yuron | 0:f73c1b076ae4 | 89 | counter_RB = pulse_RB * 100; |
yuron | 0:f73c1b076ae4 | 90 | counter_LB = pulse_LB * 100; |
yuron | 0:f73c1b076ae4 | 91 | */ |
yuron | 0:f73c1b076ae4 | 92 | |
yuron | 0:f73c1b076ae4 | 93 | //40ms*25 = 1s |
yuron | 0:f73c1b076ae4 | 94 | counter_RF = pulse_RF * 25; |
yuron | 0:f73c1b076ae4 | 95 | counter_RB = pulse_RB * 25; |
yuron | 0:f73c1b076ae4 | 96 | counter_LF = pulse_LF * 25; |
yuron | 0:f73c1b076ae4 | 97 | counter_LB = pulse_LB * 25; |
yuron | 0:f73c1b076ae4 | 98 | |
yuron | 0:f73c1b076ae4 | 99 | /* |
yuron | 0:f73c1b076ae4 | 100 | //100ms*10 = 1s |
yuron | 0:f73c1b076ae4 | 101 | counter_RB = pulse_RB * 10; |
yuron | 0:f73c1b076ae4 | 102 | counter_LB = pulse_LB * 10; |
yuron | 0:f73c1b076ae4 | 103 | */ |
yuron | 0:f73c1b076ae4 | 104 | |
yuron | 0:f73c1b076ae4 | 105 | /* /分解能 */ |
yuron | 0:f73c1b076ae4 | 106 | rps_RF = counter_RF / 100; |
yuron | 0:f73c1b076ae4 | 107 | rps_RB = counter_RB / 100; |
yuron | 0:f73c1b076ae4 | 108 | rps_LF = counter_LF / 100; |
yuron | 0:f73c1b076ae4 | 109 | rps_LB = counter_LB / 100; |
yuron | 0:f73c1b076ae4 | 110 | |
yuron | 0:f73c1b076ae4 | 111 | rpm_RF = pulse_RF * 25 * 60 / 100; |
yuron | 0:f73c1b076ae4 | 112 | rpm_RB = pulse_RB * 25 * 60 / 100; |
yuron | 0:f73c1b076ae4 | 113 | rpm_LF = pulse_LF * 25 * 60 / 100; |
yuron | 0:f73c1b076ae4 | 114 | rpm_LB = pulse_LB * 25 * 60 / 100; |
yuron | 0:f73c1b076ae4 | 115 | |
yuron | 0:f73c1b076ae4 | 116 | /* |
yuron | 0:f73c1b076ae4 | 117 | rps[0] = counter_RB / 100; |
yuron | 0:f73c1b076ae4 | 118 | rps[1] = counter_LB / 100; |
yuron | 0:f73c1b076ae4 | 119 | |
yuron | 0:f73c1b076ae4 | 120 | rpm[0] = pulse_RB * 25 * 60 / 100; |
yuron | 0:f73c1b076ae4 | 121 | rpm[1] = pulse_LB * 25 * 60 / 100; |
yuron | 0:f73c1b076ae4 | 122 | */ |
yuron | 0:f73c1b076ae4 | 123 | |
yuron | 0:f73c1b076ae4 | 124 | /* RPMから角速度へ変換 */ |
yuron | 0:f73c1b076ae4 | 125 | a_v = rpm_LB * PI / 30; |
yuron | 0:f73c1b076ae4 | 126 | |
yuron | 0:f73c1b076ae4 | 127 | /* RPMから速度(秒速)へ変換 */ |
yuron | 0:f73c1b076ae4 | 128 | /* タイヤ半径を0.05[m]とする */ |
yuron | 0:f73c1b076ae4 | 129 | n_v = 0.05 * 2 * PI * rpm_LB / 60; |
yuron | 0:f73c1b076ae4 | 130 | |
yuron | 0:f73c1b076ae4 | 131 | /* 速度(秒速)から速度(時速)へ変換 */ |
yuron | 0:f73c1b076ae4 | 132 | h_v = n_v * 3600 / 1000; |
yuron | 0:f73c1b076ae4 | 133 | |
yuron | 0:f73c1b076ae4 | 134 | //n_a = n_v / |
yuron | 0:f73c1b076ae4 | 135 | |
yuron | 0:f73c1b076ae4 | 136 | /* |
yuron | 0:f73c1b076ae4 | 137 | if(rpm[1] < 200){ |
yuron | 0:f73c1b076ae4 | 138 | send_data[0]--; |
yuron | 0:f73c1b076ae4 | 139 | } |
yuron | 0:f73c1b076ae4 | 140 | else if(rpm[1] > 250){ |
yuron | 0:f73c1b076ae4 | 141 | send_data[1]++; |
yuron | 0:f73c1b076ae4 | 142 | } |
yuron | 0:f73c1b076ae4 | 143 | */ |
yuron | 0:f73c1b076ae4 | 144 | |
yuron | 0:f73c1b076ae4 | 145 | //pc.printf("RF: %d RB: %d LF: %d LB: %d\n", rpm_RF, rpm_RB, rpm_LF, rpm_LB); |
yuron | 0:f73c1b076ae4 | 146 | //pc.printf("%d\n", abs(rpm_RF)); |
yuron | 0:f73c1b076ae4 | 147 | //pc.printf("%lf\n", n_v); |
yuron | 0:f73c1b076ae4 | 148 | //pc.printf("%lf\n", h_v); |
yuron | 0:f73c1b076ae4 | 149 | //pc.printf("rpm: %d n_v: %lf\n", rpm[1], n_v); |
yuron | 0:f73c1b076ae4 | 150 | |
yuron | 0:f73c1b076ae4 | 151 | wheel_RF.reset(); |
yuron | 0:f73c1b076ae4 | 152 | wheel_RB.reset(); |
yuron | 0:f73c1b076ae4 | 153 | wheel_LF.reset(); |
yuron | 0:f73c1b076ae4 | 154 | wheel_LB.reset(); |
yuron | 0:f73c1b076ae4 | 155 | } |
yuron | 0:f73c1b076ae4 | 156 | |
yuron | 0:f73c1b076ae4 | 157 | void flip2() |
yuron | 0:f73c1b076ae4 | 158 | { |
yuron | 0:f73c1b076ae4 | 159 | //pc.printf("RPS_RB: %d RPS_LB: %d\n", abs(rps[0]), abs(rps[1])); |
yuron | 0:f73c1b076ae4 | 160 | //pc.printf("RPM_RB: %d RPM_LB: %d\n", abs(rpm[0]), abs(rpm[1])); |
yuron | 0:f73c1b076ae4 | 161 | //pc.printf("%d\n", rpm[1]); |
yuron | 0:f73c1b076ae4 | 162 | //pc.printf("%lf\n", a_v); |
yuron | 0:f73c1b076ae4 | 163 | //pc.printf("rpm: %d a_v: %lf\n", rpm[1], a_v); |
yuron | 0:f73c1b076ae4 | 164 | } |
yuron | 0:f73c1b076ae4 | 165 | |
yuron | 0:f73c1b076ae4 | 166 | void PID() |
yuron | 0:f73c1b076ae4 | 167 | { |
yuron | 0:f73c1b076ae4 | 168 | // センサ出力値の最小、最大 |
yuron | 0:f73c1b076ae4 | 169 | //RF.setInputLimits(0, 1100); |
yuron | 0:f73c1b076ae4 | 170 | RF.setInputLimits(-400, 400); |
yuron | 0:f73c1b076ae4 | 171 | RB.setInputLimits(-400, 400); |
yuron | 0:f73c1b076ae4 | 172 | LF.setInputLimits(-400, 400); |
yuron | 0:f73c1b076ae4 | 173 | LB.setInputLimits(-400, 400); |
yuron | 0:f73c1b076ae4 | 174 | |
yuron | 0:f73c1b076ae4 | 175 | // 制御量の最小、最大 |
yuron | 0:f73c1b076ae4 | 176 | RF.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 177 | RB.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 178 | LF.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 179 | LB.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 180 | |
yuron | 0:f73c1b076ae4 | 181 | // よくわからんやつ |
yuron | 0:f73c1b076ae4 | 182 | RF.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 183 | RB.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 184 | LF.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 185 | LB.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 186 | |
yuron | 0:f73c1b076ae4 | 187 | // 目標値 |
yuron | 0:f73c1b076ae4 | 188 | RF.setSetPoint(300); |
yuron | 0:f73c1b076ae4 | 189 | RB.setSetPoint(300); |
yuron | 0:f73c1b076ae4 | 190 | LF.setSetPoint(300); |
yuron | 0:f73c1b076ae4 | 191 | LB.setSetPoint(300); |
yuron | 0:f73c1b076ae4 | 192 | |
yuron | 0:f73c1b076ae4 | 193 | // センサ出力 |
yuron | 0:f73c1b076ae4 | 194 | RF.setProcessValue(abs(rpm_RF)); |
yuron | 0:f73c1b076ae4 | 195 | RB.setProcessValue(abs(rpm_RB)); |
yuron | 0:f73c1b076ae4 | 196 | LF.setProcessValue(abs(rpm_LF)); |
yuron | 0:f73c1b076ae4 | 197 | LB.setProcessValue(abs(rpm_LB)); |
yuron | 0:f73c1b076ae4 | 198 | |
yuron | 0:f73c1b076ae4 | 199 | // 制御量(計算結果) |
yuron | 0:f73c1b076ae4 | 200 | RF_data[0] = RF.compute(); |
yuron | 0:f73c1b076ae4 | 201 | RB_data[0] = RB.compute(); |
yuron | 0:f73c1b076ae4 | 202 | LF_data[0] = LF.compute(); |
yuron | 0:f73c1b076ae4 | 203 | LB_data[0] = LB.compute(); |
yuron | 0:f73c1b076ae4 | 204 | |
yuron | 0:f73c1b076ae4 | 205 | // 制御量をPWM値に変換 |
yuron | 0:f73c1b076ae4 | 206 | true_RF_data[0] = 0x38 - RF_data[0]; |
yuron | 0:f73c1b076ae4 | 207 | true_RB_data[0] = 0x38 - RB_data[0]; |
yuron | 0:f73c1b076ae4 | 208 | true_LF_data[0] = 0x38 - LF_data[0]; |
yuron | 0:f73c1b076ae4 | 209 | true_LB_data[0] = 0x38 - LB_data[0]; |
yuron | 0:f73c1b076ae4 | 210 | } |
yuron | 0:f73c1b076ae4 | 211 | |
yuron | 0:f73c1b076ae4 | 212 | int main(void) |
yuron | 0:f73c1b076ae4 | 213 | { |
yuron | 0:f73c1b076ae4 | 214 | emergency = 0; |
yuron | 0:f73c1b076ae4 | 215 | send_data[0] = 0x40; |
yuron | 0:f73c1b076ae4 | 216 | i2c.write(0xA0, send_data, 1); |
yuron | 0:f73c1b076ae4 | 217 | i2c.write(0xA2, send_data, 1); |
yuron | 0:f73c1b076ae4 | 218 | i2c.write(0xA4, send_data, 1); |
yuron | 0:f73c1b076ae4 | 219 | i2c.write(0xA6, send_data, 1); |
yuron | 0:f73c1b076ae4 | 220 | wait(0.1); |
yuron | 0:f73c1b076ae4 | 221 | |
yuron | 0:f73c1b076ae4 | 222 | /* 加減速処理を入れた場合処理サイクルの最小周期は40msであった(2018/5/12) */ |
yuron | 0:f73c1b076ae4 | 223 | get_RPS.attach_us(&flip, 40000); |
yuron | 0:f73c1b076ae4 | 224 | //get_RPS.attach_us(&flip, 100000); |
yuron | 0:f73c1b076ae4 | 225 | |
yuron | 0:f73c1b076ae4 | 226 | //RPS表示(0.1sサイクル) |
yuron | 0:f73c1b076ae4 | 227 | //print_RPS.attach(&flip2, 0.1); |
yuron | 0:f73c1b076ae4 | 228 | |
yuron | 0:f73c1b076ae4 | 229 | while(1) |
yuron | 0:f73c1b076ae4 | 230 | { |
yuron | 0:f73c1b076ae4 | 231 | |
yuron | 0:f73c1b076ae4 | 232 | PID(); |
yuron | 0:f73c1b076ae4 | 233 | i2c.write(0xA0, true_RF_data, 1); |
yuron | 0:f73c1b076ae4 | 234 | i2c.write(0xA2, true_RB_data, 1); |
yuron | 0:f73c1b076ae4 | 235 | i2c.write(0xA4, true_LB_data, 1); |
yuron | 0:f73c1b076ae4 | 236 | i2c.write(0xA6, true_LF_data, 1); |
yuron | 0:f73c1b076ae4 | 237 | |
yuron | 0:f73c1b076ae4 | 238 | /* |
yuron | 0:f73c1b076ae4 | 239 | // センサ出力値の最小、最大 |
yuron | 0:f73c1b076ae4 | 240 | RF.setInputLimits(0, 1100); |
yuron | 0:f73c1b076ae4 | 241 | RB.setInputLimits(0, 1100); |
yuron | 0:f73c1b076ae4 | 242 | LF.setInputLimits(0, 1100); |
yuron | 0:f73c1b076ae4 | 243 | LB.setInputLimits(0, 1100); |
yuron | 0:f73c1b076ae4 | 244 | |
yuron | 0:f73c1b076ae4 | 245 | // 制御量の最小、最大 |
yuron | 0:f73c1b076ae4 | 246 | RF.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 247 | RB.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 248 | LF.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 249 | LB.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 250 | |
yuron | 0:f73c1b076ae4 | 251 | // よくわからんやつ |
yuron | 0:f73c1b076ae4 | 252 | RF.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 253 | RB.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 254 | LF.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 255 | LB.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 256 | |
yuron | 0:f73c1b076ae4 | 257 | // 目標値 |
yuron | 0:f73c1b076ae4 | 258 | RF.setSetPoint(400); |
yuron | 0:f73c1b076ae4 | 259 | RB.setSetPoint(400); |
yuron | 0:f73c1b076ae4 | 260 | LF.setSetPoint(400); |
yuron | 0:f73c1b076ae4 | 261 | LB.setSetPoint(400); |
yuron | 0:f73c1b076ae4 | 262 | |
yuron | 0:f73c1b076ae4 | 263 | // センサ出力 |
yuron | 0:f73c1b076ae4 | 264 | RF.setProcessValue(abs(rpm_RF)); |
yuron | 0:f73c1b076ae4 | 265 | RB.setProcessValue(abs(rpm_RB)); |
yuron | 0:f73c1b076ae4 | 266 | LF.setProcessValue(abs(rpm_LF)); |
yuron | 0:f73c1b076ae4 | 267 | LB.setProcessValue(abs(rpm_LB)); |
yuron | 0:f73c1b076ae4 | 268 | |
yuron | 0:f73c1b076ae4 | 269 | // 制御量(計算結果) |
yuron | 0:f73c1b076ae4 | 270 | RF_data[0] = RF.compute(); |
yuron | 0:f73c1b076ae4 | 271 | RB_data[0] = RB.compute(); |
yuron | 0:f73c1b076ae4 | 272 | LF_data[0] = LF.compute(); |
yuron | 0:f73c1b076ae4 | 273 | LB_data[0] = LB.compute(); |
yuron | 0:f73c1b076ae4 | 274 | |
yuron | 0:f73c1b076ae4 | 275 | // 制御量をPWM値に変換 |
yuron | 0:f73c1b076ae4 | 276 | true_RF_data[0] = 0x38 - RF_data[0]; |
yuron | 0:f73c1b076ae4 | 277 | true_RB_data[0] = 0x38 - RB_data[0]; |
yuron | 0:f73c1b076ae4 | 278 | true_LF_data[0] = 0x38 - LF_data[0]; |
yuron | 0:f73c1b076ae4 | 279 | true_LB_data[0] = 0x38 - LB_data[0]; |
yuron | 0:f73c1b076ae4 | 280 | */ |
yuron | 0:f73c1b076ae4 | 281 | |
yuron | 0:f73c1b076ae4 | 282 | /* |
yuron | 0:f73c1b076ae4 | 283 | // センサ出力値の最小、最大 |
yuron | 0:f73c1b076ae4 | 284 | controller.setInputLimits(0, 1100); |
yuron | 0:f73c1b076ae4 | 285 | |
yuron | 0:f73c1b076ae4 | 286 | // 制御量の最小、最大 |
yuron | 0:f73c1b076ae4 | 287 | controller.setOutputLimits(0x01, 0x37); |
yuron | 0:f73c1b076ae4 | 288 | |
yuron | 0:f73c1b076ae4 | 289 | // よくわからんやつ |
yuron | 0:f73c1b076ae4 | 290 | controller.setMode(AUTO_MODE); |
yuron | 0:f73c1b076ae4 | 291 | |
yuron | 0:f73c1b076ae4 | 292 | // 目標値 |
yuron | 0:f73c1b076ae4 | 293 | controller.setSetPoint(400); |
yuron | 0:f73c1b076ae4 | 294 | |
yuron | 0:f73c1b076ae4 | 295 | // センサ出力 |
yuron | 0:f73c1b076ae4 | 296 | controller.setProcessValue(abs(rpm[1])); |
yuron | 0:f73c1b076ae4 | 297 | |
yuron | 0:f73c1b076ae4 | 298 | // 制御量(計算結果) |
yuron | 0:f73c1b076ae4 | 299 | send_data[0] = controller.compute(); |
yuron | 0:f73c1b076ae4 | 300 | |
yuron | 0:f73c1b076ae4 | 301 | // 制御量をPWM値に変換 |
yuron | 0:f73c1b076ae4 | 302 | true_send_data[0] = 0x38 - send_data[0]; |
yuron | 0:f73c1b076ae4 | 303 | |
yuron | 0:f73c1b076ae4 | 304 | i2c.write(0x88, true_send_data, 1); |
yuron | 0:f73c1b076ae4 | 305 | */ |
yuron | 0:f73c1b076ae4 | 306 | |
yuron | 0:f73c1b076ae4 | 307 | /* |
yuron | 0:f73c1b076ae4 | 308 | //どんどん加速 |
yuron | 0:f73c1b076ae4 | 309 | for(send_data[0] = 0x37; send_data[0] > 0x01; send_data[0]--){ |
yuron | 0:f73c1b076ae4 | 310 | //ice(0x88, send_data); |
yuron | 0:f73c1b076ae4 | 311 | //ice(0xA2, send_data); |
yuron | 0:f73c1b076ae4 | 312 | i2c.write(0xA0, send_data, 1); |
yuron | 0:f73c1b076ae4 | 313 | i2c.write(0xA2, send_data, 1); |
yuron | 0:f73c1b076ae4 | 314 | i2c.write(0xA4, send_data, 1); |
yuron | 0:f73c1b076ae4 | 315 | i2c.write(0xA6, send_data, 1); |
yuron | 0:f73c1b076ae4 | 316 | wait(0.1); |
yuron | 0:f73c1b076ae4 | 317 | } |
yuron | 0:f73c1b076ae4 | 318 | |
yuron | 0:f73c1b076ae4 | 319 | //だんだん減速 |
yuron | 0:f73c1b076ae4 | 320 | for(send_data[0] = 0x02; send_data[0] <= 0x37; send_data[0]++){ |
yuron | 0:f73c1b076ae4 | 321 | //ice(0x88, send_data); |
yuron | 0:f73c1b076ae4 | 322 | //ice(0xA2, send_data); |
yuron | 0:f73c1b076ae4 | 323 | i2c.write(0xA0, send_data, 1); |
yuron | 0:f73c1b076ae4 | 324 | i2c.write(0xA2, send_data, 1); |
yuron | 0:f73c1b076ae4 | 325 | i2c.write(0xA4, send_data, 1); |
yuron | 0:f73c1b076ae4 | 326 | i2c.write(0xA6, send_data, 1); |
yuron | 0:f73c1b076ae4 | 327 | wait(0.1); |
yuron | 0:f73c1b076ae4 | 328 | } |
yuron | 0:f73c1b076ae4 | 329 | */ |
yuron | 0:f73c1b076ae4 | 330 | } |
yuron | 0:f73c1b076ae4 | 331 | } |