![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
2017年3月,伊豆大島共同打上実験 CORE_缶ロケチーム電装
Dependencies: MPU6050 MS5607 mbed SDFileSystem
main.cpp@12:211d2c6d2afc, 2017-03-03 (annotated)
- Committer:
- mikawataru
- Date:
- Fri Mar 03 01:26:07 2017 +0000
- Revision:
- 12:211d2c6d2afc
- Parent:
- 11:b61d0fcc2ed3
- Child:
- 13:f73b4beded57
add servo control by serial device
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mikawataru | 5:bcf55d8fe7a7 | 1 | /* |
mikawataru | 5:bcf55d8fe7a7 | 2 | 2017年3月 伊豆大島共同打上実験 |
mikawataru | 5:bcf55d8fe7a7 | 3 | 団体名:CORE |
mikawataru | 5:bcf55d8fe7a7 | 4 | チーム名:ヌペリオル |
mikawataru | 5:bcf55d8fe7a7 | 5 | 該当電装:ロケット搭載用 |
mikawataru | 5:bcf55d8fe7a7 | 6 | |
mikawataru | 5:bcf55d8fe7a7 | 7 | 使用部品 |
mikawataru | 5:bcf55d8fe7a7 | 8 | ・LPC1768(マイコン) |
mikawataru | 5:bcf55d8fe7a7 | 9 | ・MPU6050(加速度・ジャイロセンサ) |
mikawataru | 5:bcf55d8fe7a7 | 10 | ・MS5607(気圧・気温センサ) |
mikawataru | 5:bcf55d8fe7a7 | 11 | ・MicroSDスロット |
mikawataru | 5:bcf55d8fe7a7 | 12 | ・MG995(サーボモータ)×4 |
mikawataru | 5:bcf55d8fe7a7 | 13 | |
mikawataru | 7:5f693667d0e9 | 14 | 使用ライブラリ |
mikawataru | 7:5f693667d0e9 | 15 | ・MPU6050.h |
mikawataru | 7:5f693667d0e9 | 16 | https://developer.mbed.org/teams/mbed/code/SDFileSystem/ |
mikawataru | 7:5f693667d0e9 | 17 | ・MS5607.h |
mikawataru | 7:5f693667d0e9 | 18 | https://developer.mbed.org/users/yamaguch/code/MS5607/ |
mikawataru | 7:5f693667d0e9 | 19 | ・SDFileSystem.h |
mikawataru | 7:5f693667d0e9 | 20 | https://developer.mbed.org/teams/mbed/code/SDFileSystem/ |
mikawataru | 7:5f693667d0e9 | 21 | |
mikawataru | 5:bcf55d8fe7a7 | 22 | ピン配置 |
mikawataru | 5:bcf55d8fe7a7 | 23 | LPC1768 MPU6050 MS5607 MicroSD MG995_1 MG995_2 MG995_3 MG995_4 |
mikawataru | 5:bcf55d8fe7a7 | 24 | VIN--------------------------------------------------------------------4.5~9.0V |
mikawataru | 5:bcf55d8fe7a7 | 25 | -----------------------------------VIN------VIN------VIN------VIN------5V |
mikawataru | 5:bcf55d8fe7a7 | 26 | Vout-----VCC------VIN-----VDD------------------------------------------3.3V |
mikawataru | 6:15204813ef87 | 27 | \-ADO \-PS |
mikawataru | 5:bcf55d8fe7a7 | 28 | GND------GND------GND-----VSS------GND------GND------GND------GND------0V |
mikawataru | 6:15204813ef87 | 29 | \-CS |
mikawataru | 5:bcf55d8fe7a7 | 30 | p9-------SDA------SDA---------------------------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 31 | p10------SCL------SCL---------------------------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 32 | p11-----------------------CLK-------------------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 33 | p12-----------------------DAT0------------------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 34 | p13-----------------------CMD-------------------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 35 | p14-----------------------CD/DAT0---------------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 36 | p23--------------------------------CTRL---------------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 37 | p24-----------------------------------------CTRL------------------------- |
mikawataru | 5:bcf55d8fe7a7 | 38 | p25--------------------------------------------------CTRL---------------- |
mikawataru | 5:bcf55d8fe7a7 | 39 | p26-----------------------------------------------------------CTRL------- |
mikawataru | 5:bcf55d8fe7a7 | 40 | */ |
mikawataru | 0:10a9c9c5ce83 | 41 | #include "mbed.h" |
mikawataru | 7:5f693667d0e9 | 42 | #include "math.h" |
mikawataru | 0:10a9c9c5ce83 | 43 | #include "MS5607I2C.h" |
mikawataru | 0:10a9c9c5ce83 | 44 | #include "MPU6050.h" |
mikawataru | 1:ec75f428c6b3 | 45 | #include "SDFileSystem.h" |
mikawataru | 7:5f693667d0e9 | 46 | /*判定パラメータ*/ |
mikawataru | 8:a9e115560ba3 | 47 | #define ACC_LAUNCH 4//発射判定加速度[g] |
mikawataru | 7:5f693667d0e9 | 48 | #define DROP_TOP 1.5//頂点判定最低降下量[m] |
mikawataru | 12:211d2c6d2afc | 49 | #define ALT_CAN 150//缶サット開放高度[m] |
mikawataru | 8:a9e115560ba3 | 50 | #define TIME_TOP 15//タイマー開放時間[s] |
mikawataru | 3:9cd74af355cc | 51 | /*動作レート*/ |
mikawataru | 3:9cd74af355cc | 52 | #define RATE_LOG 10//ログ用 |
mikawataru | 3:9cd74af355cc | 53 | #define RATE_OPEN 10//開放用 |
mikawataru | 3:9cd74af355cc | 54 | /*サーボ動作*/ |
mikawataru | 6:15204813ef87 | 55 | #define LOCK 0.0005 |
mikawataru | 6:15204813ef87 | 56 | #define UNLOCK 0.0015 |
mikawataru | 12:211d2c6d2afc | 57 | /*フェーズ定義*/ |
mikawataru | 3:9cd74af355cc | 58 | #define STANDBY 0 |
mikawataru | 3:9cd74af355cc | 59 | #define LAUNCH 1 |
mikawataru | 3:9cd74af355cc | 60 | #define FLIGHT 2 |
mikawataru | 7:5f693667d0e9 | 61 | #define DROP 3 |
mikawataru | 12:211d2c6d2afc | 62 | /*入力モード定義*/ |
mikawataru | 12:211d2c6d2afc | 63 | #define BAN 0 |
mikawataru | 12:211d2c6d2afc | 64 | #define NORMAL 1 |
mikawataru | 12:211d2c6d2afc | 65 | #define SERVO_1 2 |
mikawataru | 12:211d2c6d2afc | 66 | #define SERVO_2 3 |
mikawataru | 12:211d2c6d2afc | 67 | #define MODE 4 |
mikawataru | 12:211d2c6d2afc | 68 | /**/ |
mikawataru | 8:a9e115560ba3 | 69 | #define P0 1013.25f//海面気圧[hPa] |
mikawataru | 11:b61d0fcc2ed3 | 70 | #define ACC 4096.0f//加速度オフセット値 |
mikawataru | 7:5f693667d0e9 | 71 | /*ピン指定*/ |
mikawataru | 0:10a9c9c5ce83 | 72 | MS5607I2C ms5607(p9, p10, false); |
mikawataru | 0:10a9c9c5ce83 | 73 | MPU6050 mpu(p9,p10); |
mikawataru | 3:9cd74af355cc | 74 | BusOut myled(LED1,LED2,LED3,LED4); |
mikawataru | 7:5f693667d0e9 | 75 | SDFileSystem sd(p11, p12, p13, p14, "sd"); |
mikawataru | 10:c1d1ff35a6a1 | 76 | Serial device(USBTX, USBRX); |
mikawataru | 5:bcf55d8fe7a7 | 77 | PwmOut Door_1_1(p23); |
mikawataru | 5:bcf55d8fe7a7 | 78 | PwmOut Door_1_2(p24); |
mikawataru | 5:bcf55d8fe7a7 | 79 | PwmOut Door_2_1(p25); |
mikawataru | 5:bcf55d8fe7a7 | 80 | PwmOut Door_2_2(p26); |
mikawataru | 7:5f693667d0e9 | 81 | /*タイマー類*/ |
mikawataru | 1:ec75f428c6b3 | 82 | Timer timer; |
mikawataru | 3:9cd74af355cc | 83 | Ticker loop_log; |
mikawataru | 3:9cd74af355cc | 84 | Ticker loop_open; |
mikawataru | 5:bcf55d8fe7a7 | 85 | /*ログカウンタ*/ |
mikawataru | 5:bcf55d8fe7a7 | 86 | bool row = 0; |
mikawataru | 3:9cd74af355cc | 87 | int8_t col = 0; |
mikawataru | 5:bcf55d8fe7a7 | 88 | /*ログ格納用*/ |
mikawataru | 11:b61d0fcc2ed3 | 89 | float altitude[2][RATE_LOG],pressure[2][RATE_LOG],temperature[2][RATE_LOG]; |
mikawataru | 3:9cd74af355cc | 90 | float acc[2][RATE_LOG][3],gyro[2][RATE_LOG][3]; |
mikawataru | 3:9cd74af355cc | 91 | float t[2][RATE_LOG]; |
mikawataru | 7:5f693667d0e9 | 92 | FILE *fp; |
mikawataru | 11:b61d0fcc2ed3 | 93 | /*フェーズ変数*/ |
mikawataru | 5:bcf55d8fe7a7 | 94 | int8_t Phase = STANDBY; |
mikawataru | 7:5f693667d0e9 | 95 | /*判定用*/ |
mikawataru | 11:b61d0fcc2ed3 | 96 | float alt4open[RATE_OPEN],acc4open; |
mikawataru | 11:b61d0fcc2ed3 | 97 | float alt_max,alt_launch; |
mikawataru | 7:5f693667d0e9 | 98 | float t_drop,t_top,t_launch; |
mikawataru | 11:b61d0fcc2ed3 | 99 | int8_t cnt_judge = 0; |
mikawataru | 11:b61d0fcc2ed3 | 100 | int8_t col_open = 0; |
mikawataru | 12:211d2c6d2afc | 101 | /*入力用*/ |
mikawataru | 12:211d2c6d2afc | 102 | int8_t Input_mode = NORMAL; |
mikawataru | 12:211d2c6d2afc | 103 | int8_t input_buff[3] = {}; |
mikawataru | 7:5f693667d0e9 | 104 | /*関数*/ |
mikawataru | 3:9cd74af355cc | 105 | void _Open(); |
mikawataru | 6:15204813ef87 | 106 | void _Servo(int8_t door_num, float motion); |
mikawataru | 3:9cd74af355cc | 107 | void _Log(); |
mikawataru | 12:211d2c6d2afc | 108 | void _Input(); |
mikawataru | 11:b61d0fcc2ed3 | 109 | float _GetAlt(float press, float temp); |
mikawataru | 11:b61d0fcc2ed3 | 110 | float _Median(float data[], int num); |
mikawataru | 11:b61d0fcc2ed3 | 111 | |
mikawataru | 7:5f693667d0e9 | 112 | /*---------------------------------------------------------------------*/ |
mikawataru | 0:10a9c9c5ce83 | 113 | int main() { |
mikawataru | 11:b61d0fcc2ed3 | 114 | mpu.setAcceleroRange(2); |
mikawataru | 11:b61d0fcc2ed3 | 115 | mpu.setGyroRange(2); |
mikawataru | 1:ec75f428c6b3 | 116 | timer.start(); |
mikawataru | 5:bcf55d8fe7a7 | 117 | Door_1_1.period_ms(20); |
mikawataru | 5:bcf55d8fe7a7 | 118 | Door_1_2.period_ms(20); |
mikawataru | 5:bcf55d8fe7a7 | 119 | Door_2_1.period_ms(20); |
mikawataru | 5:bcf55d8fe7a7 | 120 | Door_2_2.period_ms(20); |
mikawataru | 6:15204813ef87 | 121 | _Servo(0,LOCK); |
mikawataru | 2:b6eb08d059cc | 122 | fp = fopen("/sd/log.txt", "w"); |
mikawataru | 1:ec75f428c6b3 | 123 | fprintf(fp, "pressure,temperature,ax,ay,az,gx,gy,gz\r\n"); |
mikawataru | 12:211d2c6d2afc | 124 | device.attach(&_Input,Serial::RxIrq); |
mikawataru | 3:9cd74af355cc | 125 | loop_log.attach(&_Log,1.0/RATE_LOG); |
mikawataru | 3:9cd74af355cc | 126 | loop_open.attach(&_Open,1.0/RATE_OPEN); |
mikawataru | 3:9cd74af355cc | 127 | while(1); |
mikawataru | 3:9cd74af355cc | 128 | } |
mikawataru | 6:15204813ef87 | 129 | /*開放用関数 RATE_OPEN[Hz]で判定を行う*/ |
mikawataru | 3:9cd74af355cc | 130 | void _Open(){ |
mikawataru | 3:9cd74af355cc | 131 | myled = 1 << (Phase-1); |
mikawataru | 3:9cd74af355cc | 132 | switch (Phase) { |
mikawataru | 3:9cd74af355cc | 133 | case STANDBY://スタンバイモード(発射判定不可) |
mikawataru | 12:211d2c6d2afc | 134 | // Phase = LAUNCH; |
mikawataru | 3:9cd74af355cc | 135 | break; |
mikawataru | 7:5f693667d0e9 | 136 | case LAUNCH://点火モード(発射判定可) |
mikawataru | 11:b61d0fcc2ed3 | 137 | acc4open = (float)mpu.getAcceleroRawZ()/(ACC*0.981); |
mikawataru | 11:b61d0fcc2ed3 | 138 | alt4open[col_open] = _GetAlt(ms5607.getPressure()/100,ms5607.getTemperature()); |
mikawataru | 11:b61d0fcc2ed3 | 139 | if(acc4open>ACC_LAUNCH){ |
mikawataru | 11:b61d0fcc2ed3 | 140 | if(cnt_judge++==3){ |
mikawataru | 11:b61d0fcc2ed3 | 141 | Phase = FLIGHT; |
mikawataru | 11:b61d0fcc2ed3 | 142 | alt_launch = _Median(alt4open, RATE_OPEN); |
mikawataru | 11:b61d0fcc2ed3 | 143 | cnt_judge = 0; |
mikawataru | 11:b61d0fcc2ed3 | 144 | } |
mikawataru | 7:5f693667d0e9 | 145 | t_launch = timer.read(); |
mikawataru | 11:b61d0fcc2ed3 | 146 | alt_max = alt_launch; |
mikawataru | 7:5f693667d0e9 | 147 | }else{ |
mikawataru | 11:b61d0fcc2ed3 | 148 | if(timer.read()>t_launch+1.0) cnt_judge = 0; |
mikawataru | 3:9cd74af355cc | 149 | } |
mikawataru | 11:b61d0fcc2ed3 | 150 | device.printf("%f\r\n",acc4open); |
mikawataru | 4:cc266df87f3e | 151 | break; |
mikawataru | 7:5f693667d0e9 | 152 | case FLIGHT://飛翔中(パラシュート開放判定) |
mikawataru | 11:b61d0fcc2ed3 | 153 | alt4open[col_open] = _GetAlt(ms5607.getPressure()/100,ms5607.getTemperature()); |
mikawataru | 11:b61d0fcc2ed3 | 154 | if(alt4open[col_open]>alt_max) alt_max = alt4open[col_open]; |
mikawataru | 11:b61d0fcc2ed3 | 155 | if(alt4open[col_open]<alt_max-DROP_TOP){ |
mikawataru | 11:b61d0fcc2ed3 | 156 | if(cnt_judge++==3){ |
mikawataru | 7:5f693667d0e9 | 157 | _Servo(1,UNLOCK); |
mikawataru | 7:5f693667d0e9 | 158 | Phase = DROP; |
mikawataru | 11:b61d0fcc2ed3 | 159 | cnt_judge = 0; |
mikawataru | 7:5f693667d0e9 | 160 | } |
mikawataru | 7:5f693667d0e9 | 161 | t_top = timer.read(); |
mikawataru | 7:5f693667d0e9 | 162 | }else{ |
mikawataru | 11:b61d0fcc2ed3 | 163 | if(timer.read()>t_top+1.0) cnt_judge = 0; |
mikawataru | 7:5f693667d0e9 | 164 | } |
mikawataru | 7:5f693667d0e9 | 165 | if(timer.read()-t_launch>TIME_TOP){ |
mikawataru | 7:5f693667d0e9 | 166 | _Servo(1,UNLOCK); |
mikawataru | 7:5f693667d0e9 | 167 | Phase = DROP; |
mikawataru | 11:b61d0fcc2ed3 | 168 | cnt_judge = 0; |
mikawataru | 7:5f693667d0e9 | 169 | } |
mikawataru | 7:5f693667d0e9 | 170 | break; |
mikawataru | 7:5f693667d0e9 | 171 | case DROP://降下中(缶サット開放判定) |
mikawataru | 11:b61d0fcc2ed3 | 172 | if(alt4open[col_open] < alt_launch+ALT_CAN){ |
mikawataru | 11:b61d0fcc2ed3 | 173 | if(cnt_judge++==3){ |
mikawataru | 11:b61d0fcc2ed3 | 174 | _Servo(2,UNLOCK); |
mikawataru | 11:b61d0fcc2ed3 | 175 | cnt_judge = 0; |
mikawataru | 11:b61d0fcc2ed3 | 176 | } |
mikawataru | 7:5f693667d0e9 | 177 | t_drop = timer.read(); |
mikawataru | 7:5f693667d0e9 | 178 | }else{ |
mikawataru | 11:b61d0fcc2ed3 | 179 | if(timer.read()>t_drop+1.0)cnt_judge = 0; |
mikawataru | 7:5f693667d0e9 | 180 | } |
mikawataru | 3:9cd74af355cc | 181 | break; |
mikawataru | 0:10a9c9c5ce83 | 182 | } |
mikawataru | 11:b61d0fcc2ed3 | 183 | if(col_open++==RATE_OPEN) col_open = 0; |
mikawataru | 0:10a9c9c5ce83 | 184 | } |
mikawataru | 6:15204813ef87 | 185 | /*記録用関数 RATE_LOG[Hz]で記録を行う*/ |
mikawataru | 3:9cd74af355cc | 186 | void _Log(){ |
mikawataru | 3:9cd74af355cc | 187 | t[row][col] = timer.read(); |
mikawataru | 7:5f693667d0e9 | 188 | pressure[row][col] = ms5607.getPressure()/100; |
mikawataru | 3:9cd74af355cc | 189 | temperature[row][col] = ms5607.getTemperature(); |
mikawataru | 3:9cd74af355cc | 190 | mpu.getAccelero(&acc[row][col][0]); |
mikawataru | 3:9cd74af355cc | 191 | mpu.getGyro(&gyro[row][col][0]); |
mikawataru | 3:9cd74af355cc | 192 | fprintf(fp, "%f,%f,%f,%f,%f,%f,%f,%f,%f\r\n", |
mikawataru | 11:b61d0fcc2ed3 | 193 | t[row][col],pressure[row][col],temperature[row][col],acc[row][col][0]/10.0, |
mikawataru | 11:b61d0fcc2ed3 | 194 | acc[row][col][1]/10.0,acc[row][col][2]/10.0,gyro[row][col][0],gyro[row][col][1],gyro[row][col][2] |
mikawataru | 3:9cd74af355cc | 195 | ); |
mikawataru | 3:9cd74af355cc | 196 | if(col++==RATE_LOG){ |
mikawataru | 3:9cd74af355cc | 197 | fclose(fp); |
mikawataru | 3:9cd74af355cc | 198 | fp = fopen("/sd/log.txt", "a"); |
mikawataru | 3:9cd74af355cc | 199 | row =! row; |
mikawataru | 3:9cd74af355cc | 200 | col = 0; |
mikawataru | 3:9cd74af355cc | 201 | } |
mikawataru | 3:9cd74af355cc | 202 | } |
mikawataru | 6:15204813ef87 | 203 | /*サーボ動作用関数 _Servo(int8_t 扉番号,float pwm波長)*/ |
mikawataru | 6:15204813ef87 | 204 | void _Servo(int8_t door_num, float motion){ |
mikawataru | 6:15204813ef87 | 205 | if(door_num==0){//全扉 |
mikawataru | 6:15204813ef87 | 206 | Door_1_1.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 207 | Door_1_2.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 208 | Door_2_1.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 209 | Door_2_2.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 210 | }else if(door_num==1){//扉1 |
mikawataru | 6:15204813ef87 | 211 | Door_1_1.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 212 | Door_1_2.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 213 | }else if(door_num==2){//扉2 |
mikawataru | 6:15204813ef87 | 214 | Door_2_1.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 215 | Door_2_2.pulsewidth(motion); |
mikawataru | 6:15204813ef87 | 216 | }else{ |
mikawataru | 12:211d2c6d2afc | 217 | device.printf("servo error:%d\r\n",door_num); |
mikawataru | 6:15204813ef87 | 218 | } |
mikawataru | 3:9cd74af355cc | 219 | } |
mikawataru | 7:5f693667d0e9 | 220 | |
mikawataru | 12:211d2c6d2afc | 221 | /*入力用*/ |
mikawataru | 12:211d2c6d2afc | 222 | void _Input(){ |
mikawataru | 12:211d2c6d2afc | 223 | char c = device.getc(); |
mikawataru | 12:211d2c6d2afc | 224 | switch (Input_mode) { |
mikawataru | 12:211d2c6d2afc | 225 | case NORMAL: |
mikawataru | 12:211d2c6d2afc | 226 | if(c=='s'){ |
mikawataru | 12:211d2c6d2afc | 227 | Input_mode = SERVO_1; |
mikawataru | 12:211d2c6d2afc | 228 | device.printf("\r\nInput_mode:SERVO\r\n"); |
mikawataru | 12:211d2c6d2afc | 229 | device.printf("\r\n0:All\r\n1:Parachute\r\n2:Cansat\r\n>>"); |
mikawataru | 12:211d2c6d2afc | 230 | }else{ |
mikawataru | 12:211d2c6d2afc | 231 | device.printf("\r\nthis command is not found:%c\r\n",c); |
mikawataru | 12:211d2c6d2afc | 232 | device.printf("\r\nInput_mode:NORMAL\r\ns:SERVO\r\n"); |
mikawataru | 12:211d2c6d2afc | 233 | } |
mikawataru | 12:211d2c6d2afc | 234 | break; |
mikawataru | 12:211d2c6d2afc | 235 | case SERVO_1: |
mikawataru | 12:211d2c6d2afc | 236 | input_buff[0] = (int)(c-'0'); |
mikawataru | 12:211d2c6d2afc | 237 | if(c=='0'||c=='1'||c=='2'){ |
mikawataru | 12:211d2c6d2afc | 238 | Input_mode = SERVO_2; |
mikawataru | 12:211d2c6d2afc | 239 | device.printf("\r\n0:OPEN\r\n1:CLOSE\r\n>>"); |
mikawataru | 12:211d2c6d2afc | 240 | }else{ |
mikawataru | 12:211d2c6d2afc | 241 | device.printf("\r\nthis servo_num is not found:%d\r\n",input_buff[0]); |
mikawataru | 12:211d2c6d2afc | 242 | device.printf("\r\nInput_mode:NORMAL\r\ns:SERVO\r\n>>"); |
mikawataru | 12:211d2c6d2afc | 243 | Input_mode = NORMAL; |
mikawataru | 12:211d2c6d2afc | 244 | } |
mikawataru | 12:211d2c6d2afc | 245 | break; |
mikawataru | 12:211d2c6d2afc | 246 | case SERVO_2: |
mikawataru | 12:211d2c6d2afc | 247 | if(c=='0')_Servo(input_buff[0],UNLOCK); |
mikawataru | 12:211d2c6d2afc | 248 | else if(c=='1')_Servo(input_buff[0],LOCK); |
mikawataru | 12:211d2c6d2afc | 249 | else{ |
mikawataru | 12:211d2c6d2afc | 250 | device.printf("\r\nthis motion_num is not found:%c\r\n",c); |
mikawataru | 12:211d2c6d2afc | 251 | } |
mikawataru | 12:211d2c6d2afc | 252 | device.printf("Input_mode:NORMAL\r\ns:SERVO\r\n"); |
mikawataru | 12:211d2c6d2afc | 253 | Input_mode = NORMAL; |
mikawataru | 12:211d2c6d2afc | 254 | break; |
mikawataru | 12:211d2c6d2afc | 255 | case MODE: |
mikawataru | 12:211d2c6d2afc | 256 | break; |
mikawataru | 12:211d2c6d2afc | 257 | case BAN://reset only |
mikawataru | 12:211d2c6d2afc | 258 | break; |
mikawataru | 12:211d2c6d2afc | 259 | default: |
mikawataru | 12:211d2c6d2afc | 260 | break; |
mikawataru | 12:211d2c6d2afc | 261 | } |
mikawataru | 12:211d2c6d2afc | 262 | } |
mikawataru | 12:211d2c6d2afc | 263 | |
mikawataru | 12:211d2c6d2afc | 264 | /*その他雑関数*/ |
mikawataru | 11:b61d0fcc2ed3 | 265 | float _GetAlt(float press, float temp){ |
mikawataru | 7:5f693667d0e9 | 266 | return (pow((P0/press), (1.0f/5.257f))-1.0f)*(temp+273.15f)/0.0065f; |
mikawataru | 7:5f693667d0e9 | 267 | } |
mikawataru | 11:b61d0fcc2ed3 | 268 | float _Median(float data[], int num){ |
mikawataru | 11:b61d0fcc2ed3 | 269 | float median; |
mikawataru | 11:b61d0fcc2ed3 | 270 | float *sort = (float *)malloc(sizeof(float)*num); |
mikawataru | 11:b61d0fcc2ed3 | 271 | for(int i=0; i<num; i++) sort[i] = data[i]; |
mikawataru | 11:b61d0fcc2ed3 | 272 | for(int i=0; i<num; i++){ |
mikawataru | 11:b61d0fcc2ed3 | 273 | for(int j=0; j<num-i-1; j++){ |
mikawataru | 11:b61d0fcc2ed3 | 274 | if(sort[j]>sort[j+1]){ |
mikawataru | 11:b61d0fcc2ed3 | 275 | float buff = sort[j+1]; |
mikawataru | 11:b61d0fcc2ed3 | 276 | sort[j+1] = sort[j]; |
mikawataru | 11:b61d0fcc2ed3 | 277 | sort[j] = buff; |
mikawataru | 11:b61d0fcc2ed3 | 278 | } |
mikawataru | 11:b61d0fcc2ed3 | 279 | } |
mikawataru | 11:b61d0fcc2ed3 | 280 | } |
mikawataru | 11:b61d0fcc2ed3 | 281 | if(num%2!=0)median = sort[num/2]; |
mikawataru | 11:b61d0fcc2ed3 | 282 | else median = (sort[num/2-1]+sort[num/2])/2.0; |
mikawataru | 11:b61d0fcc2ed3 | 283 | free(sort); |
mikawataru | 11:b61d0fcc2ed3 | 284 | return median; |
mikawataru | 11:b61d0fcc2ed3 | 285 | } |