ボタンを押すと、 バッテリ更新を停止し、 他のボタンもロックさせる
Dependencies: RemoteIR TextLCD
main.cpp@4:3f80c0180e2f, 2020-07-29 (annotated)
- Committer:
- yangtzuli
- Date:
- Wed Jul 29 03:10:44 2020 +0000
- Revision:
- 4:3f80c0180e2f
- Parent:
- 3:2ae6218973be
- Child:
- 5:3fffb364744b
!"#$%&'()=~
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangtzuli | 0:0d0037aabe41 | 1 | /* mbed Microcontroller Library |
yangtzuli | 0:0d0037aabe41 | 2 | * Copyright (c) 2019 ARM Limited |
yangtzuli | 0:0d0037aabe41 | 3 | * SPDX-License-Identifier: Apache-2.0 |
yangtzuli | 0:0d0037aabe41 | 4 | */ |
yangtzuli | 0:0d0037aabe41 | 5 | |
yangtzuli | 0:0d0037aabe41 | 6 | #include "mbed.h" |
yangtzuli | 0:0d0037aabe41 | 7 | #include "ReceiverIR.h" |
yangtzuli | 0:0d0037aabe41 | 8 | #include "rtos.h" |
yangtzuli | 0:0d0037aabe41 | 9 | #include <stdint.h> |
yangtzuli | 0:0d0037aabe41 | 10 | #include "platform/mbed_thread.h" |
yangtzuli | 2:38825726cb1b | 11 | #include "TextLCD.h" |
yangtzuli | 0:0d0037aabe41 | 12 | |
yangtzuli | 0:0d0037aabe41 | 13 | Serial pc(USBTX, USBRX); |
yangtzuli | 0:0d0037aabe41 | 14 | |
yangtzuli | 3:2ae6218973be | 15 | /* マクロ定義、列挙型定義 */ |
yangtzuli | 3:2ae6218973be | 16 | #define MIN_V 2.0 |
yangtzuli | 3:2ae6218973be | 17 | #define MAX_V 2.67 |
yangtzuli | 3:2ae6218973be | 18 | #define LOW 0 // |
yangtzuli | 3:2ae6218973be | 19 | #define HIGH 1 // |
yangtzuli | 3:2ae6218973be | 20 | #define NORMAL 0 // フラグ値 |
yangtzuli | 3:2ae6218973be | 21 | #define FAST 1 // フラグ値 |
yangtzuli | 3:2ae6218973be | 22 | #define VERYFAST 2 // フラグ値 |
yangtzuli | 2:38825726cb1b | 23 | |
yangtzuli | 3:2ae6218973be | 24 | enum MODE{ |
yangtzuli | 3:2ae6218973be | 25 | READY = -1, |
yangtzuli | 3:2ae6218973be | 26 | ADVANCE = 1, |
yangtzuli | 2:38825726cb1b | 27 | RIGHT, |
yangtzuli | 2:38825726cb1b | 28 | LEFT, |
yangtzuli | 2:38825726cb1b | 29 | BACK, |
yangtzuli | 2:38825726cb1b | 30 | STOP, |
yangtzuli | 2:38825726cb1b | 31 | LINE_TRACE, |
yangtzuli | 2:38825726cb1b | 32 | AVOIDANCE, |
yangtzuli | 3:2ae6218973be | 33 | SPEED, |
yangtzuli | 2:38825726cb1b | 34 | }; |
yangtzuli | 2:38825726cb1b | 35 | |
yangtzuli | 3:2ae6218973be | 36 | /* ピン配置 */ |
yangtzuli | 3:2ae6218973be | 37 | ReceiverIR ir(p5); // リモコン操作 |
yangtzuli | 3:2ae6218973be | 38 | DigitalOut trig(p6); // 超音波センサtrigger |
yangtzuli | 3:2ae6218973be | 39 | DigitalOut echo(p7); // 超音波センサecho |
yangtzuli | 3:2ae6218973be | 40 | DigitalIn ss1(p8); // ライントレースセンサ(左) |
yangtzuli | 3:2ae6218973be | 41 | DigitalIn ss2(p9); // ライントレースセンサ |
yangtzuli | 3:2ae6218973be | 42 | DigitalIn ss3(p10); // ライントレースセンサ |
yangtzuli | 3:2ae6218973be | 43 | DigitalIn ss4(p11); // ライントレースセンサ |
yangtzuli | 3:2ae6218973be | 44 | DigitalIn ss5(p12); // ライントレースセンサ(右) |
yangtzuli | 3:2ae6218973be | 45 | Serial esp(p13, p14); // Wi-Fiモジュール(tx, rx) |
yangtzuli | 3:2ae6218973be | 46 | AnalogIn battery(p15); // 電池残量読み取り(Max 3.3V) |
yangtzuli | 3:2ae6218973be | 47 | PwmOut motorR2(p21); // 右モーター後退 |
yangtzuli | 3:2ae6218973be | 48 | PwmOut motorR1(p22); // 右モーター前進 |
yangtzuli | 3:2ae6218973be | 49 | PwmOut motorL2(p23); // 左モーター後退 |
yangtzuli | 3:2ae6218973be | 50 | PwmOut motorL1(p24); // 左モーター前進 |
yangtzuli | 3:2ae6218973be | 51 | PwmOut servo(p25); // サーボ |
yangtzuli | 3:2ae6218973be | 52 | I2C i2c_lcd(p28,p27); // LCD(tx, rx) |
yangtzuli | 2:38825726cb1b | 53 | |
yangtzuli | 3:2ae6218973be | 54 | /* 変数宣言 */ |
yangtzuli | 3:2ae6218973be | 55 | int mode; // 操作モード |
yangtzuli | 3:2ae6218973be | 56 | int run; // 走行状態 |
yangtzuli | 3:2ae6218973be | 57 | int beforeMode; // 前のモード |
yangtzuli | 3:2ae6218973be | 58 | int flag_sp = 0; // スピード変化フラグ |
yangtzuli | 3:2ae6218973be | 59 | Timer viewTimer; // スピ―ド変更時に3秒計測 |
yangtzuli | 3:2ae6218973be | 60 | float motorSpeed[6] = {0.7, 0.8, 0.9, 0.8, 0.9, 1.0}; |
yangtzuli | 3:2ae6218973be | 61 | // モーター速度設定(後半はライントレース用) |
yangtzuli | 3:2ae6218973be | 62 | Mutex mutex; |
yangtzuli | 3:2ae6218973be | 63 | // ポートp15を赤外線受信モジュールの接続先に指定 |
yangtzuli | 3:2ae6218973be | 64 | RemoteIR::Format format; |
yangtzuli | 3:2ae6218973be | 65 | uint8_t buf[32]; |
yangtzuli | 3:2ae6218973be | 66 | uint32_t bitcount; |
yangtzuli | 3:2ae6218973be | 67 | uint32_t code; |
yangtzuli | 3:2ae6218973be | 68 | |
yangtzuli | 3:2ae6218973be | 69 | //bChangeのいろいろ |
yangtzuli | 3:2ae6218973be | 70 | TextLCD_I2C lcd(&i2c_lcd, (0x27 << 1), TextLCD::LCD16x2, TextLCD::HD44780); |
yangtzuli | 3:2ae6218973be | 71 | int b = 0; |
yangtzuli | 3:2ae6218973be | 72 | double test; |
yangtzuli | 3:2ae6218973be | 73 | int flag_b = 0; |
yangtzuli | 3:2ae6218973be | 74 | int flag_t = 0; |
yangtzuli | 3:2ae6218973be | 75 | |
yangtzuli | 3:2ae6218973be | 76 | // ライントレース |
yangtzuli | 3:2ae6218973be | 77 | int sensArray[32] = {0,0,0,0,0,0,0,0, // ライントレースセンサパターン |
yangtzuli | 3:2ae6218973be | 78 | 0,0,0,0,0,0,0,0, |
yangtzuli | 3:2ae6218973be | 79 | 0,0,0,0,0,0,0,0, |
yangtzuli | 3:2ae6218973be | 80 | 0,0,0,0,0,0,0,0}; |
yangtzuli | 0:0d0037aabe41 | 81 | |
yangtzuli | 2:38825726cb1b | 82 | /* 障害物検知用の変数設定 */ |
yangtzuli | 3:2ae6218973be | 83 | Timer timer; // 距離計測用タイマ |
yangtzuli | 3:2ae6218973be | 84 | int DT; // 距離 |
yangtzuli | 2:38825726cb1b | 85 | int SC; // 正面 |
yangtzuli | 2:38825726cb1b | 86 | int SL; // 左 |
yangtzuli | 2:38825726cb1b | 87 | int SR; // 右 |
yangtzuli | 2:38825726cb1b | 88 | int SLD; // 左前 |
yangtzuli | 2:38825726cb1b | 89 | int SRD; // 右前 |
yangtzuli | 2:38825726cb1b | 90 | int flag = 0; // 障害物有無のフラグ |
yangtzuli | 2:38825726cb1b | 91 | const int limit = 20; // 障害物の距離のリミット(単位:cm) |
yangtzuli | 3:2ae6218973be | 92 | int far; // 最も遠い距離 |
yangtzuli | 2:38825726cb1b | 93 | int houkou; // 進行方向(1:前 2:左 3:右) |
yangtzuli | 2:38825726cb1b | 94 | int i; // ループ変数 |
yangtzuli | 2:38825726cb1b | 95 | |
yangtzuli | 3:2ae6218973be | 96 | |
yangtzuli | 3:2ae6218973be | 97 | |
yangtzuli | 3:2ae6218973be | 98 | /* プロトタイプ宣言 */ |
yangtzuli | 3:2ae6218973be | 99 | void decodeIR(void const *argument); |
yangtzuli | 3:2ae6218973be | 100 | void motor(void const *argument); |
yangtzuli | 3:2ae6218973be | 101 | void changeSpeed(); |
yangtzuli | 2:38825726cb1b | 102 | void avoidance(void const *argument); |
yangtzuli | 3:2ae6218973be | 103 | void trace(void const *argument); |
yangtzuli | 2:38825726cb1b | 104 | void watchsurrounding(); |
yangtzuli | 2:38825726cb1b | 105 | int watch(); |
yangtzuli | 4:3f80c0180e2f | 106 | void bChange(/*void const *argument*/); |
yangtzuli | 3:2ae6218973be | 107 | void display(); |
yangtzuli | 3:2ae6218973be | 108 | void lcdBacklight(void const *argument); |
yangtzuli | 4:3f80c0180e2f | 109 | Thread thread1(decodeIR, NULL, osPriorityRealtime);//+3 |
yangtzuli | 4:3f80c0180e2f | 110 | Thread thread2(motor, NULL, osPriorityHigh);//+2 |
yangtzuli | 4:3f80c0180e2f | 111 | Thread thread3(avoidance, NULL, osPriorityHigh);//+2 |
yangtzuli | 4:3f80c0180e2f | 112 | Thread thread4(trace, NULL, osPriorityHigh);//+2 |
yangtzuli | 4:3f80c0180e2f | 113 | //Thread thread5(bChange, NULL, osPriorityBelowNormal);//-1 |
yangtzuli | 3:2ae6218973be | 114 | RtosTimer bTimer(lcdBacklight, osTimerPeriodic); |
yangtzuli | 2:38825726cb1b | 115 | |
yangtzuli | 3:2ae6218973be | 116 | |
yangtzuli | 4:3f80c0180e2f | 117 | void decodeIR(void const *argument){ |
yangtzuli | 4:3f80c0180e2f | 118 | while(1){ |
yangtzuli | 0:0d0037aabe41 | 119 | // 受信待ち |
yangtzuli | 4:3f80c0180e2f | 120 | pc.printf("decodeIR\r\n"); |
yangtzuli | 3:2ae6218973be | 121 | if (ir.getState() == ReceiverIR::Received) { |
yangtzuli | 0:0d0037aabe41 | 122 | // コード受信 |
yangtzuli | 3:2ae6218973be | 123 | bitcount = ir.getData(&format, buf, sizeof(buf) * 8); |
yangtzuli | 0:0d0037aabe41 | 124 | if(bitcount > 1){ |
yangtzuli | 0:0d0037aabe41 | 125 | // 受信成功 |
yangtzuli | 1:5bb497a38344 | 126 | code=0; |
yangtzuli | 1:5bb497a38344 | 127 | for(int j=0;j<4;j++){ |
yangtzuli | 1:5bb497a38344 | 128 | code+=(buf[j]<<(8*(3-j))); |
yangtzuli | 1:5bb497a38344 | 129 | } |
yangtzuli | 3:2ae6218973be | 130 | if(mode!=SPEED){ |
yangtzuli | 3:2ae6218973be | 131 | beforeMode=mode; |
yangtzuli | 3:2ae6218973be | 132 | } |
yangtzuli | 3:2ae6218973be | 133 | |
yangtzuli | 3:2ae6218973be | 134 | //pc.printf("%0x\r\n",code); |
yangtzuli | 0:0d0037aabe41 | 135 | switch(code){ |
yangtzuli | 1:5bb497a38344 | 136 | case 0x40bf27d8://クイック |
yangtzuli | 3:2ae6218973be | 137 | pc.printf("mode = SPEED\r\n"); |
yangtzuli | 3:2ae6218973be | 138 | mode = SPEED; |
yangtzuli | 4:3f80c0180e2f | 139 | changeSpeed(); |
yangtzuli | 4:3f80c0180e2f | 140 | display(); |
yangtzuli | 4:3f80c0180e2f | 141 | mode = beforeMode; |
yangtzuli | 1:5bb497a38344 | 142 | break; |
yangtzuli | 1:5bb497a38344 | 143 | case 0x40be34cb://レグザリンク |
yangtzuli | 3:2ae6218973be | 144 | pc.printf("mode = INE_TRACE\r\n"); |
yangtzuli | 3:2ae6218973be | 145 | mode=LINE_TRACE; |
yangtzuli | 3:2ae6218973be | 146 | display(); |
yangtzuli | 1:5bb497a38344 | 147 | break; |
yangtzuli | 1:5bb497a38344 | 148 | case 0x40bf6e91://番組表 |
yangtzuli | 3:2ae6218973be | 149 | pc.printf("mode = AVOIDANCE\r\n"); |
yangtzuli | 3:2ae6218973be | 150 | mode=AVOIDANCE; |
yangtzuli | 3:2ae6218973be | 151 | display(); |
yangtzuli | 1:5bb497a38344 | 152 | break; |
yangtzuli | 1:5bb497a38344 | 153 | case 0x40bf3ec1://↑ |
yangtzuli | 3:2ae6218973be | 154 | pc.printf("mode = ADVANCE\r\n"); |
yangtzuli | 3:2ae6218973be | 155 | mode = ADVANCE; |
yangtzuli | 3:2ae6218973be | 156 | run = ADVANCE; |
yangtzuli | 3:2ae6218973be | 157 | display(); |
yangtzuli | 1:5bb497a38344 | 158 | break; |
yangtzuli | 1:5bb497a38344 | 159 | case 0x40bf3fc0://↓ |
yangtzuli | 3:2ae6218973be | 160 | pc.printf("mode = BACK\r\n"); |
yangtzuli | 3:2ae6218973be | 161 | mode = BACK; |
yangtzuli | 3:2ae6218973be | 162 | run = BACK; |
yangtzuli | 3:2ae6218973be | 163 | display(); |
yangtzuli | 0:0d0037aabe41 | 164 | break; |
yangtzuli | 1:5bb497a38344 | 165 | case 0x40bf5fa0://← |
yangtzuli | 3:2ae6218973be | 166 | pc.printf("mode = LEFT\r\n"); |
yangtzuli | 3:2ae6218973be | 167 | mode = LEFT; |
yangtzuli | 3:2ae6218973be | 168 | run = LEFT; |
yangtzuli | 3:2ae6218973be | 169 | display(); |
yangtzuli | 1:5bb497a38344 | 170 | break; |
yangtzuli | 1:5bb497a38344 | 171 | case 0x40bf5ba4://→ |
yangtzuli | 3:2ae6218973be | 172 | pc.printf("mode = RIGHT\r\n"); |
yangtzuli | 3:2ae6218973be | 173 | mode = RIGHT; |
yangtzuli | 3:2ae6218973be | 174 | run = RIGHT; |
yangtzuli | 3:2ae6218973be | 175 | display(); |
yangtzuli | 1:5bb497a38344 | 176 | break; |
yangtzuli | 1:5bb497a38344 | 177 | case 0x40bf3dc2://決定 |
yangtzuli | 3:2ae6218973be | 178 | pc.printf("mode = STOP\r\n"); |
yangtzuli | 3:2ae6218973be | 179 | mode = STOP; |
yangtzuli | 3:2ae6218973be | 180 | run = STOP; |
yangtzuli | 3:2ae6218973be | 181 | display(); |
yangtzuli | 1:5bb497a38344 | 182 | break; |
yangtzuli | 0:0d0037aabe41 | 183 | default: |
yangtzuli | 0:0d0037aabe41 | 184 | ; |
yangtzuli | 0:0d0037aabe41 | 185 | } |
yangtzuli | 0:0d0037aabe41 | 186 | } |
yangtzuli | 0:0d0037aabe41 | 187 | } |
yangtzuli | 4:3f80c0180e2f | 188 | if(viewTimer.read_ms()>=3000){ |
yangtzuli | 4:3f80c0180e2f | 189 | //pc.printf("a"); |
yangtzuli | 4:3f80c0180e2f | 190 | viewTimer.stop(); |
yangtzuli | 4:3f80c0180e2f | 191 | //defaultView(); |
yangtzuli | 4:3f80c0180e2f | 192 | viewTimer.reset(); |
yangtzuli | 4:3f80c0180e2f | 193 | display(); |
yangtzuli | 4:3f80c0180e2f | 194 | //flaga=0; |
yangtzuli | 4:3f80c0180e2f | 195 | } |
yangtzuli | 4:3f80c0180e2f | 196 | //pc.printf(" main2\r\n"); |
yangtzuli | 4:3f80c0180e2f | 197 | //if(viewTimer.read_ms()==0){ |
yangtzuli | 4:3f80c0180e2f | 198 | // display(); |
yangtzuli | 4:3f80c0180e2f | 199 | //} |
yangtzuli | 4:3f80c0180e2f | 200 | ThisThread::sleep_for(90); |
yangtzuli | 4:3f80c0180e2f | 201 | } |
yangtzuli | 2:38825726cb1b | 202 | } |
yangtzuli | 2:38825726cb1b | 203 | void motor(void const *argument){ |
yangtzuli | 3:2ae6218973be | 204 | while(true){ |
yangtzuli | 3:2ae6218973be | 205 | pc.printf("motor\r\n"); |
yangtzuli | 3:2ae6218973be | 206 | if(flag_sp >VERYFAST){ |
yangtzuli | 3:2ae6218973be | 207 | flag_sp -= 3; |
yangtzuli | 3:2ae6218973be | 208 | } |
yangtzuli | 3:2ae6218973be | 209 | switch(run){ |
yangtzuli | 3:2ae6218973be | 210 | case ADVANCE: |
yangtzuli | 3:2ae6218973be | 211 | motorR1 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 212 | motorR2 = LOW; |
yangtzuli | 3:2ae6218973be | 213 | motorL1 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 214 | motorL2 = LOW; |
yangtzuli | 3:2ae6218973be | 215 | break; |
yangtzuli | 3:2ae6218973be | 216 | case RIGHT: |
yangtzuli | 3:2ae6218973be | 217 | motorR1 = LOW; |
yangtzuli | 3:2ae6218973be | 218 | motorR2 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 219 | motorL1 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 220 | motorL2 = LOW; |
yangtzuli | 3:2ae6218973be | 221 | break; |
yangtzuli | 3:2ae6218973be | 222 | case LEFT: |
yangtzuli | 3:2ae6218973be | 223 | motorR1 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 224 | motorR2 = LOW; |
yangtzuli | 3:2ae6218973be | 225 | motorL1 = LOW; |
yangtzuli | 3:2ae6218973be | 226 | motorL2 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 227 | break; |
yangtzuli | 3:2ae6218973be | 228 | case BACK: |
yangtzuli | 3:2ae6218973be | 229 | motorR1 = LOW; |
yangtzuli | 3:2ae6218973be | 230 | motorR2 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 231 | motorL1 = LOW; |
yangtzuli | 3:2ae6218973be | 232 | motorL2 = motorSpeed[flag_sp]; |
yangtzuli | 3:2ae6218973be | 233 | break; |
yangtzuli | 3:2ae6218973be | 234 | case STOP: |
yangtzuli | 3:2ae6218973be | 235 | motorR1 = LOW; |
yangtzuli | 3:2ae6218973be | 236 | motorR2 = LOW; |
yangtzuli | 3:2ae6218973be | 237 | motorL1 = LOW; |
yangtzuli | 3:2ae6218973be | 238 | motorL2 = LOW; |
yangtzuli | 3:2ae6218973be | 239 | break; |
yangtzuli | 3:2ae6218973be | 240 | } |
yangtzuli | 3:2ae6218973be | 241 | pc.printf(" motor\r\n"); |
yangtzuli | 4:3f80c0180e2f | 242 | ThisThread::sleep_for(30); |
yangtzuli | 2:38825726cb1b | 243 | } |
yangtzuli | 2:38825726cb1b | 244 | } |
yangtzuli | 3:2ae6218973be | 245 | void changeSpeed(){ |
yangtzuli | 3:2ae6218973be | 246 | if(flag_sp == VERYFAST){ |
yangtzuli | 3:2ae6218973be | 247 | flag_sp = NORMAL; |
yangtzuli | 3:2ae6218973be | 248 | |
yangtzuli | 3:2ae6218973be | 249 | }else{ |
yangtzuli | 3:2ae6218973be | 250 | flag_sp = flag_sp + 1; |
yangtzuli | 3:2ae6218973be | 251 | } |
yangtzuli | 3:2ae6218973be | 252 | } |
yangtzuli | 3:2ae6218973be | 253 | void trace(void const *argument){ |
yangtzuli | 3:2ae6218973be | 254 | while(true){ |
yangtzuli | 3:2ae6218973be | 255 | if(mode==LINE_TRACE){ |
yangtzuli | 3:2ae6218973be | 256 | pc.printf("line trace\r\n"); |
yangtzuli | 3:2ae6218973be | 257 | // センサー値読み取り |
yangtzuli | 3:2ae6218973be | 258 | int sensor1 = ss1; |
yangtzuli | 3:2ae6218973be | 259 | int sensor2 = ss2; |
yangtzuli | 3:2ae6218973be | 260 | int sensor3 = ss3; |
yangtzuli | 3:2ae6218973be | 261 | int sensor4 = ss4; |
yangtzuli | 3:2ae6218973be | 262 | int sensor5 = ss5; |
yangtzuli | 3:2ae6218973be | 263 | |
yangtzuli | 3:2ae6218973be | 264 | int sensD = 0; |
yangtzuli | 3:2ae6218973be | 265 | int sensorNum; |
yangtzuli | 3:2ae6218973be | 266 | |
yangtzuli | 3:2ae6218973be | 267 | if(sensor1 > 0) sensD |= 0x10; |
yangtzuli | 3:2ae6218973be | 268 | if(sensor2 > 0) sensD |= 0x08; |
yangtzuli | 3:2ae6218973be | 269 | if(sensor3 > 0) sensD |= 0x04; |
yangtzuli | 3:2ae6218973be | 270 | if(sensor4 > 0) sensD |= 0x02; |
yangtzuli | 3:2ae6218973be | 271 | if(sensor5 > 0) sensD |= 0x01; |
yangtzuli | 3:2ae6218973be | 272 | |
yangtzuli | 3:2ae6218973be | 273 | sensorNum = sensArray[sensD]; |
yangtzuli | 3:2ae6218973be | 274 | |
yangtzuli | 3:2ae6218973be | 275 | switch(sensorNum){ |
yangtzuli | 3:2ae6218973be | 276 | case 1: |
yangtzuli | 3:2ae6218973be | 277 | run = ADVANCE; |
yangtzuli | 3:2ae6218973be | 278 | break; |
yangtzuli | 3:2ae6218973be | 279 | case 2: |
yangtzuli | 3:2ae6218973be | 280 | run = RIGHT; |
yangtzuli | 3:2ae6218973be | 281 | break; |
yangtzuli | 3:2ae6218973be | 282 | case 3: |
yangtzuli | 3:2ae6218973be | 283 | run = LEFT; |
yangtzuli | 3:2ae6218973be | 284 | break; |
yangtzuli | 3:2ae6218973be | 285 | case 4: |
yangtzuli | 3:2ae6218973be | 286 | flag_sp += 3; |
yangtzuli | 3:2ae6218973be | 287 | run = RIGHT; |
yangtzuli | 3:2ae6218973be | 288 | break; |
yangtzuli | 3:2ae6218973be | 289 | case 5: |
yangtzuli | 3:2ae6218973be | 290 | flag_sp += 3; |
yangtzuli | 3:2ae6218973be | 291 | run = LEFT; |
yangtzuli | 3:2ae6218973be | 292 | break; |
yangtzuli | 3:2ae6218973be | 293 | } |
yangtzuli | 3:2ae6218973be | 294 | pc.printf(" line trace\r\n"); |
yangtzuli | 4:3f80c0180e2f | 295 | ThisThread::sleep_for(30); |
yangtzuli | 3:2ae6218973be | 296 | }else{ |
yangtzuli | 4:3f80c0180e2f | 297 | ThisThread::sleep_for(1); |
yangtzuli | 3:2ae6218973be | 298 | } |
yangtzuli | 3:2ae6218973be | 299 | } |
yangtzuli | 3:2ae6218973be | 300 | } |
yangtzuli | 3:2ae6218973be | 301 | |
yangtzuli | 2:38825726cb1b | 302 | /* 障害物回避走行 */ |
yangtzuli | 2:38825726cb1b | 303 | void avoidance(void const *argument){ |
yangtzuli | 3:2ae6218973be | 304 | while(1){ |
yangtzuli | 3:2ae6218973be | 305 | if(mode==AVOIDANCE){ |
yangtzuli | 3:2ae6218973be | 306 | pc.printf("avoidance\r\n"); |
yangtzuli | 3:2ae6218973be | 307 | if(flag == 0){ // 障害物がない場合 |
yangtzuli | 3:2ae6218973be | 308 | run = ADVANCE; // 前進 |
yangtzuli | 3:2ae6218973be | 309 | } |
yangtzuli | 3:2ae6218973be | 310 | /*else{ // 障害物がある場合 |
yangtzuli | 3:2ae6218973be | 311 | i = 0; |
yangtzuli | 3:2ae6218973be | 312 | if(SC < 15){ // 正面15cm以内に障害物が現れた場合 |
yangtzuli | 3:2ae6218973be | 313 | run = BACK; // 後退 |
yangtzuli | 3:2ae6218973be | 314 | while(watch() < limit){ // 正面20cm以内に障害物がある間 |
yangtzuli | 2:38825726cb1b | 315 | |
yangtzuli | 3:2ae6218973be | 316 | } |
yangtzuli | 3:2ae6218973be | 317 | run = STOP; // 停止 |
yangtzuli | 2:38825726cb1b | 318 | } |
yangtzuli | 3:2ae6218973be | 319 | if(SC < limit && SLD < limit && SL < limit && SRD < limit && SR < limit){ // 全方向に障害物がある場合 |
yangtzuli | 3:2ae6218973be | 320 | run = LEFT; // 左折 |
yangtzuli | 3:2ae6218973be | 321 | while(i < 100){ // 進行方向確認 |
yangtzuli | 3:2ae6218973be | 322 | if(watch() > limit){ |
yangtzuli | 3:2ae6218973be | 323 | i++; |
yangtzuli | 3:2ae6218973be | 324 | } |
yangtzuli | 3:2ae6218973be | 325 | else{ |
yangtzuli | 3:2ae6218973be | 326 | i = 0; |
yangtzuli | 3:2ae6218973be | 327 | } |
yangtzuli | 3:2ae6218973be | 328 | } |
yangtzuli | 3:2ae6218973be | 329 | run = STOP; // 停止 |
yangtzuli | 3:2ae6218973be | 330 | } |
yangtzuli | 3:2ae6218973be | 331 | else { // 全方向以外 |
yangtzuli | 3:2ae6218973be | 332 | far = SC; // 正面を最も遠い距離に設定 |
yangtzuli | 3:2ae6218973be | 333 | houkou = 1; // 進行方向を前に設定 |
yangtzuli | 3:2ae6218973be | 334 | if(far < SLD || far < SL){ // 左または左前がより遠い場合 |
yangtzuli | 3:2ae6218973be | 335 | if(SL < SLD){ // 左前が左より遠い場合 |
yangtzuli | 3:2ae6218973be | 336 | far = SLD; // 左前を最も遠い距離に設定 |
yangtzuli | 3:2ae6218973be | 337 | } |
yangtzuli | 3:2ae6218973be | 338 | else{ // 左が左前より遠い場合 |
yangtzuli | 3:2ae6218973be | 339 | far = SL; // 左を最も遠い距離に設定 |
yangtzuli | 3:2ae6218973be | 340 | } |
yangtzuli | 3:2ae6218973be | 341 | houkou = 2; // 進行方向を左に設定 |
yangtzuli | 2:38825726cb1b | 342 | } |
yangtzuli | 3:2ae6218973be | 343 | if(far < SRD || far < SR){ // 右または右前がより遠い場合 |
yangtzuli | 3:2ae6218973be | 344 | if(SR < SRD){ // 右前が右より遠い場合 |
yangtzuli | 3:2ae6218973be | 345 | far = SRD; // 右前を最も遠い距離に設定 |
yangtzuli | 3:2ae6218973be | 346 | } |
yangtzuli | 3:2ae6218973be | 347 | else{ // 右が右前よりも遠い場合 |
yangtzuli | 3:2ae6218973be | 348 | far = SR; // 右を最も遠い距離に設定 |
yangtzuli | 3:2ae6218973be | 349 | } |
yangtzuli | 3:2ae6218973be | 350 | houkou = 3; // 進行方向を右に設定 |
yangtzuli | 3:2ae6218973be | 351 | } |
yangtzuli | 3:2ae6218973be | 352 | switch(houkou){ // 進行方向の場合分け |
yangtzuli | 3:2ae6218973be | 353 | case 1: // 前の場合 |
yangtzuli | 3:2ae6218973be | 354 | run = ADVANCE; // 前進 |
yangtzuli | 3:2ae6218973be | 355 | thread_sleep_for(100); // 1秒待つ |
yangtzuli | 3:2ae6218973be | 356 | break; |
yangtzuli | 3:2ae6218973be | 357 | case 2: // 左の場合 |
yangtzuli | 3:2ae6218973be | 358 | run = LEFT; // 左折 |
yangtzuli | 3:2ae6218973be | 359 | while(i < 100){ // 進行方向確認 |
yangtzuli | 3:2ae6218973be | 360 | if(watch() > (far - 2)){ |
yangtzuli | 3:2ae6218973be | 361 | i++; |
yangtzuli | 3:2ae6218973be | 362 | } |
yangtzuli | 3:2ae6218973be | 363 | else{ |
yangtzuli | 3:2ae6218973be | 364 | i = 0; |
yangtzuli | 3:2ae6218973be | 365 | } |
yangtzuli | 3:2ae6218973be | 366 | } |
yangtzuli | 3:2ae6218973be | 367 | run = STOP; // 停止 |
yangtzuli | 3:2ae6218973be | 368 | break; |
yangtzuli | 3:2ae6218973be | 369 | case 3: // 右の場合 |
yangtzuli | 3:2ae6218973be | 370 | run = RIGHT; // 右折 |
yangtzuli | 3:2ae6218973be | 371 | while(i < 100){ // 進行方向確認 |
yangtzuli | 3:2ae6218973be | 372 | if(watch() > (far - 2)){ |
yangtzuli | 3:2ae6218973be | 373 | i++; |
yangtzuli | 3:2ae6218973be | 374 | } |
yangtzuli | 3:2ae6218973be | 375 | else{ |
yangtzuli | 3:2ae6218973be | 376 | i = 0; |
yangtzuli | 3:2ae6218973be | 377 | } |
yangtzuli | 3:2ae6218973be | 378 | } |
yangtzuli | 3:2ae6218973be | 379 | run = STOP; // 停止 |
yangtzuli | 3:2ae6218973be | 380 | break; |
yangtzuli | 2:38825726cb1b | 381 | } |
yangtzuli | 2:38825726cb1b | 382 | } |
yangtzuli | 3:2ae6218973be | 383 | }*/ |
yangtzuli | 3:2ae6218973be | 384 | flag = 0; // フラグを0にセット |
yangtzuli | 3:2ae6218973be | 385 | watchsurrounding(); |
yangtzuli | 3:2ae6218973be | 386 | pc.printf(" avoidance\r\n"); |
yangtzuli | 3:2ae6218973be | 387 | }else{ |
yangtzuli | 4:3f80c0180e2f | 388 | ThisThread::sleep_for(1); |
yangtzuli | 3:2ae6218973be | 389 | } |
yangtzuli | 2:38825726cb1b | 390 | } |
yangtzuli | 2:38825726cb1b | 391 | } |
yangtzuli | 2:38825726cb1b | 392 | int watch(){ |
yangtzuli | 2:38825726cb1b | 393 | pc.printf("watch\r\n"); |
yangtzuli | 2:38825726cb1b | 394 | trig = 0; |
yangtzuli | 2:38825726cb1b | 395 | ThisThread::sleep_for(5); // 5ms待つ |
yangtzuli | 2:38825726cb1b | 396 | trig = 1; |
yangtzuli | 2:38825726cb1b | 397 | ThisThread::sleep_for(15); // 15ms待つ |
yangtzuli | 2:38825726cb1b | 398 | trig = 0; |
yangtzuli | 2:38825726cb1b | 399 | //while(echo.read() == 0){ |
yangtzuli | 2:38825726cb1b | 400 | //} |
yangtzuli | 2:38825726cb1b | 401 | timer.start(); // 距離計測タイマースタート |
yangtzuli | 2:38825726cb1b | 402 | while(echo.read() == 1){ |
yangtzuli | 2:38825726cb1b | 403 | } |
yangtzuli | 2:38825726cb1b | 404 | timer.stop(); // 距離計測タイマーストップ |
yangtzuli | 2:38825726cb1b | 405 | DT = timer.read_us()*0.01657; // 距離計算 |
yangtzuli | 2:38825726cb1b | 406 | if(DT > 400){ // 検知範囲外なら400cmに設定 |
yangtzuli | 2:38825726cb1b | 407 | DT = 400; |
yangtzuli | 2:38825726cb1b | 408 | } |
yangtzuli | 2:38825726cb1b | 409 | timer.reset(); // 距離計測タイマーリセット |
yangtzuli | 3:2ae6218973be | 410 | //ThisThread::sleep_for(30); // 30ms待つ |
yangtzuli | 3:2ae6218973be | 411 | pc.printf(" watch\r\n"); |
yangtzuli | 2:38825726cb1b | 412 | return DT; |
yangtzuli | 0:0d0037aabe41 | 413 | } |
yangtzuli | 0:0d0037aabe41 | 414 | |
yangtzuli | 2:38825726cb1b | 415 | void watchsurrounding(){ |
yangtzuli | 2:38825726cb1b | 416 | pc.printf("watchsurrounding\r\n"); |
yangtzuli | 2:38825726cb1b | 417 | SC = watch(); |
yangtzuli | 2:38825726cb1b | 418 | if(SC < limit){ // 正面20cm以内に障害物がある場合 |
yangtzuli | 2:38825726cb1b | 419 | run = STOP; // 停止 |
yangtzuli | 2:38825726cb1b | 420 | } |
yangtzuli | 2:38825726cb1b | 421 | servo.pulsewidth_us(1925); // サーボを左に40度回転 |
yangtzuli | 2:38825726cb1b | 422 | ThisThread::sleep_for(250); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 423 | SLD = watch(); |
yangtzuli | 2:38825726cb1b | 424 | if(SLD < limit){ // 左前20cm以内に障害物がある場合 |
yangtzuli | 2:38825726cb1b | 425 | run = STOP; // 停止 |
yangtzuli | 2:38825726cb1b | 426 | } |
yangtzuli | 2:38825726cb1b | 427 | servo.pulsewidth_us(2400); // サーボを左に90度回転 |
yangtzuli | 2:38825726cb1b | 428 | ThisThread::sleep_for(250); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 429 | SL = watch(); |
yangtzuli | 2:38825726cb1b | 430 | if(SL < limit){ // 左20cm以内に障害物がある場合 |
yangtzuli | 2:38825726cb1b | 431 | run = STOP; // 停止 |
yangtzuli | 2:38825726cb1b | 432 | } |
yangtzuli | 2:38825726cb1b | 433 | servo.pulsewidth_us(1450); |
yangtzuli | 2:38825726cb1b | 434 | ThisThread::sleep_for(100); |
yangtzuli | 2:38825726cb1b | 435 | servo.pulsewidth_us(925); // サーボを右に40度回転 |
yangtzuli | 2:38825726cb1b | 436 | ThisThread::sleep_for(250); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 437 | SRD = watch(); |
yangtzuli | 2:38825726cb1b | 438 | if(SRD < limit){ // 右前20cm以内に障害物がある場合 |
yangtzuli | 2:38825726cb1b | 439 | run = STOP; // 停止 |
yangtzuli | 2:38825726cb1b | 440 | } |
yangtzuli | 2:38825726cb1b | 441 | servo.pulsewidth_us(500); // サーボを右に90度回転 |
yangtzuli | 2:38825726cb1b | 442 | ThisThread::sleep_for(250); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 443 | SR = watch(); |
yangtzuli | 2:38825726cb1b | 444 | if(SR < limit){ // 右20cm以内に障害物がある場合 |
yangtzuli | 2:38825726cb1b | 445 | run = STOP; // 停止 |
yangtzuli | 2:38825726cb1b | 446 | } |
yangtzuli | 2:38825726cb1b | 447 | servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
yangtzuli | 2:38825726cb1b | 448 | ThisThread::sleep_for(100); // 100ms待つ |
yangtzuli | 2:38825726cb1b | 449 | if(SC < limit || SLD < limit || SL < limit || SRD < limit || SR < limit){ // 20cm以内に障害物を検知した場合 |
yangtzuli | 2:38825726cb1b | 450 | flag = 1; // フラグに1をセット |
yangtzuli | 2:38825726cb1b | 451 | } |
yangtzuli | 3:2ae6218973be | 452 | pc.printf(" watchsurrounding\r\n"); |
yangtzuli | 3:2ae6218973be | 453 | } |
yangtzuli | 3:2ae6218973be | 454 | |
yangtzuli | 3:2ae6218973be | 455 | void defaultView(){ |
yangtzuli | 3:2ae6218973be | 456 | lcd.setAddress(0,0); |
yangtzuli | 3:2ae6218973be | 457 | lcd.printf("Battery:"); |
yangtzuli | 3:2ae6218973be | 458 | lcd.setAddress(0,1); |
yangtzuli | 3:2ae6218973be | 459 | lcd.printf("Mode:"); |
yangtzuli | 2:38825726cb1b | 460 | } |
yangtzuli | 2:38825726cb1b | 461 | |
yangtzuli | 3:2ae6218973be | 462 | void display(){ |
yangtzuli | 3:2ae6218973be | 463 | mutex.lock(); |
yangtzuli | 3:2ae6218973be | 464 | lcd.setAddress(0,1); |
yangtzuli | 3:2ae6218973be | 465 | switch(mode){ |
yangtzuli | 3:2ae6218973be | 466 | case ADVANCE: |
yangtzuli | 3:2ae6218973be | 467 | //strcpy(DispMode,"Mode:Advance"); |
yangtzuli | 3:2ae6218973be | 468 | lcd.printf("Mode:Advance "); |
yangtzuli | 3:2ae6218973be | 469 | break; |
yangtzuli | 3:2ae6218973be | 470 | case RIGHT: |
yangtzuli | 3:2ae6218973be | 471 | //strcpy(DispMode,"Mode:Right"); |
yangtzuli | 3:2ae6218973be | 472 | lcd.printf("Mode:Right "); |
yangtzuli | 3:2ae6218973be | 473 | break; |
yangtzuli | 3:2ae6218973be | 474 | case LEFT: |
yangtzuli | 3:2ae6218973be | 475 | //strcpy(DispMode,"Mode:Left"); |
yangtzuli | 3:2ae6218973be | 476 | lcd.printf("Mode:Left "); |
yangtzuli | 3:2ae6218973be | 477 | break; |
yangtzuli | 3:2ae6218973be | 478 | case BACK: |
yangtzuli | 3:2ae6218973be | 479 | //strcpy(DispMode,"Mode:Back"); |
yangtzuli | 3:2ae6218973be | 480 | lcd.printf("Mode:Back "); |
yangtzuli | 3:2ae6218973be | 481 | break; |
yangtzuli | 3:2ae6218973be | 482 | case STOP: |
yangtzuli | 3:2ae6218973be | 483 | //strcpy(DispMode,"Mode:Stop"); |
yangtzuli | 3:2ae6218973be | 484 | lcd.printf("Mode:Stop "); |
yangtzuli | 3:2ae6218973be | 485 | break; |
yangtzuli | 3:2ae6218973be | 486 | case READY: |
yangtzuli | 3:2ae6218973be | 487 | //strcpy(DispMode,"Mode:Stop"); |
yangtzuli | 3:2ae6218973be | 488 | lcd.printf("Mode:Ready "); |
yangtzuli | 3:2ae6218973be | 489 | break; |
yangtzuli | 3:2ae6218973be | 490 | case LINE_TRACE: |
yangtzuli | 3:2ae6218973be | 491 | //strcpy(DispMode,"Mode:LineTrace"); |
yangtzuli | 3:2ae6218973be | 492 | lcd.printf("Mode:LineTrace "); |
yangtzuli | 3:2ae6218973be | 493 | break; |
yangtzuli | 3:2ae6218973be | 494 | case AVOIDANCE: |
yangtzuli | 3:2ae6218973be | 495 | //strcpy(DispMode,"Mode:Avoidance"); |
yangtzuli | 3:2ae6218973be | 496 | lcd.setAddress(0,1); |
yangtzuli | 3:2ae6218973be | 497 | lcd.printf("Mode:Avoidance "); |
yangtzuli | 3:2ae6218973be | 498 | break; |
yangtzuli | 3:2ae6218973be | 499 | case SPEED: |
yangtzuli | 3:2ae6218973be | 500 | switch(flag_sp){ |
yangtzuli | 3:2ae6218973be | 501 | case(NORMAL): |
yangtzuli | 3:2ae6218973be | 502 | lcd.printf("Speed:Normal "); |
yangtzuli | 3:2ae6218973be | 503 | break; |
yangtzuli | 3:2ae6218973be | 504 | case(FAST): |
yangtzuli | 3:2ae6218973be | 505 | lcd.printf("Speed:Fast "); |
yangtzuli | 3:2ae6218973be | 506 | break; |
yangtzuli | 3:2ae6218973be | 507 | case(VERYFAST): |
yangtzuli | 3:2ae6218973be | 508 | lcd.printf("Speed:VeryFast "); |
yangtzuli | 3:2ae6218973be | 509 | break; |
yangtzuli | 3:2ae6218973be | 510 | } |
yangtzuli | 3:2ae6218973be | 511 | viewTimer.reset(); |
yangtzuli | 3:2ae6218973be | 512 | viewTimer.start(); |
yangtzuli | 3:2ae6218973be | 513 | break; |
yangtzuli | 3:2ae6218973be | 514 | } |
yangtzuli | 3:2ae6218973be | 515 | mutex.unlock(); |
yangtzuli | 3:2ae6218973be | 516 | } |
yangtzuli | 3:2ae6218973be | 517 | |
yangtzuli | 3:2ae6218973be | 518 | void lcdBacklight(void const *argument){ |
yangtzuli | 3:2ae6218973be | 519 | if(flag_b == 1){ |
yangtzuli | 3:2ae6218973be | 520 | lcd.setBacklight(TextLCD::LightOn); |
yangtzuli | 3:2ae6218973be | 521 | }else{ |
yangtzuli | 3:2ae6218973be | 522 | lcd.setBacklight(TextLCD::LightOff); |
yangtzuli | 3:2ae6218973be | 523 | } |
yangtzuli | 3:2ae6218973be | 524 | flag_b = !flag_b; |
yangtzuli | 3:2ae6218973be | 525 | } |
yangtzuli | 2:38825726cb1b | 526 | |
yangtzuli | 4:3f80c0180e2f | 527 | void bChange(/*void const *argument*/){ |
yangtzuli | 3:2ae6218973be | 528 | /*while(1){ |
yangtzuli | 3:2ae6218973be | 529 | pc.printf(" bChange1\r\n"); |
yangtzuli | 3:2ae6218973be | 530 | lcd.setBacklight(TextLCD::LightOn); |
yangtzuli | 2:38825726cb1b | 531 | test = battery.read()*MAX_V; |
yangtzuli | 2:38825726cb1b | 532 | b = (int)((test - MIN_V)/0.107 + 0.5)*10; |
yangtzuli | 3:2ae6218973be | 533 | if(b < 0){ |
yangtzuli | 3:2ae6218973be | 534 | b = 0; |
yangtzuli | 3:2ae6218973be | 535 | }else if(b > 100){ |
yangtzuli | 3:2ae6218973be | 536 | b = 100; |
yangtzuli | 3:2ae6218973be | 537 | } |
yangtzuli | 3:2ae6218973be | 538 | mutex.lock(); |
yangtzuli | 3:2ae6218973be | 539 | lcd.setAddress(0,0); |
yangtzuli | 3:2ae6218973be | 540 | lcd.printf("Battery:%3d%% ",b); |
yangtzuli | 3:2ae6218973be | 541 | pc.printf(" bChange2\r\n"); |
yangtzuli | 3:2ae6218973be | 542 | mutex.unlock(); |
yangtzuli | 3:2ae6218973be | 543 | }*/ |
yangtzuli | 3:2ae6218973be | 544 | lcd.setBacklight(TextLCD::LightOn); |
yangtzuli | 3:2ae6218973be | 545 | while(1){ |
yangtzuli | 3:2ae6218973be | 546 | pc.printf(" bChange1\r\n"); |
yangtzuli | 4:3f80c0180e2f | 547 | b = (int)(((battery.read() * 3.3 - MIN_V)/0.67)*10+0.5)*10; |
yangtzuli | 4:3f80c0180e2f | 548 | pc.printf("%f",battery.read()); |
yangtzuli | 4:3f80c0180e2f | 549 | if(b < 0){//すべての機能停止(今はなし) |
yangtzuli | 4:3f80c0180e2f | 550 | /*lcd.setBacklight(TextLCD::LightOff); |
yangtzuli | 3:2ae6218973be | 551 | bTimer.stop(); |
yangtzuli | 4:3f80c0180e2f | 552 | exit(1);*/ |
yangtzuli | 4:3f80c0180e2f | 553 | b = 0; |
yangtzuli | 3:2ae6218973be | 554 | }else if(b > 100){ |
yangtzuli | 3:2ae6218973be | 555 | b = 100; |
yangtzuli | 3:2ae6218973be | 556 | } |
yangtzuli | 3:2ae6218973be | 557 | mutex.lock(); |
yangtzuli | 3:2ae6218973be | 558 | lcd.setAddress(0,0); |
yangtzuli | 2:38825726cb1b | 559 | lcd.printf("Battery:%3d%%",b); |
yangtzuli | 3:2ae6218973be | 560 | pc.printf(" bChange2\r\n"); |
yangtzuli | 3:2ae6218973be | 561 | mutex.unlock(); |
yangtzuli | 3:2ae6218973be | 562 | if(b <= 30){ |
yangtzuli | 3:2ae6218973be | 563 | if(flag_t == 0){ |
yangtzuli | 3:2ae6218973be | 564 | bTimer.start(500); |
yangtzuli | 3:2ae6218973be | 565 | flag_t = 1; |
yangtzuli | 3:2ae6218973be | 566 | } |
yangtzuli | 3:2ae6218973be | 567 | }else{ |
yangtzuli | 3:2ae6218973be | 568 | if(flag_t == 1){ |
yangtzuli | 3:2ae6218973be | 569 | bTimer.stop(); |
yangtzuli | 3:2ae6218973be | 570 | lcd.setBacklight(TextLCD::LightOn); |
yangtzuli | 3:2ae6218973be | 571 | flag_t = 0; |
yangtzuli | 3:2ae6218973be | 572 | } |
yangtzuli | 3:2ae6218973be | 573 | } |
yangtzuli | 2:38825726cb1b | 574 | } |
yangtzuli | 4:3f80c0180e2f | 575 | ThisThread::sleep_for(500); |
yangtzuli | 2:38825726cb1b | 576 | } |
yangtzuli | 0:0d0037aabe41 | 577 | int main() { |
yangtzuli | 3:2ae6218973be | 578 | mode = READY; |
yangtzuli | 3:2ae6218973be | 579 | beforeMode = READY; |
yangtzuli | 3:2ae6218973be | 580 | run = STOP; |
yangtzuli | 3:2ae6218973be | 581 | flag_sp = NORMAL; |
yangtzuli | 4:3f80c0180e2f | 582 | display(); |
yangtzuli | 3:2ae6218973be | 583 | //defaultView(); |
yangtzuli | 2:38825726cb1b | 584 | |
yangtzuli | 0:0d0037aabe41 | 585 | while(1){ |
yangtzuli | 3:2ae6218973be | 586 | pc.printf(" main1\r\n"); |
yangtzuli | 4:3f80c0180e2f | 587 | // 受信待ち |
yangtzuli | 4:3f80c0180e2f | 588 | /*switch(mode){ |
yangtzuli | 4:3f80c0180e2f | 589 | case ADVANCE: |
yangtzuli | 3:2ae6218973be | 590 | run = ADVANCE; |
yangtzuli | 3:2ae6218973be | 591 | break; |
yangtzuli | 3:2ae6218973be | 592 | case RIGHT: |
yangtzuli | 3:2ae6218973be | 593 | run = RIGHT; |
yangtzuli | 3:2ae6218973be | 594 | break; |
yangtzuli | 3:2ae6218973be | 595 | case LEFT: |
yangtzuli | 3:2ae6218973be | 596 | run = LEFT; |
yangtzuli | 3:2ae6218973be | 597 | break; |
yangtzuli | 3:2ae6218973be | 598 | case BACK: |
yangtzuli | 3:2ae6218973be | 599 | run = BACK; |
yangtzuli | 3:2ae6218973be | 600 | break; |
yangtzuli | 3:2ae6218973be | 601 | case STOP: |
yangtzuli | 3:2ae6218973be | 602 | run = STOP; |
yangtzuli | 3:2ae6218973be | 603 | break; |
yangtzuli | 3:2ae6218973be | 604 | case READY: |
yangtzuli | 3:2ae6218973be | 605 | run = STOP; |
yangtzuli | 4:3f80c0180e2f | 606 | break; |
yangtzuli | 3:2ae6218973be | 607 | case SPEED: |
yangtzuli | 3:2ae6218973be | 608 | changeSpeed(); |
yangtzuli | 3:2ae6218973be | 609 | display(); |
yangtzuli | 3:2ae6218973be | 610 | mode = beforeMode; |
yangtzuli | 3:2ae6218973be | 611 | break; |
yangtzuli | 4:3f80c0180e2f | 612 | }*/ |
yangtzuli | 3:2ae6218973be | 613 | |
yangtzuli | 4:3f80c0180e2f | 614 | /* if(viewTimer.read_ms()>=3000){ |
yangtzuli | 3:2ae6218973be | 615 | pc.printf("a"); |
yangtzuli | 3:2ae6218973be | 616 | viewTimer.stop(); |
yangtzuli | 3:2ae6218973be | 617 | //defaultView(); |
yangtzuli | 3:2ae6218973be | 618 | viewTimer.reset(); |
yangtzuli | 3:2ae6218973be | 619 | //flaga=0; |
yangtzuli | 3:2ae6218973be | 620 | } |
yangtzuli | 3:2ae6218973be | 621 | pc.printf(" main2\r\n"); |
yangtzuli | 3:2ae6218973be | 622 | if(viewTimer.read_ms()==0){ |
yangtzuli | 3:2ae6218973be | 623 | display(); |
yangtzuli | 4:3f80c0180e2f | 624 | }*/ |
yangtzuli | 4:3f80c0180e2f | 625 | bChange(); |
yangtzuli | 3:2ae6218973be | 626 | pc.printf(" main3\r\n"); |
yangtzuli | 4:3f80c0180e2f | 627 | ThisThread::sleep_for(1); |
yangtzuli | 0:0d0037aabe41 | 628 | } |
yangtzuli | 0:0d0037aabe41 | 629 | } |