
linetrace
Dependencies: RemoteIR TextLCD
main.cpp@50:8843bee40df5, 2020-09-01 (annotated)
- Committer:
- mori2020
- Date:
- Tue Sep 01 05:38:46 2020 +0000
- Revision:
- 50:8843bee40df5
- Parent:
- 49:178dcafb4f0e
- Child:
- 51:2d35f207d217
komennto kehita
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 | |
nishimura_taku_pet | 27:90962c01bfeb | 13 | RawSerial pc(USBTX, USBRX); |
yangtzuli | 0:0d0037aabe41 | 14 | |
yangtzuli | 3:2ae6218973be | 15 | /* マクロ定義、列挙型定義 */ |
takuminomura | 48:3003ea51c619 | 16 | #define MIN_V 2.0 // 電圧の最小値 |
takuminomura | 48:3003ea51c619 | 17 | #define MAX_V 2.67 // 電圧の最大値 |
takuminomura | 48:3003ea51c619 | 18 | #define LOW 0 // モーターOFF |
takuminomura | 48:3003ea51c619 | 19 | #define HIGH 1 // モーターON |
takuminomura | 48:3003ea51c619 | 20 | #define NORMAL 0 // 普通 |
takuminomura | 48:3003ea51c619 | 21 | #define FAST 1 // 速い |
takuminomura | 48:3003ea51c619 | 22 | #define VERYFAST 2 // とても速い |
takuminomura | 48:3003ea51c619 | 23 | |
takuminomura | 48:3003ea51c619 | 24 | #define SLOW 0.8 |
takuminomura | 48:3003ea51c619 | 25 | #define REVERSE 0.5 |
takuminomura | 48:3003ea51c619 | 26 | |
takuminomura | 48:3003ea51c619 | 27 | #define MBED04 0.781//Mbed04号機の左右のモーター速度比(R:L = 1: 0.781) |
takuminomura | 48:3003ea51c619 | 28 | #define MBED05 0.953//Mbed05号機の左右のモーター速度比(R:L = 1: 0.953) |
takuminomura | 48:3003ea51c619 | 29 | #define MSR0 0.4 |
takuminomura | 48:3003ea51c619 | 30 | #define MSR1 0.5 |
takuminomura | 48:3003ea51c619 | 31 | #define MSR2 0.6 |
takuminomura | 48:3003ea51c619 | 32 | #define MSR3 MSR0*SLOW |
takuminomura | 48:3003ea51c619 | 33 | #define MSR4 MSR1*SLOW |
takuminomura | 48:3003ea51c619 | 34 | #define MSR5 MSR2*SLOW |
takuminomura | 48:3003ea51c619 | 35 | #define MSR6 0.7 |
takuminomura | 48:3003ea51c619 | 36 | #define MSR7 0.8 |
takuminomura | 48:3003ea51c619 | 37 | #define MSR8 0.9 |
takuminomura | 48:3003ea51c619 | 38 | #define MSL0 MSR0*MBED05 |
takuminomura | 48:3003ea51c619 | 39 | #define MSL1 MSR1*MBED05 |
takuminomura | 48:3003ea51c619 | 40 | #define MSL2 MSR2*MBED05 |
takuminomura | 48:3003ea51c619 | 41 | #define MSL3 MSR3*MBED05 |
takuminomura | 48:3003ea51c619 | 42 | #define MSL4 MSR4*MBED05 |
takuminomura | 48:3003ea51c619 | 43 | #define MSL5 MSR5*MBED05 |
takuminomura | 48:3003ea51c619 | 44 | #define MSL6 MSR6*MBED05 |
takuminomura | 48:3003ea51c619 | 45 | #define MSL7 MSR7*MBED05 |
takuminomura | 48:3003ea51c619 | 46 | #define MSL8 MSR8*MBED05 |
yangtzuli | 2:38825726cb1b | 47 | |
tomotsugu | 8:a47dbf4fa455 | 48 | /* 操作モード定義 */ |
yangtzuli | 3:2ae6218973be | 49 | enum MODE{ |
tomotsugu | 8:a47dbf4fa455 | 50 | READY = -1, // -1:待ち |
tomotsugu | 8:a47dbf4fa455 | 51 | ADVANCE = 1, // 1:前進 |
tomotsugu | 8:a47dbf4fa455 | 52 | RIGHT, // 2:右折 |
tomotsugu | 8:a47dbf4fa455 | 53 | LEFT, // 3:左折 |
tomotsugu | 8:a47dbf4fa455 | 54 | BACK, // 4:後退 |
tomotsugu | 8:a47dbf4fa455 | 55 | STOP, // 5:停止 |
tomotsugu | 8:a47dbf4fa455 | 56 | LINE_TRACE, // 6:ライントレース |
tomotsugu | 8:a47dbf4fa455 | 57 | AVOIDANCE, // 7:障害物回避 |
tomotsugu | 8:a47dbf4fa455 | 58 | SPEED, // 8:スピード制御 |
yangtzuli | 2:38825726cb1b | 59 | }; |
yangtzuli | 2:38825726cb1b | 60 | |
yangtzuli | 3:2ae6218973be | 61 | /* ピン配置 */ |
yangtzuli | 3:2ae6218973be | 62 | ReceiverIR ir(p5); // リモコン操作 |
yangtzuli | 3:2ae6218973be | 63 | DigitalOut trig(p6); // 超音波センサtrigger |
yangtzuli | 5:3fffb364744b | 64 | DigitalIn echo(p7); // 超音波センサecho |
yangtzuli | 3:2ae6218973be | 65 | DigitalIn ss1(p8); // ライントレースセンサ(左) |
yangtzuli | 3:2ae6218973be | 66 | DigitalIn ss2(p9); // ライントレースセンサ |
yangtzuli | 3:2ae6218973be | 67 | DigitalIn ss3(p10); // ライントレースセンサ |
yangtzuli | 3:2ae6218973be | 68 | DigitalIn ss4(p11); // ライントレースセンサ |
yangtzuli | 3:2ae6218973be | 69 | DigitalIn ss5(p12); // ライントレースセンサ(右) |
nishimura_taku_pet | 24:9481c8f56a49 | 70 | RawSerial esp(p13, p14); // Wi-Fiモジュール(tx, rx) |
yangtzuli | 3:2ae6218973be | 71 | AnalogIn battery(p15); // 電池残量読み取り(Max 3.3V) |
takuminomura | 48:3003ea51c619 | 72 | PwmOut motorR2(p22); // 右モーター後退 |
takuminomura | 48:3003ea51c619 | 73 | PwmOut motorR1(p21); // 右モーター前進 |
yangtzuli | 3:2ae6218973be | 74 | PwmOut motorL2(p23); // 左モーター後退 |
yangtzuli | 3:2ae6218973be | 75 | PwmOut motorL1(p24); // 左モーター前進 |
yangtzuli | 3:2ae6218973be | 76 | PwmOut servo(p25); // サーボ |
yangtzuli | 3:2ae6218973be | 77 | I2C i2c_lcd(p28,p27); // LCD(tx, rx) |
yangtzuli | 2:38825726cb1b | 78 | |
yangtzuli | 3:2ae6218973be | 79 | /* 変数宣言 */ |
yangtzuli | 3:2ae6218973be | 80 | int mode; // 操作モード |
yangtzuli | 3:2ae6218973be | 81 | int run; // 走行状態 |
takuminomura | 48:3003ea51c619 | 82 | int beforeRun = STOP; // 前回の走行状態 |
tomotsugu | 8:a47dbf4fa455 | 83 | int beforeMode; // 前回のモード |
tomotsugu | 8:a47dbf4fa455 | 84 | int flag_sp = 0; // スピード変化フラグ |
tomotsugu | 8:a47dbf4fa455 | 85 | Timer viewTimer; // スピ―ド変更時に3秒計測タイマー |
takuminomura | 48:3003ea51c619 | 86 | |
takuminomura | 48:3003ea51c619 | 87 | float motorSpeedR1[9] = {MSR0, MSR1, MSR2, MSR3 , MSR4 , MSR5 , MSR6 , MSR7 , MSR8 }; |
takuminomura | 48:3003ea51c619 | 88 | //float motorSpeedR2[9] = {MSR0, MSR1, MSR2, MSR3*REVERSE, MSR4*REVERSE, MSR5*REVERSE, MSR6*REVERSE, MSR7*REVERSE, MSR8*REVERSE}; |
takuminomura | 48:3003ea51c619 | 89 | float motorSpeedR2[9] = {MSR0, MSR1, MSR2, MSR3*REVERSE, MSR4*REVERSE, MSR5*REVERSE, MSR6, MSR7, MSR8}; |
takuminomura | 48:3003ea51c619 | 90 | float motorSpeedL1[9] = {MSL0, MSL1, MSL2, MSL3 , MSL4 , MSL5 , MSL6 , MSL7 , MSL8 }; |
takuminomura | 48:3003ea51c619 | 91 | //float motorSpeedL2[9] = {MSL0, MSL1, MSL2, MSL3*REVERSE, MSL4*REVERSE, MSL5*REVERSE, MSL6*REVERSE, MSL7*REVERSE, MSL8*REVERSE}; |
takuminomura | 48:3003ea51c619 | 92 | float motorSpeedL2[9] = {MSL0, MSL1, MSL2, MSL3*REVERSE, MSL4*REVERSE, MSL5*REVERSE, MSL6, MSL7, MSL8}; |
yangtzuli | 3:2ae6218973be | 93 | // モーター速度設定(後半はライントレース用) |
takuminomura | 48:3003ea51c619 | 94 | // 0,1,2:基準速度 |
takuminomura | 48:3003ea51c619 | 95 | // 3,4,5:低速 |
takuminomura | 48:3003ea51c619 | 96 | // 6,7,8:高速 |
takuminomura | 48:3003ea51c619 | 97 | // R1 : 右前, R2 : 右後, L1 : 左前, L2 : 左後 |
tomotsugu | 8:a47dbf4fa455 | 98 | |
tomotsugu | 8:a47dbf4fa455 | 99 | Mutex mutex; // ミューテックス |
takuminomura | 48:3003ea51c619 | 100 | |
tomotsugu | 8:a47dbf4fa455 | 101 | /* decodeIR用変数 */ |
yangtzuli | 3:2ae6218973be | 102 | RemoteIR::Format format; |
yangtzuli | 3:2ae6218973be | 103 | uint8_t buf[32]; |
yangtzuli | 3:2ae6218973be | 104 | uint32_t bitcount; |
yangtzuli | 3:2ae6218973be | 105 | uint32_t code; |
yangtzuli | 3:2ae6218973be | 106 | |
tomotsugu | 8:a47dbf4fa455 | 107 | /* bChange, lcdbacklight用変数 */ |
yangtzuli | 3:2ae6218973be | 108 | TextLCD_I2C lcd(&i2c_lcd, (0x27 << 1), TextLCD::LCD16x2, TextLCD::HD44780); |
tomotsugu | 8:a47dbf4fa455 | 109 | int b = 0; // バッテリー残量 |
tomotsugu | 8:a47dbf4fa455 | 110 | int flag_b = 0; // バックライト点滅フラグ |
tomotsugu | 8:a47dbf4fa455 | 111 | int flag_t = 0; // バックライトタイマーフラグ |
yangtzuli | 3:2ae6218973be | 112 | |
tomotsugu | 8:a47dbf4fa455 | 113 | /* trace用変数 */ |
takuminomura | 48:3003ea51c619 | 114 | int sensArray[32] = {0,6,2,4,1,2,1,4, // ライントレースセンサパターン |
takuminomura | 48:3003ea51c619 | 115 | 3,6,1,6,1,1,1,6, // 0:前回動作継続 |
takuminomura | 48:3003ea51c619 | 116 | 7,1,7,1,3,1,1,1, // 1:高速前進 |
takuminomura | 48:3003ea51c619 | 117 | 5,1,7,1,5,1,7,1}; // 2:低速右折 |
takuminomura | 48:3003ea51c619 | 118 | // 3:低速左折 |
takuminomura | 48:3003ea51c619 | 119 | // 4:中速右折 |
takuminomura | 48:3003ea51c619 | 120 | // 5:中速左折 |
takuminomura | 48:3003ea51c619 | 121 | // 6:高速右折 |
takuminomura | 48:3003ea51c619 | 122 | // 7:高速左折 |
takuminomura | 48:3003ea51c619 | 123 | |
takuminomura | 48:3003ea51c619 | 124 | //int sensArray[32] = {0,6,0,4,1,0,1,4, // ライントレースセンサパターン |
takuminomura | 48:3003ea51c619 | 125 | // 0,6,1,6,1,1,1,6, // 0:前回動作継続 |
takuminomura | 48:3003ea51c619 | 126 | // 7,1,7,1,0,1,1,1, // 1:高速前進 |
takuminomura | 48:3003ea51c619 | 127 | // 5,1,7,1,5,1,7,1}; // 2:低速右折 |
takuminomura | 48:3003ea51c619 | 128 | // // 3:低速左折 |
takuminomura | 48:3003ea51c619 | 129 | // // 4:中速右折 |
takuminomura | 48:3003ea51c619 | 130 | // // 5:中速左折 |
takuminomura | 48:3003ea51c619 | 131 | // // 6:高速右折 |
takuminomura | 48:3003ea51c619 | 132 | // // 7:高速左折 |
yangtzuli | 0:0d0037aabe41 | 133 | |
tomotsugu | 8:a47dbf4fa455 | 134 | /* avoidance用変数 */ |
yangtzuli | 3:2ae6218973be | 135 | Timer timer; // 距離計測用タイマ |
yangtzuli | 3:2ae6218973be | 136 | int DT; // 距離 |
takuminomura | 48:3003ea51c619 | 137 | int SC; // 正面 |
yangtzuli | 2:38825726cb1b | 138 | int SL; // 左 |
yangtzuli | 2:38825726cb1b | 139 | int SR; // 右 |
yangtzuli | 2:38825726cb1b | 140 | int SLD; // 左前 |
yangtzuli | 2:38825726cb1b | 141 | int SRD; // 右前 |
tomotsugu | 8:a47dbf4fa455 | 142 | int flag_a = 0; // 障害物有無のフラグ |
yangtzuli | 2:38825726cb1b | 143 | const int limit = 20; // 障害物の距離のリミット(単位:cm) |
yangtzuli | 3:2ae6218973be | 144 | int far; // 最も遠い距離 |
yangtzuli | 2:38825726cb1b | 145 | int houkou; // 進行方向(1:前 2:左 3:右) |
nishimura_taku_pet | 29:600e4b9b5c5b | 146 | int t1 = 0; |
yangtzuli | 2:38825726cb1b | 147 | |
nishimura_taku_pet | 24:9481c8f56a49 | 148 | /*WiFi用変数*/ |
nishimura_taku_pet | 24:9481c8f56a49 | 149 | Timer time1; |
nishimura_taku_pet | 24:9481c8f56a49 | 150 | Timer time2; |
nishimura_taku_pet | 24:9481c8f56a49 | 151 | int bufflen, DataRX, ount, getcount, replycount, servreq, timeout; |
nishimura_taku_pet | 24:9481c8f56a49 | 152 | int bufl, ipdLen, linkID, weberror, webcounter,click_flag; |
nishimura_taku_pet | 24:9481c8f56a49 | 153 | float R1=100000, R2=10000; // resistor values to give a 10:1 reduction of measured AnalogIn voltage |
nishimura_taku_pet | 24:9481c8f56a49 | 154 | char webcount[8]; |
nishimura_taku_pet | 24:9481c8f56a49 | 155 | char type[16]; |
nishimura_taku_pet | 24:9481c8f56a49 | 156 | char channel[2]; |
nishimura_taku_pet | 24:9481c8f56a49 | 157 | char cmdbuff[32]; |
nishimura_taku_pet | 24:9481c8f56a49 | 158 | char replybuff[1024]; |
nishimura_taku_pet | 24:9481c8f56a49 | 159 | char webdata[1024]; // This may need to be bigger depending on WEB browser used |
nishimura_taku_pet | 27:90962c01bfeb | 160 | char webbuff[4096]; // Currently using 1986 characters, Increase this if more web page data added |
nishimura_taku_pet | 24:9481c8f56a49 | 161 | int port =80; // set server port |
nishimura_taku_pet | 24:9481c8f56a49 | 162 | int SERVtimeout =5; // set server timeout in seconds in case link breaks. |
takuminomura | 48:3003ea51c619 | 163 | char ssid[32] = "mbed05"; // enter WiFi router ssid inside the quotes |
nishimura_taku_pet | 24:9481c8f56a49 | 164 | char pwd [32] = "0123456789a"; // enter WiFi router password inside the quotes |
yangtzuli | 3:2ae6218973be | 165 | |
yangtzuli | 3:2ae6218973be | 166 | /* プロトタイプ宣言 */ |
nishimura_taku_pet | 33:a6f1090e0174 | 167 | void decodeIR(/*void const *argument*/); |
nishimura_taku_pet | 33:a6f1090e0174 | 168 | void motor(/*void const *argument*/); |
yangtzuli | 3:2ae6218973be | 169 | void changeSpeed(); |
nishimura_taku_pet | 16:ffc732a3cf92 | 170 | void avoidance(/*void const *argument*/); |
nishimura_taku_pet | 16:ffc732a3cf92 | 171 | void trace(/*void const *argument*/); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 172 | void watchsurrounding3(); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 173 | void watchsurrounding5(); |
yangtzuli | 2:38825726cb1b | 174 | int watch(); |
takuminomura | 48:3003ea51c619 | 175 | char battery_ch[8]; |
yangtzuli | 5:3fffb364744b | 176 | void bChange(); |
yangtzuli | 3:2ae6218973be | 177 | void display(); |
yangtzuli | 3:2ae6218973be | 178 | void lcdBacklight(void const *argument); |
nishimura_taku_pet | 45:76e8c07d76ef | 179 | void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck(); |
nishimura_taku_pet | 43:243c1455f88a | 180 | void wifi(/*void const *argument*/); |
takuminomura | 48:3003ea51c619 | 181 | Thread *deco_thread; // decodeIRをスレッド化 :+3 |
nishimura_taku_pet | 43:243c1455f88a | 182 | Thread *wifi_thread; |
takuminomura | 48:3003ea51c619 | 183 | //wifi_thread(wifi,NULL,osPriorityHigh); // wifiをスレッド化 |
takuminomura | 48:3003ea51c619 | 184 | Thread *motor_thread; // motorをスレッド化 :+2 |
takuminomura | 48:3003ea51c619 | 185 | RtosTimer bTimer(lcdBacklight, osTimerPeriodic); // lcdBacklightをタイマー割り込みで設定 |
takuminomura | 48:3003ea51c619 | 186 | Thread *avoi_thread; // avoidanceをスレッド化:+2 |
takuminomura | 48:3003ea51c619 | 187 | Thread *trace_thread; // traceをスレッド化 :+2 |
yangtzuli | 2:38825726cb1b | 188 | |
nishimura_taku_pet | 24:9481c8f56a49 | 189 | DigitalOut led1(LED1); |
nishimura_taku_pet | 24:9481c8f56a49 | 190 | DigitalOut led2(LED2); |
nishimura_taku_pet | 24:9481c8f56a49 | 191 | DigitalOut led3(LED3); |
nishimura_taku_pet | 24:9481c8f56a49 | 192 | DigitalOut led4(LED4); |
yangtzuli | 3:2ae6218973be | 193 | |
nishimura_taku_pet | 33:a6f1090e0174 | 194 | void setup(){ |
nishimura_taku_pet | 33:a6f1090e0174 | 195 | deco_thread = new Thread(decodeIR); |
nishimura_taku_pet | 33:a6f1090e0174 | 196 | deco_thread -> set_priority(osPriorityRealtime); |
nishimura_taku_pet | 33:a6f1090e0174 | 197 | motor_thread = new Thread(motor); |
nishimura_taku_pet | 33:a6f1090e0174 | 198 | motor_thread -> set_priority(osPriorityHigh); |
mori2020 | 49:178dcafb4f0e | 199 | wifi_thread -> set_priority(osPriorityRealtime); |
nishimura_taku_pet | 33:a6f1090e0174 | 200 | display(); |
nishimura_taku_pet | 33:a6f1090e0174 | 201 | } |
nishimura_taku_pet | 33:a6f1090e0174 | 202 | |
tomotsugu | 8:a47dbf4fa455 | 203 | /* リモコン受信スレッド */ |
takuminomura | 48:3003ea51c619 | 204 | void decodeIR(/*void const *argument*/){ |
takuminomura | 48:3003ea51c619 | 205 | while(1){ |
yangtzuli | 0:0d0037aabe41 | 206 | // 受信待ち |
tomotsugu | 8:a47dbf4fa455 | 207 | if (ir.getState() == ReceiverIR::Received){ // コード受信 |
yangtzuli | 3:2ae6218973be | 208 | bitcount = ir.getData(&format, buf, sizeof(buf) * 8); |
tomotsugu | 8:a47dbf4fa455 | 209 | if(bitcount > 1){ // 受信成功 |
yangtzuli | 1:5bb497a38344 | 210 | code=0; |
tomotsugu | 15:5eef1955f6c2 | 211 | for(int j = 0; j < 4; j++){ |
yangtzuli | 1:5bb497a38344 | 212 | code+=(buf[j]<<(8*(3-j))); |
yangtzuli | 1:5bb497a38344 | 213 | } |
tomotsugu | 8:a47dbf4fa455 | 214 | if(mode != SPEED){ // スピードモード以外なら |
takuminomura | 48:3003ea51c619 | 215 | beforeMode=mode; // 前回のモードに現在のモードを設定 |
yangtzuli | 3:2ae6218973be | 216 | } |
yangtzuli | 0:0d0037aabe41 | 217 | switch(code){ |
tomotsugu | 8:a47dbf4fa455 | 218 | case 0x40bf27d8: // クイック |
mori2020 | 50:8843bee40df5 | 219 | ////*-*-*-5("mode = SPEED\r\n"); |
takuminomura | 48:3003ea51c619 | 220 | mode = SPEED; // スピードモード |
tomotsugu | 8:a47dbf4fa455 | 221 | changeSpeed(); // 速度変更 |
tomotsugu | 8:a47dbf4fa455 | 222 | display(); // ディスプレイ表示 |
tomotsugu | 8:a47dbf4fa455 | 223 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
yangtzuli | 1:5bb497a38344 | 224 | break; |
tomotsugu | 8:a47dbf4fa455 | 225 | case 0x40be34cb: // レグザリンク |
mori2020 | 50:8843bee40df5 | 226 | ////*-*-*-5("mode = LINE_TRACE\r\n"); |
nishimura_taku_pet | 16:ffc732a3cf92 | 227 | if(trace_thread->get_state() == Thread::Deleted){ |
nishimura_taku_pet | 16:ffc732a3cf92 | 228 | delete trace_thread; |
nishimura_taku_pet | 16:ffc732a3cf92 | 229 | trace_thread = new Thread(trace); |
nishimura_taku_pet | 16:ffc732a3cf92 | 230 | trace_thread -> set_priority(osPriorityHigh); |
nishimura_taku_pet | 16:ffc732a3cf92 | 231 | } |
tomotsugu | 8:a47dbf4fa455 | 232 | mode=LINE_TRACE; // ライントレースモード |
tomotsugu | 8:a47dbf4fa455 | 233 | display(); // ディスプレイ表示 |
yangtzuli | 1:5bb497a38344 | 234 | break; |
tomotsugu | 8:a47dbf4fa455 | 235 | case 0x40bf6e91: // 番組表 |
mori2020 | 50:8843bee40df5 | 236 | ////*-*-*-5("mode = AVOIDANCE\r\n"); |
nishimura_taku_pet | 16:ffc732a3cf92 | 237 | if(avoi_thread->get_state() == Thread::Deleted){ |
nishimura_taku_pet | 16:ffc732a3cf92 | 238 | delete avoi_thread; |
nishimura_taku_pet | 16:ffc732a3cf92 | 239 | avoi_thread = new Thread(avoidance); |
nishimura_taku_pet | 16:ffc732a3cf92 | 240 | avoi_thread -> set_priority(osPriorityHigh); |
nishimura_taku_pet | 16:ffc732a3cf92 | 241 | } |
tomotsugu | 18:6cca64c7dbc3 | 242 | flag_a = 0; |
tomotsugu | 8:a47dbf4fa455 | 243 | mode=AVOIDANCE; // 障害物回避モード |
tomotsugu | 13:1a7667d0aa78 | 244 | run = ADVANCE; // 前進 |
tomotsugu | 8:a47dbf4fa455 | 245 | display(); // ディスプレイ表示 |
yangtzuli | 1:5bb497a38344 | 246 | break; |
takuminomura | 48:3003ea51c619 | 247 | case 0x40bf3ec1: // ↑ |
mori2020 | 50:8843bee40df5 | 248 | ////*-*-*-5("mode = ADVANCE\r\n"); |
tomotsugu | 8:a47dbf4fa455 | 249 | mode = ADVANCE; // 前進モード |
tomotsugu | 8:a47dbf4fa455 | 250 | run = ADVANCE; // 前進 |
tomotsugu | 8:a47dbf4fa455 | 251 | display(); // ディスプレイ表示 |
yangtzuli | 1:5bb497a38344 | 252 | break; |
takuminomura | 48:3003ea51c619 | 253 | case 0x40bf3fc0: // ↓ |
mori2020 | 50:8843bee40df5 | 254 | ////*-*-*-5("mode = BACK\r\n"); |
tomotsugu | 8:a47dbf4fa455 | 255 | mode = BACK; // 後退モード |
tomotsugu | 8:a47dbf4fa455 | 256 | run = BACK; // 後退 |
tomotsugu | 8:a47dbf4fa455 | 257 | display(); // ディスプレイ表示 |
yangtzuli | 0:0d0037aabe41 | 258 | break; |
takuminomura | 48:3003ea51c619 | 259 | case 0x40bf5fa0: // ← |
mori2020 | 50:8843bee40df5 | 260 | ////*-*-*-5("mode = LEFT\r\n"); |
tomotsugu | 8:a47dbf4fa455 | 261 | mode = LEFT; // 左折モード |
tomotsugu | 8:a47dbf4fa455 | 262 | run = LEFT; // 左折 |
tomotsugu | 8:a47dbf4fa455 | 263 | display(); // ディスプレイ表示 |
yangtzuli | 1:5bb497a38344 | 264 | break; |
takuminomura | 48:3003ea51c619 | 265 | case 0x40bf5ba4: // → |
mori2020 | 50:8843bee40df5 | 266 | ////*-*-*-5("mode = RIGHT\r\n"); |
tomotsugu | 8:a47dbf4fa455 | 267 | mode = RIGHT; // 右折モード |
tomotsugu | 8:a47dbf4fa455 | 268 | run = RIGHT; // 右折 |
tomotsugu | 8:a47dbf4fa455 | 269 | display(); // ディスプレイ表示 |
yangtzuli | 1:5bb497a38344 | 270 | break; |
takuminomura | 48:3003ea51c619 | 271 | case 0x40bf3dc2: // 決定 |
mori2020 | 50:8843bee40df5 | 272 | ////*-*-*-5("mode = STOP\r\n"); |
tomotsugu | 8:a47dbf4fa455 | 273 | mode = STOP; // 停止モード |
tomotsugu | 8:a47dbf4fa455 | 274 | run = STOP; // 停止 |
tomotsugu | 8:a47dbf4fa455 | 275 | display(); // ディスプレイ表示 |
yangtzuli | 1:5bb497a38344 | 276 | break; |
yangtzuli | 0:0d0037aabe41 | 277 | default: |
yangtzuli | 0:0d0037aabe41 | 278 | ; |
yangtzuli | 0:0d0037aabe41 | 279 | } |
nishimura_taku_pet | 16:ffc732a3cf92 | 280 | if(mode != LINE_TRACE && trace_thread->get_state() != Thread::Deleted){ |
nishimura_taku_pet | 16:ffc732a3cf92 | 281 | trace_thread->terminate(); |
nishimura_taku_pet | 16:ffc732a3cf92 | 282 | } |
nishimura_taku_pet | 16:ffc732a3cf92 | 283 | if(mode != AVOIDANCE && avoi_thread->get_state() != Thread::Deleted){ |
nishimura_taku_pet | 16:ffc732a3cf92 | 284 | avoi_thread->terminate(); |
nishimura_taku_pet | 28:cb51cafca490 | 285 | servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 16:ffc732a3cf92 | 286 | } |
yangtzuli | 0:0d0037aabe41 | 287 | } |
yangtzuli | 0:0d0037aabe41 | 288 | } |
takuminomura | 48:3003ea51c619 | 289 | if(viewTimer.read_ms()>=3000){ // スピードモードのまま3秒経過 |
takuminomura | 48:3003ea51c619 | 290 | viewTimer.stop(); // タイマーストップ |
takuminomura | 48:3003ea51c619 | 291 | viewTimer.reset(); // タイマーリセット |
takuminomura | 48:3003ea51c619 | 292 | display(); // ディスプレイ表示 |
yangtzuli | 4:3f80c0180e2f | 293 | } |
takuminomura | 48:3003ea51c619 | 294 | ThisThread::sleep_for(90); // 90ms待つ |
takuminomura | 48:3003ea51c619 | 295 | } |
yangtzuli | 2:38825726cb1b | 296 | } |
tomotsugu | 8:a47dbf4fa455 | 297 | |
tomotsugu | 8:a47dbf4fa455 | 298 | /* モーター制御スレッド */ |
nishimura_taku_pet | 33:a6f1090e0174 | 299 | void motor(/*void const *argument*/){ |
tomotsugu | 8:a47dbf4fa455 | 300 | while(1){ |
tomotsugu | 8:a47dbf4fa455 | 301 | /* 走行状態の場合分け */ |
yangtzuli | 3:2ae6218973be | 302 | switch(run){ |
tomotsugu | 8:a47dbf4fa455 | 303 | /* 前進 */ |
yangtzuli | 3:2ae6218973be | 304 | case ADVANCE: |
takuminomura | 48:3003ea51c619 | 305 | motorR1 = motorSpeedR1[flag_sp]; // 右前進モーターON |
takuminomura | 48:3003ea51c619 | 306 | motorR2 = LOW; // 右後退モーターOFF |
takuminomura | 48:3003ea51c619 | 307 | motorL1 = motorSpeedL1[flag_sp]; // 左前進モーターON |
takuminomura | 48:3003ea51c619 | 308 | motorL2 = LOW; // 左後退モーターOFF |
yangtzuli | 3:2ae6218973be | 309 | break; |
tomotsugu | 8:a47dbf4fa455 | 310 | /* 右折 */ |
yangtzuli | 3:2ae6218973be | 311 | case RIGHT: |
takuminomura | 48:3003ea51c619 | 312 | motorR1 = LOW; // 右前進モーターOFF |
takuminomura | 48:3003ea51c619 | 313 | motorR2 = motorSpeedR2[flag_sp]; // 右後退モーターON |
takuminomura | 48:3003ea51c619 | 314 | motorL1 = motorSpeedL1[flag_sp]; // 左前進モーターON |
takuminomura | 48:3003ea51c619 | 315 | motorL2 = LOW; // 左後退モーターOFF |
yangtzuli | 3:2ae6218973be | 316 | break; |
tomotsugu | 8:a47dbf4fa455 | 317 | /* 左折 */ |
yangtzuli | 3:2ae6218973be | 318 | case LEFT: |
takuminomura | 48:3003ea51c619 | 319 | motorR1 = motorSpeedR1[flag_sp]; // 右前進モーターON |
takuminomura | 48:3003ea51c619 | 320 | motorR2 = LOW; // 右後退モーターOFF |
takuminomura | 48:3003ea51c619 | 321 | motorL1 = LOW; // 左前進モーターOFF |
takuminomura | 48:3003ea51c619 | 322 | motorL2 = motorSpeedL2[flag_sp]; // 左後退モーターON |
yangtzuli | 3:2ae6218973be | 323 | break; |
tomotsugu | 8:a47dbf4fa455 | 324 | /* 後退 */ |
yangtzuli | 3:2ae6218973be | 325 | case BACK: |
takuminomura | 48:3003ea51c619 | 326 | motorR1 = LOW; // 右前進モーターOFF |
takuminomura | 48:3003ea51c619 | 327 | motorR2 = motorSpeedR2[flag_sp]; // 右後退モーターON |
takuminomura | 48:3003ea51c619 | 328 | motorL1 = LOW; // 左前進モーターOFF |
takuminomura | 48:3003ea51c619 | 329 | motorL2 = motorSpeedL2[flag_sp]; // 左後退モーターON |
yangtzuli | 3:2ae6218973be | 330 | break; |
tomotsugu | 8:a47dbf4fa455 | 331 | /* 停止 */ |
yangtzuli | 3:2ae6218973be | 332 | case STOP: |
tomotsugu | 8:a47dbf4fa455 | 333 | motorR1 = LOW; // 右前進モーターOFF |
tomotsugu | 8:a47dbf4fa455 | 334 | motorR2 = LOW; // 右後退モーターOFF |
tomotsugu | 8:a47dbf4fa455 | 335 | motorL1 = LOW; // 左前進モーターOFF |
tomotsugu | 8:a47dbf4fa455 | 336 | motorL2 = LOW; // 左後退モーターOFF |
yangtzuli | 3:2ae6218973be | 337 | break; |
yangtzuli | 3:2ae6218973be | 338 | } |
tomotsugu | 8:a47dbf4fa455 | 339 | if(flag_sp > VERYFAST){ // スピード変更フラグが2より大きいなら |
nishimura_taku_pet | 47:8a5a4275480a | 340 | flag_sp %= 3; // スピード変更フラグ調整 |
yangtzuli | 6:800a745c7f2e | 341 | } |
takuminomura | 48:3003ea51c619 | 342 | ThisThread::sleep_for(3); // 30ms待つ |
yangtzuli | 2:38825726cb1b | 343 | } |
yangtzuli | 2:38825726cb1b | 344 | } |
tomotsugu | 8:a47dbf4fa455 | 345 | |
tomotsugu | 8:a47dbf4fa455 | 346 | /* スピード変更関数 */ |
yangtzuli | 3:2ae6218973be | 347 | void changeSpeed(){ |
tomotsugu | 8:a47dbf4fa455 | 348 | if(flag_sp%3 == 2){ // スピード変更フラグを3で割った余りが2なら |
takuminomura | 48:3003ea51c619 | 349 | flag_sp = 0; // スピード変更フラグを0にする |
tomotsugu | 8:a47dbf4fa455 | 350 | }else{ // それ以外 |
takuminomura | 48:3003ea51c619 | 351 | flag_sp = flag_sp + 1; // スピード変更フラグを+1 |
takuminomura | 48:3003ea51c619 | 352 | } |
yangtzuli | 3:2ae6218973be | 353 | } |
tomotsugu | 8:a47dbf4fa455 | 354 | |
tomotsugu | 8:a47dbf4fa455 | 355 | /* ライントレーススレッド */ |
tomotsugu | 20:02bb875a9b13 | 356 | void trace(){ |
takuminomura | 48:3003ea51c619 | 357 | while(1){ |
takuminomura | 48:3003ea51c619 | 358 | /* 各センサー値読み取り */ |
takuminomura | 48:3003ea51c619 | 359 | int sensor1 = ss1; |
takuminomura | 48:3003ea51c619 | 360 | int sensor2 = ss2; |
takuminomura | 48:3003ea51c619 | 361 | int sensor3 = ss3; |
takuminomura | 48:3003ea51c619 | 362 | int sensor4 = ss4; |
takuminomura | 48:3003ea51c619 | 363 | int sensor5 = ss5; |
mori2020 | 50:8843bee40df5 | 364 | ////*-*-*-5("%d %d %d %d %d \r\n",sensor1,sensor2,sensor3,sensor4,sensor5); |
takuminomura | 48:3003ea51c619 | 365 | int sensD = 0; |
takuminomura | 48:3003ea51c619 | 366 | |
takuminomura | 48:3003ea51c619 | 367 | /* センサー値の決定 */ |
takuminomura | 48:3003ea51c619 | 368 | if(sensor1 > 0) sensD |= 0x10; |
takuminomura | 48:3003ea51c619 | 369 | if(sensor2 > 0) sensD |= 0x08; |
takuminomura | 48:3003ea51c619 | 370 | if(sensor3 > 0) sensD |= 0x04; |
takuminomura | 48:3003ea51c619 | 371 | if(sensor4 > 0) sensD |= 0x02; |
takuminomura | 48:3003ea51c619 | 372 | if(sensor5 > 0) sensD |= 0x01; |
takuminomura | 48:3003ea51c619 | 373 | |
takuminomura | 48:3003ea51c619 | 374 | /* センサー値によって場合分け */ |
takuminomura | 48:3003ea51c619 | 375 | switch(sensArray[sensD]){ |
takuminomura | 48:3003ea51c619 | 376 | case 1: |
takuminomura | 48:3003ea51c619 | 377 | flag_sp = flag_sp % 3 + 6; |
takuminomura | 48:3003ea51c619 | 378 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 379 | run = ADVANCE; // 高速で前進 |
takuminomura | 48:3003ea51c619 | 380 | break; |
takuminomura | 48:3003ea51c619 | 381 | case 2: |
takuminomura | 48:3003ea51c619 | 382 | flag_sp = flag_sp % 3 + 3; |
takuminomura | 48:3003ea51c619 | 383 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 384 | run = RIGHT; // 低速で右折 |
takuminomura | 48:3003ea51c619 | 385 | break; |
takuminomura | 48:3003ea51c619 | 386 | case 3: |
takuminomura | 48:3003ea51c619 | 387 | flag_sp = flag_sp % 3 + 3; |
takuminomura | 48:3003ea51c619 | 388 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 389 | run = LEFT; // 低速で左折 |
takuminomura | 48:3003ea51c619 | 390 | break; |
takuminomura | 48:3003ea51c619 | 391 | case 4: |
takuminomura | 48:3003ea51c619 | 392 | flag_sp = flag_sp % 3; |
takuminomura | 48:3003ea51c619 | 393 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 394 | run = RIGHT; // 中速で右折 |
takuminomura | 48:3003ea51c619 | 395 | break; |
takuminomura | 48:3003ea51c619 | 396 | case 5: |
takuminomura | 48:3003ea51c619 | 397 | flag_sp = flag_sp % 3; |
takuminomura | 48:3003ea51c619 | 398 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 399 | run = LEFT; // 中速で左折 |
takuminomura | 48:3003ea51c619 | 400 | break; |
takuminomura | 48:3003ea51c619 | 401 | case 6: |
takuminomura | 48:3003ea51c619 | 402 | flag_sp = flag_sp % 3 + 6; |
takuminomura | 48:3003ea51c619 | 403 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 404 | run = RIGHT; // 高速で右折 |
takuminomura | 48:3003ea51c619 | 405 | break; |
takuminomura | 48:3003ea51c619 | 406 | case 7: |
takuminomura | 48:3003ea51c619 | 407 | flag_sp = flag_sp % 3 + 6; |
takuminomura | 48:3003ea51c619 | 408 | beforeRun = run; |
takuminomura | 48:3003ea51c619 | 409 | run = LEFT; // 高速で左折 |
takuminomura | 48:3003ea51c619 | 410 | break; |
takuminomura | 48:3003ea51c619 | 411 | default: |
takuminomura | 48:3003ea51c619 | 412 | break; // 前回動作を継続 |
tomotsugu | 18:6cca64c7dbc3 | 413 | } |
takuminomura | 48:3003ea51c619 | 414 | // ThisThread::sleep_for(30); // 30ms待つ |
takuminomura | 48:3003ea51c619 | 415 | ThisThread::sleep_for(3); |
takuminomura | 48:3003ea51c619 | 416 | } |
yangtzuli | 3:2ae6218973be | 417 | } |
yangtzuli | 3:2ae6218973be | 418 | |
tomotsugu | 8:a47dbf4fa455 | 419 | /* 障害物回避走行スレッド */ |
tomotsugu | 20:02bb875a9b13 | 420 | void avoidance(){ |
nishimura_taku_pet | 46:c6deb699160b | 421 | int i; |
yangtzuli | 3:2ae6218973be | 422 | while(1){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 423 | watchsurrounding3(); |
mori2020 | 50:8843bee40df5 | 424 | // //*-*-*-5("%d %d %d %d %d \r\n",SL,SLD,SC,SRD,SR); |
takuminomura | 48:3003ea51c619 | 425 | if(flag_a == 0){ // 障害物がない場合 |
takuminomura | 48:3003ea51c619 | 426 | run = ADVANCE; // 前進 |
takuminomura | 48:3003ea51c619 | 427 | }else{ // 障害物がある場合 |
tomotsugu | 18:6cca64c7dbc3 | 428 | i = 0; |
takuminomura | 48:3003ea51c619 | 429 | if(SC < 15){ // 正面15cm以内に障害物が現れた場合 |
nishimura_taku_pet | 41:3c58a4be1199 | 430 | servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 41:3c58a4be1199 | 431 | ThisThread::sleep_for(100); // 100ms待つ |
takuminomura | 48:3003ea51c619 | 432 | run = BACK; // 後退 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 433 | int cnt_kyori=0; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 434 | int kyori = watch(); |
takuminomura | 48:3003ea51c619 | 435 | while(kyori < limit){ // 正面20cm以内に障害物がある間 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 436 | if(kyori==-1){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 437 | cnt_kyori++; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 438 | if(cnt_kyori>15){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 439 | cnt_kyori=0; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 440 | break; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 441 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 442 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 443 | kyori = watch(); |
tomotsugu | 18:6cca64c7dbc3 | 444 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 445 | /*while(i < 30){ // 正面20cm以内に障害物がある間 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 446 | if(watch() < limit){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 447 | break; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 448 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 449 | i++; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 450 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 451 | i = 0;*/ |
takuminomura | 48:3003ea51c619 | 452 | run = STOP; // 停止 |
yangtzuli | 3:2ae6218973be | 453 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 454 | watchsurrounding5(); |
takuminomura | 48:3003ea51c619 | 455 | if(SC < limit && SLD < limit && SL < limit && SRD < limit && SR < limit){ // 全方向に障害物がある場合 |
takuminomura | 48:3003ea51c619 | 456 | run = LEFT; // 左折 |
nishimura_taku_pet | 28:cb51cafca490 | 457 | while(i < 1){ // 進行方向確認 |
tomotsugu | 18:6cca64c7dbc3 | 458 | if(watch() > limit){ |
tomotsugu | 18:6cca64c7dbc3 | 459 | i++; |
nishimura_taku_pet | 28:cb51cafca490 | 460 | }else{ |
nishimura_taku_pet | 28:cb51cafca490 | 461 | i = 0; |
yangtzuli | 2:38825726cb1b | 462 | } |
yangtzuli | 2:38825726cb1b | 463 | } |
nishimura_taku_pet | 28:cb51cafca490 | 464 | run = STOP; // 停止 |
takuminomura | 48:3003ea51c619 | 465 | }else { // 全方向以外 |
nishimura_taku_pet | 28:cb51cafca490 | 466 | far = SC; // 正面を最も遠い距離に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 467 | houkou = 1; // 進行方向を前に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 468 | if(far < SLD || far < SL){ // 左または左前がより遠い場合 |
nishimura_taku_pet | 28:cb51cafca490 | 469 | if(SL < SLD){ // 左前が左より遠い場合 |
nishimura_taku_pet | 28:cb51cafca490 | 470 | far = SLD; // 左前を最も遠い距離に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 471 | }else{ // 左が左前より遠い場合 |
nishimura_taku_pet | 28:cb51cafca490 | 472 | far = SL; // 左を最も遠い距離に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 473 | } |
nishimura_taku_pet | 28:cb51cafca490 | 474 | houkou = 2; // 進行方向を左に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 475 | } |
nishimura_taku_pet | 28:cb51cafca490 | 476 | if(far < SRD || far < SR){ // 右または右前がより遠い場合 |
nishimura_taku_pet | 28:cb51cafca490 | 477 | if(SR < SRD){ // 右前が右より遠い場合 |
nishimura_taku_pet | 28:cb51cafca490 | 478 | far = SRD; // 右前を最も遠い距離に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 479 | }else{ // 右が右前よりも遠い場合 |
nishimura_taku_pet | 28:cb51cafca490 | 480 | far = SR; // 右を最も遠い距離に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 481 | } |
nishimura_taku_pet | 28:cb51cafca490 | 482 | houkou = 3; // 進行方向を右に設定 |
nishimura_taku_pet | 28:cb51cafca490 | 483 | } |
nishimura_taku_pet | 28:cb51cafca490 | 484 | switch(houkou){ // 進行方向の場合分け |
nishimura_taku_pet | 28:cb51cafca490 | 485 | case 1: // 前の場合 |
nishimura_taku_pet | 28:cb51cafca490 | 486 | run = ADVANCE; // 前進 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 487 | ThisThread::sleep_for(500); // 0.5秒待つ |
nishimura_taku_pet | 28:cb51cafca490 | 488 | break; |
takuminomura | 48:3003ea51c619 | 489 | case 2: // 左の場合 |
nishimura_taku_pet | 28:cb51cafca490 | 490 | run = LEFT; // 左折 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 491 | //int kyori = watch(); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 492 | //int kyori_f=0; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 493 | while(i < 20){ // 進行方向確認 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 494 | /*if(kyori > (far - 2) || kyori_f == 2){ // 正面の計測距離と最も遠い距離が一致したら(誤差-2cm) |
takuminomura | 48:3003ea51c619 | 495 | break; // ループ+ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 496 | }else if(kyori==-1){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 497 | kyori_f++; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 498 | }else{ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 499 | kyori_f = 0; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 500 | i++; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 501 | }*/ |
nishimura_taku_pet | 28:cb51cafca490 | 502 | if(watch() > (far - 2)){ // 正面の計測距離と最も遠い距離が一致したら(誤差-2cm) |
takuminomura | 48:3003ea51c619 | 503 | break; // ループ+ |
nishimura_taku_pet | 28:cb51cafca490 | 504 | }else{ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 505 | i++; |
nishimura_taku_pet | 28:cb51cafca490 | 506 | } |
nishimura_taku_pet | 28:cb51cafca490 | 507 | } |
nishimura_taku_pet | 28:cb51cafca490 | 508 | run = STOP; // 停止 |
nishimura_taku_pet | 28:cb51cafca490 | 509 | break; |
takuminomura | 48:3003ea51c619 | 510 | case 3: // 右の場合 |
nishimura_taku_pet | 28:cb51cafca490 | 511 | run = RIGHT; // 右折 |
nishimura_taku_pet | 45:76e8c07d76ef | 512 | //int kyori = watch(); |
nishimura_taku_pet | 45:76e8c07d76ef | 513 | //int kyori_f=0; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 514 | while(i < 20){ // 進行方向確認 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 515 | /*if(kyori > (far - 2) || kyori_f == 2){ // 正面の計測距離と最も遠い距離が一致したら(誤差-2cm) |
nishimura_taku_pet | 40:75e1ad7c27e4 | 516 | break; // ループ+ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 517 | }else if(kyori==-1){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 518 | kyori_f++; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 519 | }else{ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 520 | kyori_f = 0; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 521 | i++; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 522 | }*/ |
nishimura_taku_pet | 28:cb51cafca490 | 523 | if(watch() > (far - 2)){ // 正面の計測距離と最も遠い距離が一致したら(誤差-2cm) |
takuminomura | 48:3003ea51c619 | 524 | break; // ループ+ |
nishimura_taku_pet | 28:cb51cafca490 | 525 | }else{ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 526 | i++; |
nishimura_taku_pet | 28:cb51cafca490 | 527 | } |
nishimura_taku_pet | 28:cb51cafca490 | 528 | } |
nishimura_taku_pet | 28:cb51cafca490 | 529 | run = STOP; // 停止 |
nishimura_taku_pet | 28:cb51cafca490 | 530 | break; |
nishimura_taku_pet | 28:cb51cafca490 | 531 | } |
yangtzuli | 5:3fffb364744b | 532 | } |
nishimura_taku_pet | 28:cb51cafca490 | 533 | } |
nishimura_taku_pet | 28:cb51cafca490 | 534 | flag_a = 0; // 障害物有無フラグを0にセット |
nishimura_taku_pet | 40:75e1ad7c27e4 | 535 | if(SLD < 29){ // 正面15cm以内に障害物が現れた場合 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 536 | run = RIGHT; // 右折 |
nishimura_taku_pet | 41:3c58a4be1199 | 537 | ThisThread::sleep_for(200); // 100ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 538 | run = STOP; // 停止 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 539 | }else if(SRD < 29){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 540 | run = LEFT; // 左折 |
nishimura_taku_pet | 41:3c58a4be1199 | 541 | ThisThread::sleep_for(200); // 100ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 542 | run = STOP; // 停止 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 543 | } |
yangtzuli | 2:38825726cb1b | 544 | } |
yangtzuli | 2:38825726cb1b | 545 | } |
tomotsugu | 8:a47dbf4fa455 | 546 | |
tomotsugu | 8:a47dbf4fa455 | 547 | /* 距離計測関数 */ |
yangtzuli | 2:38825726cb1b | 548 | int watch(){ |
tomotsugu | 21:68d38e8f64b5 | 549 | do{ |
tomotsugu | 21:68d38e8f64b5 | 550 | trig = 0; |
tomotsugu | 21:68d38e8f64b5 | 551 | ThisThread::sleep_for(5); // 5ms待つ |
tomotsugu | 21:68d38e8f64b5 | 552 | trig = 1; |
tomotsugu | 21:68d38e8f64b5 | 553 | ThisThread::sleep_for(15); // 15ms待つ |
tomotsugu | 21:68d38e8f64b5 | 554 | trig = 0; |
tomotsugu | 21:68d38e8f64b5 | 555 | timer.start(); |
yangtzuli | 17:f7259ab2fe86 | 556 | t1=timer.read_ms(); |
nishimura_taku_pet | 29:600e4b9b5c5b | 557 | while(echo.read() == 0 && t1<10){ |
tomotsugu | 21:68d38e8f64b5 | 558 | t1=timer.read_ms(); |
tomotsugu | 21:68d38e8f64b5 | 559 | led1 = 1; |
tomotsugu | 21:68d38e8f64b5 | 560 | } |
tomotsugu | 21:68d38e8f64b5 | 561 | timer.stop(); |
tomotsugu | 21:68d38e8f64b5 | 562 | timer.reset(); |
nishimura_taku_pet | 28:cb51cafca490 | 563 | /*if((t1-t2) >= 10){ |
nishimura_taku_pet | 28:cb51cafca490 | 564 | run = STOP;*/ |
nishimura_taku_pet | 29:600e4b9b5c5b | 565 | }while(t1 >= 10); |
tomotsugu | 21:68d38e8f64b5 | 566 | timer.start(); // 距離計測タイマースタート |
tomotsugu | 21:68d38e8f64b5 | 567 | while(echo.read() == 1){ |
yangtzuli | 5:3fffb364744b | 568 | } |
tomotsugu | 21:68d38e8f64b5 | 569 | timer.stop(); // 距離計測タイマーストップ |
tomotsugu | 21:68d38e8f64b5 | 570 | DT = (int)(timer.read_us()*0.01657); // 距離計算 |
nishimura_taku_pet | 28:cb51cafca490 | 571 | if(DT > 1000){ |
nishimura_taku_pet | 28:cb51cafca490 | 572 | DT = -1; |
nishimura_taku_pet | 28:cb51cafca490 | 573 | }else if(DT > 150){ // 検知範囲外なら100cmに設定 |
tomotsugu | 22:c6e2a3b9aa14 | 574 | DT = 150; |
yangtzuli | 2:38825726cb1b | 575 | } |
tomotsugu | 21:68d38e8f64b5 | 576 | timer.reset(); // 距離計測タイマーリセット |
tomotsugu | 8:a47dbf4fa455 | 577 | led1 = 0; |
yangtzuli | 2:38825726cb1b | 578 | return DT; |
yangtzuli | 0:0d0037aabe41 | 579 | } |
yangtzuli | 0:0d0037aabe41 | 580 | |
tomotsugu | 8:a47dbf4fa455 | 581 | /* 障害物検知関数 */ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 582 | void watchsurrounding3(){ |
nishimura_taku_pet | 28:cb51cafca490 | 583 | //servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 28:cb51cafca490 | 584 | //ThisThread::sleep_for(200); // 100ms待つ |
yangtzuli | 2:38825726cb1b | 585 | SC = watch(); |
nishimura_taku_pet | 28:cb51cafca490 | 586 | if(SC < limit){ // 正面20cm以内に障害物がある場合 |
takuminomura | 48:3003ea51c619 | 587 | if(SC!=-1){ |
nishimura_taku_pet | 28:cb51cafca490 | 588 | run = STOP; // 停止 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 589 | flag_a = 1; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 590 | return; |
nishimura_taku_pet | 28:cb51cafca490 | 591 | } |
yangtzuli | 2:38825726cb1b | 592 | } |
yangtzuli | 2:38825726cb1b | 593 | servo.pulsewidth_us(1925); // サーボを左に40度回転 |
nishimura_taku_pet | 28:cb51cafca490 | 594 | ThisThread::sleep_for(100); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 595 | SLD = watch(); |
yangtzuli | 2:38825726cb1b | 596 | if(SLD < limit){ // 左前20cm以内に障害物がある場合 |
tomotsugu | 20:02bb875a9b13 | 597 | run = STOP; // 停止 |
nishimura_taku_pet | 28:cb51cafca490 | 598 | flag_a = 1; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 599 | return; |
yangtzuli | 2:38825726cb1b | 600 | } |
tomotsugu | 19:c6f9f010bd9e | 601 | servo.pulsewidth_us(1450); |
nishimura_taku_pet | 42:56022456ef23 | 602 | ThisThread::sleep_for(150); |
tomotsugu | 19:c6f9f010bd9e | 603 | SC = watch(); |
tomotsugu | 19:c6f9f010bd9e | 604 | if(SC < limit){ |
takuminomura | 48:3003ea51c619 | 605 | if(SC!=-1){ |
takuminomura | 48:3003ea51c619 | 606 | run = STOP; // 停止 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 607 | flag_a = 1; |
takuminomura | 48:3003ea51c619 | 608 | return; |
nishimura_taku_pet | 28:cb51cafca490 | 609 | } |
tomotsugu | 19:c6f9f010bd9e | 610 | } |
yangtzuli | 2:38825726cb1b | 611 | servo.pulsewidth_us(925); // サーボを右に40度回転 |
nishimura_taku_pet | 28:cb51cafca490 | 612 | ThisThread::sleep_for(100); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 613 | SRD = watch(); |
yangtzuli | 2:38825726cb1b | 614 | if(SRD < limit){ // 右前20cm以内に障害物がある場合 |
tomotsugu | 20:02bb875a9b13 | 615 | run = STOP; // 停止 |
nishimura_taku_pet | 28:cb51cafca490 | 616 | flag_a = 1; |
nishimura_taku_pet | 40:75e1ad7c27e4 | 617 | return; |
yangtzuli | 2:38825726cb1b | 618 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 619 | servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 40:75e1ad7c27e4 | 620 | ThisThread::sleep_for(100); // 100ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 621 | /*if(SC < limit || SLD < limit || SL < limit || SRD < limit || SR < limit){ // 20cm以内に障害物を検知した場合 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 622 | flag_a = 1; // 障害物有無フラグに1をセット |
nishimura_taku_pet | 40:75e1ad7c27e4 | 623 | }*/ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 624 | } |
nishimura_taku_pet | 40:75e1ad7c27e4 | 625 | |
nishimura_taku_pet | 40:75e1ad7c27e4 | 626 | /* 障害物検知関数 */ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 627 | void watchsurrounding5(){ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 628 | //servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 40:75e1ad7c27e4 | 629 | //ThisThread::sleep_for(200); // 100ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 630 | SC = watch(); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 631 | servo.pulsewidth_us(1925); // サーボを左に40度回転 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 632 | ThisThread::sleep_for(100); // 250ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 633 | SLD = watch(); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 634 | servo.pulsewidth_us(2400); // サーボを左に90度回転 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 635 | ThisThread::sleep_for(100); // 250ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 636 | SL = watch(); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 637 | servo.pulsewidth_us(1450); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 638 | ThisThread::sleep_for(250); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 639 | SC = watch(); |
nishimura_taku_pet | 40:75e1ad7c27e4 | 640 | servo.pulsewidth_us(925); // サーボを右に40度回転 |
nishimura_taku_pet | 40:75e1ad7c27e4 | 641 | ThisThread::sleep_for(100); // 250ms待つ |
nishimura_taku_pet | 40:75e1ad7c27e4 | 642 | SRD = watch(); |
yangtzuli | 2:38825726cb1b | 643 | servo.pulsewidth_us(500); // サーボを右に90度回転 |
nishimura_taku_pet | 28:cb51cafca490 | 644 | ThisThread::sleep_for(100); // 250ms待つ |
yangtzuli | 2:38825726cb1b | 645 | SR = watch(); |
yangtzuli | 2:38825726cb1b | 646 | servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 28:cb51cafca490 | 647 | ThisThread::sleep_for(250); // 100ms待つ |
yangtzuli | 3:2ae6218973be | 648 | } |
yangtzuli | 3:2ae6218973be | 649 | |
tomotsugu | 8:a47dbf4fa455 | 650 | /* ディスプレイ表示関数 */ |
yangtzuli | 3:2ae6218973be | 651 | void display(){ |
tomotsugu | 8:a47dbf4fa455 | 652 | mutex.lock(); // ミューテックスロック |
yangtzuli | 3:2ae6218973be | 653 | lcd.setAddress(0,1); |
tomotsugu | 8:a47dbf4fa455 | 654 | |
tomotsugu | 8:a47dbf4fa455 | 655 | /* 操作モードによる場合分け */ |
yangtzuli | 3:2ae6218973be | 656 | switch(mode){ |
tomotsugu | 8:a47dbf4fa455 | 657 | /* 前進 */ |
yangtzuli | 3:2ae6218973be | 658 | case ADVANCE: |
yangtzuli | 3:2ae6218973be | 659 | lcd.printf("Mode:Advance "); |
yangtzuli | 3:2ae6218973be | 660 | break; |
tomotsugu | 8:a47dbf4fa455 | 661 | /* 右折 */ |
yangtzuli | 3:2ae6218973be | 662 | case RIGHT: |
yangtzuli | 5:3fffb364744b | 663 | lcd.printf("Mode:TurnRight "); |
yangtzuli | 3:2ae6218973be | 664 | break; |
tomotsugu | 8:a47dbf4fa455 | 665 | /* 左折 */ |
yangtzuli | 3:2ae6218973be | 666 | case LEFT: |
yangtzuli | 5:3fffb364744b | 667 | lcd.printf("Mode:TurnLeft "); |
yangtzuli | 3:2ae6218973be | 668 | break; |
tomotsugu | 8:a47dbf4fa455 | 669 | /* 後退 */ |
yangtzuli | 3:2ae6218973be | 670 | case BACK: |
yangtzuli | 3:2ae6218973be | 671 | lcd.printf("Mode:Back "); |
yangtzuli | 3:2ae6218973be | 672 | break; |
tomotsugu | 8:a47dbf4fa455 | 673 | /* 停止 */ |
yangtzuli | 3:2ae6218973be | 674 | case STOP: |
yangtzuli | 3:2ae6218973be | 675 | lcd.printf("Mode:Stop "); |
yangtzuli | 3:2ae6218973be | 676 | break; |
tomotsugu | 8:a47dbf4fa455 | 677 | /* 待ち */ |
yangtzuli | 3:2ae6218973be | 678 | case READY: |
yangtzuli | 3:2ae6218973be | 679 | lcd.printf("Mode:Ready "); |
yangtzuli | 3:2ae6218973be | 680 | break; |
tomotsugu | 8:a47dbf4fa455 | 681 | /* ライントレース */ |
yangtzuli | 3:2ae6218973be | 682 | case LINE_TRACE: |
yangtzuli | 3:2ae6218973be | 683 | lcd.printf("Mode:LineTrace "); |
yangtzuli | 3:2ae6218973be | 684 | break; |
tomotsugu | 8:a47dbf4fa455 | 685 | /* 障害物回避 */ |
yangtzuli | 3:2ae6218973be | 686 | case AVOIDANCE: |
yangtzuli | 3:2ae6218973be | 687 | lcd.printf("Mode:Avoidance "); |
yangtzuli | 3:2ae6218973be | 688 | break; |
tomotsugu | 8:a47dbf4fa455 | 689 | /* スピード制御 */ |
yangtzuli | 3:2ae6218973be | 690 | case SPEED: |
tomotsugu | 8:a47dbf4fa455 | 691 | /* スピードの状態で場合分け */ |
takuminomura | 48:3003ea51c619 | 692 | switch(flag_sp % 3){ |
tomotsugu | 8:a47dbf4fa455 | 693 | /* 普通 */ |
yangtzuli | 3:2ae6218973be | 694 | case(NORMAL): |
yangtzuli | 3:2ae6218973be | 695 | lcd.printf("Speed:Normal "); |
yangtzuli | 3:2ae6218973be | 696 | break; |
tomotsugu | 8:a47dbf4fa455 | 697 | /* 速い */ |
yangtzuli | 3:2ae6218973be | 698 | case(FAST): |
yangtzuli | 3:2ae6218973be | 699 | lcd.printf("Speed:Fast "); |
yangtzuli | 3:2ae6218973be | 700 | break; |
tomotsugu | 8:a47dbf4fa455 | 701 | /* とても速い */ |
yangtzuli | 3:2ae6218973be | 702 | case(VERYFAST): |
yangtzuli | 3:2ae6218973be | 703 | lcd.printf("Speed:VeryFast "); |
yangtzuli | 3:2ae6218973be | 704 | break; |
yangtzuli | 3:2ae6218973be | 705 | } |
tomotsugu | 8:a47dbf4fa455 | 706 | viewTimer.reset(); // タイマーリセット |
tomotsugu | 8:a47dbf4fa455 | 707 | viewTimer.start(); // タイマースタート |
takuminomura | 48:3003ea51c619 | 708 | break; |
yangtzuli | 3:2ae6218973be | 709 | } |
tomotsugu | 8:a47dbf4fa455 | 710 | mutex.unlock(); // ミューテックスアンロック |
yangtzuli | 3:2ae6218973be | 711 | } |
yangtzuli | 3:2ae6218973be | 712 | |
tomotsugu | 8:a47dbf4fa455 | 713 | /* バックライト点滅 */ |
yangtzuli | 3:2ae6218973be | 714 | void lcdBacklight(void const *argument){ |
tomotsugu | 8:a47dbf4fa455 | 715 | if(flag_b == 1){ // バックライト点滅フラグが1なら |
tomotsugu | 8:a47dbf4fa455 | 716 | lcd.setBacklight(TextLCD::LightOn); // バックライトON |
tomotsugu | 8:a47dbf4fa455 | 717 | }else{ // バックライト点滅フラグが0なら |
tomotsugu | 8:a47dbf4fa455 | 718 | lcd.setBacklight(TextLCD::LightOff); // バックライトOFF |
yangtzuli | 3:2ae6218973be | 719 | } |
tomotsugu | 8:a47dbf4fa455 | 720 | flag_b = !flag_b; // バックライト点滅フラグ切り替え |
yangtzuli | 3:2ae6218973be | 721 | } |
yangtzuli | 2:38825726cb1b | 722 | |
tomotsugu | 8:a47dbf4fa455 | 723 | /* バッテリー残量更新関数 */ |
yangtzuli | 5:3fffb364744b | 724 | void bChange(){ |
mori2020 | 50:8843bee40df5 | 725 | ////*-*-*-5(" bChange1\r\n"); |
tomotsugu | 10:d193030ce672 | 726 | b = (int)(((battery.read() * 3.3 - MIN_V)/0.67)*10+0.5)*10; |
tomotsugu | 10:d193030ce672 | 727 | if(b <= 0){ // バッテリー残量0%なら全ての機能停止 |
tomotsugu | 10:d193030ce672 | 728 | b = 0; |
tomotsugu | 10:d193030ce672 | 729 | //lcd.setBacklight(TextLCD::LightOff); |
tomotsugu | 10:d193030ce672 | 730 | //run = STOP; |
tomotsugu | 10:d193030ce672 | 731 | //exit(1); // 電池残量が5%未満の時、LCDを消灯し、モーターを停止し、プログラムを終了する。 |
tomotsugu | 10:d193030ce672 | 732 | } |
tomotsugu | 10:d193030ce672 | 733 | mutex.lock(); // ミューテックスロック |
tomotsugu | 10:d193030ce672 | 734 | lcd.setAddress(0,0); |
tomotsugu | 10:d193030ce672 | 735 | lcd.printf("Battery:%3d%%",b); // バッテリー残量表示 |
takuminomura | 48:3003ea51c619 | 736 | mutex.unlock(); // ミューテックスアンロック |
tomotsugu | 10:d193030ce672 | 737 | if(b <= 30){ // バッテリー残量30%以下なら |
tomotsugu | 10:d193030ce672 | 738 | if(flag_t == 0){ // バックライトタイマーフラグが0なら |
nishimura_taku_pet | 43:243c1455f88a | 739 | //bTimer.attach(lcdBacklight,0.5); |
tomotsugu | 10:d193030ce672 | 740 | bTimer.start(500); // 0.5秒周期でバックライトタイマー割り込み |
tomotsugu | 10:d193030ce672 | 741 | flag_t = 1; // バックライトタイマーフラグを1に切り替え |
yangtzuli | 3:2ae6218973be | 742 | } |
tomotsugu | 10:d193030ce672 | 743 | }else{ |
tomotsugu | 10:d193030ce672 | 744 | if(flag_t == 1){ // バックライトタイマーフラグが1なら |
nishimura_taku_pet | 43:243c1455f88a | 745 | //bTimer.detach(); |
tomotsugu | 10:d193030ce672 | 746 | bTimer.stop(); // バックライトタイマーストップ |
tomotsugu | 10:d193030ce672 | 747 | lcd.setBacklight(TextLCD::LightOn); // バックライトON |
tomotsugu | 10:d193030ce672 | 748 | flag_t = 0; // バックライトタイマーフラグを0に切り替え |
yangtzuli | 3:2ae6218973be | 749 | } |
tomotsugu | 10:d193030ce672 | 750 | } |
yangtzuli | 2:38825726cb1b | 751 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 752 | // Serial Interrupt read ESP data |
nishimura_taku_pet | 24:9481c8f56a49 | 753 | void callback() |
nishimura_taku_pet | 24:9481c8f56a49 | 754 | { |
mori2020 | 50:8843bee40df5 | 755 | ////*-*-*-5("\n\r------------ callback is being called --------------\n\r"); |
nishimura_taku_pet | 24:9481c8f56a49 | 756 | led3=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 757 | while (esp.readable()) { |
nishimura_taku_pet | 24:9481c8f56a49 | 758 | webbuff[ount] = esp.getc(); |
nishimura_taku_pet | 24:9481c8f56a49 | 759 | ount++; |
nishimura_taku_pet | 24:9481c8f56a49 | 760 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 761 | if(strlen(webbuff)>bufflen) { |
mori2020 | 50:8843bee40df5 | 762 | // //*-*-*-5("\f\n\r------------ webbuff over bufflen --------------\n\r"); |
nishimura_taku_pet | 24:9481c8f56a49 | 763 | DataRX=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 764 | led3=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 765 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 766 | } |
takuminomura | 48:3003ea51c619 | 767 | |
nishimura_taku_pet | 43:243c1455f88a | 768 | void wifi(/*void const *argument*/) |
nishimura_taku_pet | 24:9481c8f56a49 | 769 | { |
mori2020 | 50:8843bee40df5 | 770 | //*-*-*-5("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r"); |
nishimura_taku_pet | 33:a6f1090e0174 | 771 | ThisThread::sleep_for(100); |
nishimura_taku_pet | 24:9481c8f56a49 | 772 | led1=1,led2=0,led3=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 773 | timeout=6000; |
nishimura_taku_pet | 24:9481c8f56a49 | 774 | getcount=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 775 | getreply(); |
nishimura_taku_pet | 24:9481c8f56a49 | 776 | esp.baud(115200); // ESP8266 baudrate. Maximum on KLxx' is 115200, 230400 works on K20 and K22F |
nishimura_taku_pet | 24:9481c8f56a49 | 777 | startserver(); |
mori2020 | 49:178dcafb4f0e | 778 | |
nishimura_taku_pet | 24:9481c8f56a49 | 779 | while(1) { |
nishimura_taku_pet | 24:9481c8f56a49 | 780 | if(DataRX==1) { |
mori2020 | 50:8843bee40df5 | 781 | //*-*-*-5("\f\n\r------------ main while > if --------------\n\r"); |
nishimura_taku_pet | 24:9481c8f56a49 | 782 | click_flag = 1; |
nishimura_taku_pet | 24:9481c8f56a49 | 783 | ReadWebData(); |
mori2020 | 50:8843bee40df5 | 784 | //*-*-*-5("\f\n\r------------ click_flag=%d --------------\n\r",click_flag); |
mori2020 | 49:178dcafb4f0e | 785 | //if ((servreq == 1 && weberror == 0) && click_flag == 1) { |
mori2020 | 49:178dcafb4f0e | 786 | if (servreq == 1 && weberror == 0) { |
mori2020 | 50:8843bee40df5 | 787 | //*-*-*-5("\f\n\r------------ befor send page --------------\n\r"); |
nishimura_taku_pet | 24:9481c8f56a49 | 788 | sendpage(); |
nishimura_taku_pet | 24:9481c8f56a49 | 789 | } |
mori2020 | 50:8843bee40df5 | 790 | //*-*-*-5("\f\n\r------------ send_check begin --------------\n\r"); |
mori2020 | 49:178dcafb4f0e | 791 | |
mori2020 | 49:178dcafb4f0e | 792 | //sendcheck(); |
mori2020 | 50:8843bee40df5 | 793 | //*-*-*-5("\f\n\r------------ ssend_check end--------------\n\r"); |
mori2020 | 49:178dcafb4f0e | 794 | |
nishimura_taku_pet | 24:9481c8f56a49 | 795 | esp.attach(&callback); |
mori2020 | 50:8843bee40df5 | 796 | //*-*-*-5(" IPD Data:\r\n\n Link ID = %d,\r\n IPD Header Length = %d \r\n IPD Type = %s\r\n", linkID, ipdLen, type); |
mori2020 | 50:8843bee40df5 | 797 | //*-*-*-5("\n\n HTTP Packet: \n\n%s\n", webdata); |
mori2020 | 50:8843bee40df5 | 798 | //*-*-*-5(" Web Characters sent : %d\n\n", bufl); |
mori2020 | 50:8843bee40df5 | 799 | //*-*-*-5(" -------------------------------------\n\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 800 | servreq=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 801 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 802 | ThisThread::sleep_for(100); |
nishimura_taku_pet | 24:9481c8f56a49 | 803 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 804 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 805 | // Static WEB page |
nishimura_taku_pet | 24:9481c8f56a49 | 806 | void sendpage() |
nishimura_taku_pet | 24:9481c8f56a49 | 807 | { |
nishimura_taku_pet | 24:9481c8f56a49 | 808 | // WEB page data |
mori2020 | 49:178dcafb4f0e | 809 | |
nishimura_taku_pet | 24:9481c8f56a49 | 810 | strcpy(webbuff, "<!DOCTYPE html>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 811 | strcat(webbuff, "<html><head><title>RobotCar</title><meta name='viewport' content='width=device-width'/>"); |
mori2020 | 49:178dcafb4f0e | 812 | //strcat(webbuff, "<meta http-equiv=\"refresh\" content=\"5\"; >"); |
molberry | 38:39db3f7450c2 | 813 | strcat(webbuff, "<style type=\"text/css\">.noselect{ width:100px;height:60px;}.light{ width:100px;height:60px;background-color:#00ff66;}.load{ width: 50px; height: 30px;font-size:10px}</style>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 814 | strcat(webbuff, "</head><body><center><p><strong>Robot Car Remote Controller"); |
nishimura_taku_pet | 24:9481c8f56a49 | 815 | strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level "); |
mori2020 | 49:178dcafb4f0e | 816 | if(b > 30) { //残電量表示 |
mori2020 | 49:178dcafb4f0e | 817 | sprintf(webbuff, "%s%3d", webbuff, b); |
mori2020 | 49:178dcafb4f0e | 818 | } else { //30%より下の場合残電量を赤文字 |
mori2020 | 49:178dcafb4f0e | 819 | strcat(webbuff, "<font color=\"red\">"); |
mori2020 | 49:178dcafb4f0e | 820 | sprintf(webbuff, "%s%3d", webbuff, b); |
mori2020 | 49:178dcafb4f0e | 821 | strcat(webbuff, "</font>"); |
mori2020 | 49:178dcafb4f0e | 822 | } |
mori2020 | 49:178dcafb4f0e | 823 | strcat(webbuff, "%</strong>"); |
mori2020 | 50:8843bee40df5 | 824 | strcat(webbuff, "<button id=\"reloadbtn\" type=\"button\" class=\"load\" onclick=\"location.reload()\">RELOAD</button>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 825 | strcat(webbuff, "</td></p>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 826 | strcat(webbuff, "<br>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 827 | strcat(webbuff, "<table><tr><td></td><td>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 828 | |
molberry | 35:4cda290bdb87 | 829 | switch(mode) { //ブラウザ更新時の現在の車の状態からボタンの点灯判定 |
molberry | 35:4cda290bdb87 | 830 | case ADVANCE: //前進 |
mori2020 | 50:8843bee40df5 | 831 | strcat(webbuff, "<button id='gobtn' type='button' class=\"light\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 832 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 833 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 834 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 835 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 836 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 837 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 838 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 839 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 840 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 841 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 842 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 843 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 844 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 845 | break; |
molberry | 35:4cda290bdb87 | 846 | case LEFT: //左折 |
mori2020 | 50:8843bee40df5 | 847 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 848 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 849 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"light\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 850 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 851 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 852 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 853 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 854 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 855 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 856 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 857 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 858 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 859 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 860 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 861 | break; |
molberry | 35:4cda290bdb87 | 862 | case STOP: //停止 |
mori2020 | 50:8843bee40df5 | 863 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 864 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 865 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 866 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 867 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"light\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 868 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 869 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 870 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 871 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 872 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 873 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 874 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 875 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 876 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 877 | break; |
molberry | 35:4cda290bdb87 | 878 | case RIGHT: //右折 |
mori2020 | 50:8843bee40df5 | 879 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 880 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 881 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 882 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 883 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 884 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 885 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"light\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 886 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 887 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 888 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 889 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 890 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 891 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 892 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 893 | break; |
molberry | 35:4cda290bdb87 | 894 | case BACK: //後進 |
mori2020 | 50:8843bee40df5 | 895 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 896 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 897 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 898 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 899 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 900 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 901 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 902 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 903 | strcat(webbuff, "<button id='backbtn' type='button' class=\"light\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 904 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr><td>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 905 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 906 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 907 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 908 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 909 | break; |
molberry | 35:4cda290bdb87 | 910 | case AVOIDANCE: //障害物回避 |
mori2020 | 50:8843bee40df5 | 911 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 912 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 913 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 914 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 915 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 916 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 917 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 918 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 919 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 920 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 921 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 922 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"light\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 923 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 924 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 925 | break; |
molberry | 35:4cda290bdb87 | 926 | case LINE_TRACE: //ライントレース |
mori2020 | 50:8843bee40df5 | 927 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 928 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 929 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 930 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 931 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 932 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 933 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 934 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 935 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 936 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 937 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 938 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 939 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 940 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"light\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 941 | break; |
molberry | 35:4cda290bdb87 | 942 | default: //その他 |
mori2020 | 50:8843bee40df5 | 943 | strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.value)'>GO"); |
nishimura_taku_pet | 24:9481c8f56a49 | 944 | strcat(webbuff, "</button></td><td></td></tr><tr><td>"); |
mori2020 | 50:8843bee40df5 | 945 | strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.value)' >LEFT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 946 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 947 | strcat(webbuff, "<button id='stopbtn' type='button' class=\"noselect\" value=\"STOP\" onClick='send_mes(this.value)' >STOP"); |
nishimura_taku_pet | 24:9481c8f56a49 | 948 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 949 | strcat(webbuff, "<button id='rightbtn' type='button' class=\"noselect\" value=\"RIGHT\" onClick='send_mes(this.value)' >RIGHT"); |
nishimura_taku_pet | 24:9481c8f56a49 | 950 | strcat(webbuff, "</button></td></tr><td></td><td>"); |
mori2020 | 50:8843bee40df5 | 951 | strcat(webbuff, "<button id='backbtn' type='button' class=\"noselect\" value=\"BACK\" onClick='send_mes(this.value)' >BACK"); |
nishimura_taku_pet | 24:9481c8f56a49 | 952 | strcat(webbuff, "</button></td><td style='vertical-align:top; text-align:right;'></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 953 | strcat(webbuff, "<strong>Mode</strong>"); |
mori2020 | 50:8843bee40df5 | 954 | strcat(webbuff, "<table><tr><td><button id='avoidbtn' type='button' class=\"noselect\" value=\"AVOIDANCE\" onClick='send_mes(this.value)' >"); |
nishimura_taku_pet | 24:9481c8f56a49 | 955 | strcat(webbuff, "AVOIDANCE</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 956 | strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.value)' >LINE_TRACE"); |
nishimura_taku_pet | 24:9481c8f56a49 | 957 | break; |
nishimura_taku_pet | 24:9481c8f56a49 | 958 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 959 | strcat(webbuff, "</button></td></tr></table>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 960 | strcat(webbuff, "<strong>Speed</strong>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 961 | strcat(webbuff, "<table><tr><td>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 962 | //ready示速度だけ点灯 |
molberry | 35:4cda290bdb87 | 963 | switch (flag_sp) { //現在の速度のボタン表示 |
molberry | 35:4cda290bdb87 | 964 | case 0: //ノーマル |
mori2020 | 50:8843bee40df5 | 965 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"light\" value=\"Normal\" onClick='send_mes_spe(this.value)' >Normal"); |
nishimura_taku_pet | 24:9481c8f56a49 | 966 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 967 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"Fast\" onClick='send_mes_spe(this.value)' >Fast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 968 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 969 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"VeryFast\" onClick='send_mes_spe(this.value)' >VeryFast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 970 | break; |
molberry | 35:4cda290bdb87 | 971 | case 1: //ファスト |
mori2020 | 50:8843bee40df5 | 972 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"Normal\" onClick='send_mes_spe(this.value)' >Normal"); |
nishimura_taku_pet | 24:9481c8f56a49 | 973 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 974 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"light\" value=\"Fast\" onClick='send_mes_spe(this.value)' >Fast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 975 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 976 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"VeryFast\" onClick='send_mes_spe(this.value)' >VeryFast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 977 | break; |
molberry | 35:4cda290bdb87 | 978 | case 2: //ベリーファスト |
mori2020 | 50:8843bee40df5 | 979 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"Normal\" onClick='send_mes_spe(this.value)' >Normal"); |
nishimura_taku_pet | 24:9481c8f56a49 | 980 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 981 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"Fast\" onClick='send_mes_spe(this.value)' >Fast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 982 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 983 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"light\" value=\"VeryFast\" onClick='send_mes_spe(this.value)' >VeryFast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 984 | break; |
molberry | 35:4cda290bdb87 | 985 | default: //その他 |
mori2020 | 50:8843bee40df5 | 986 | strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"Normal\" onClick='send_mes_spe(this.value)' >Normal"); |
nishimura_taku_pet | 24:9481c8f56a49 | 987 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 988 | strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"Fast\" onClick='send_mes_spe(this.value)' >Fast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 989 | strcat(webbuff, "</button></td><td>"); |
mori2020 | 50:8843bee40df5 | 990 | strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"VeryFast\" onClick='send_mes_spe(this.value)' >VeryFast"); |
nishimura_taku_pet | 24:9481c8f56a49 | 991 | break; |
nishimura_taku_pet | 24:9481c8f56a49 | 992 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 993 | strcat(webbuff, "</button></td></tr></table>"); |
mori2020 | 49:178dcafb4f0e | 994 | |
nishimura_taku_pet | 24:9481c8f56a49 | 995 | strcat(webbuff, "</center>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 996 | strcat(webbuff, "</body>"); |
nishimura_taku_pet | 24:9481c8f56a49 | 997 | strcat(webbuff, "</html>"); |
mori2020 | 49:178dcafb4f0e | 998 | |
molberry | 35:4cda290bdb87 | 999 | strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); //機能 |
mori2020 | 49:178dcafb4f0e | 1000 | |
mori2020 | 49:178dcafb4f0e | 1001 | strcat(webbuff, "var button_9 = document.getElementsByTagName(\"button\");"); |
mori2020 | 49:178dcafb4f0e | 1002 | |
mori2020 | 49:178dcafb4f0e | 1003 | //ボタン入力時それぞれの関数から呼び出されサーバーとの通信を行う |
nishimura_taku_pet | 24:9481c8f56a49 | 1004 | strcat(webbuff, "function htmlacs(url) {"); |
mori2020 | 49:178dcafb4f0e | 1005 | strcat(webbuff, "for(var m=0;m<11;m++){button_9[m].disabled=true;}"); |
mori2020 | 49:178dcafb4f0e | 1006 | strcat(webbuff, "var xhr = new XMLHttpRequest();"); |
mori2020 | 49:178dcafb4f0e | 1007 | strcat(webbuff, "xhr.open(\"GET\", url);"); |
mori2020 | 49:178dcafb4f0e | 1008 | strcat(webbuff, "xhr.onreadystatechange = function(){"); |
mori2020 | 49:178dcafb4f0e | 1009 | //strcat(webbuff, "if(this.readyState == 4 && this.status == 200){"); |
mori2020 | 49:178dcafb4f0e | 1010 | strcat(webbuff, "if(this.readyState == 4){"); |
mori2020 | 50:8843bee40df5 | 1011 | strcat(webbuff, "for(var m=0;m<11;m++){button_9[m].disabled=false;}"); |
mori2020 | 49:178dcafb4f0e | 1012 | strcat(webbuff, "}"); |
mori2020 | 49:178dcafb4f0e | 1013 | strcat(webbuff, "};"); |
mori2020 | 49:178dcafb4f0e | 1014 | strcat(webbuff, "xhr.send(\"\");"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1015 | strcat(webbuff, "}"); |
mori2020 | 49:178dcafb4f0e | 1016 | |
mori2020 | 50:8843bee40df5 | 1017 | //mode変更ボタン入力時動作 //sendmes |
mori2020 | 50:8843bee40df5 | 1018 | strcat(webbuff, "function send_mes(btnval){"); //mode変更ボタン入力時の点灯消灯判定 |
nishimura_taku_pet | 24:9481c8f56a49 | 1019 | strcat(webbuff, "console.log(btnval);"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1020 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1021 | strcat(webbuff, "htmlacs(url);"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1022 | strcat(webbuff, "console.log(url);"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1023 | strcat(webbuff, "var buttons = document.getElementsByTagName(\"button\");"); |
nishimura_taku_pet | 43:243c1455f88a | 1024 | strcat(webbuff, "for(var i=1;i<8;i++){"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1025 | strcat(webbuff, "if(buttons[i].value == btnval){"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1026 | strcat(webbuff, "buttons[i].className=\"light\";"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1027 | strcat(webbuff, "}else{"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1028 | strcat(webbuff, "buttons[i].className=\"noselect\";"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1029 | strcat(webbuff, "}"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1030 | strcat(webbuff, "}"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1031 | strcat(webbuff, "}"); |
mori2020 | 49:178dcafb4f0e | 1032 | |
mori2020 | 50:8843bee40df5 | 1033 | strcat(webbuff, "function send_mes_spe(btnval){"); //speed変更ボタン入力時の点灯消灯判定 |
nishimura_taku_pet | 24:9481c8f56a49 | 1034 | strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1035 | strcat(webbuff, "htmlacs(url);"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1036 | strcat(webbuff, "console.log(url);"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1037 | strcat(webbuff, "var buttons = document.getElementsByTagName(\"button\");"); |
nishimura_taku_pet | 43:243c1455f88a | 1038 | strcat(webbuff, "for(var i=8;i<11;i++){"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1039 | strcat(webbuff, "if(buttons[i].value == btnval){"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1040 | strcat(webbuff, "buttons[i].className=\"light\";"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1041 | strcat(webbuff, "}else{"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1042 | strcat(webbuff, "buttons[i].className=\"noselect\";"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1043 | strcat(webbuff, "}"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1044 | strcat(webbuff, "}"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1045 | strcat(webbuff, "}"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1046 | strcat(webbuff, "</script>"); |
mori2020 | 49:178dcafb4f0e | 1047 | |
mori2020 | 49:178dcafb4f0e | 1048 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1049 | // end of WEB page data |
nishimura_taku_pet | 24:9481c8f56a49 | 1050 | bufl = strlen(webbuff); // get total page buffer length |
mori2020 | 49:178dcafb4f0e | 1051 | //sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length. |
nishimura_taku_pet | 24:9481c8f56a49 | 1052 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1053 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl>2048?2048:bufl)); // send IPD link channel and buffer character length. |
nishimura_taku_pet | 24:9481c8f56a49 | 1054 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1055 | getcount=40; |
nishimura_taku_pet | 24:9481c8f56a49 | 1056 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1057 | getreply(); |
mori2020 | 50:8843bee40df5 | 1058 | //*-*-*-5(replybuff); |
mori2020 | 50:8843bee40df5 | 1059 | ////*-*-*-5("\n++++++++++ AT+CIPSENDBUF=%d,%d+++++++++\r\n", linkID, (bufl>2048?2048:bufl)); |
mori2020 | 49:178dcafb4f0e | 1060 | |
mori2020 | 50:8843bee40df5 | 1061 | //*-*-*-5("\n++++++++++ bufl is %d ++++++++++\r\n",bufl); |
mori2020 | 49:178dcafb4f0e | 1062 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1063 | //pastthrough mode |
nishimura_taku_pet | 24:9481c8f56a49 | 1064 | SendWEB(); // send web page |
mori2020 | 50:8843bee40df5 | 1065 | //*-*-*-5("\n++++++++++ webbuff clear ++++++++++\r\n"); |
mori2020 | 49:178dcafb4f0e | 1066 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1067 | memset(webbuff, '\0', sizeof(webbuff)); |
nishimura_taku_pet | 24:9481c8f56a49 | 1068 | sendcheck(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1069 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1070 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1071 | // Large WEB buffer data send |
nishimura_taku_pet | 24:9481c8f56a49 | 1072 | void SendWEB() |
nishimura_taku_pet | 24:9481c8f56a49 | 1073 | { |
nishimura_taku_pet | 24:9481c8f56a49 | 1074 | int i=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 1075 | if(esp.writeable()) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1076 | while(webbuff[i]!='\0') { |
nishimura_taku_pet | 24:9481c8f56a49 | 1077 | esp.putc(webbuff[i]); |
mori2020 | 49:178dcafb4f0e | 1078 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1079 | //**** |
nishimura_taku_pet | 24:9481c8f56a49 | 1080 | //output at command when 2000 |
nishimura_taku_pet | 24:9481c8f56a49 | 1081 | if(((i%2047)==0) && (i>0)) { |
mori2020 | 49:178dcafb4f0e | 1082 | //wait_ms(10); |
takuminomura | 48:3003ea51c619 | 1083 | ThisThread::sleep_for(100); |
mori2020 | 49:178dcafb4f0e | 1084 | sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl-2048)>2048?2048:(bufl-2048)); // send IPD link channel and buffer character length. |
mori2020 | 50:8843bee40df5 | 1085 | ////*-*-*-5("\r\n++++++++++ AT+CIPSENDBUF=%d,%d ++++++++++\r\n", linkID, (bufl-2048)>2048?2048:(bufl-2048)); |
nishimura_taku_pet | 24:9481c8f56a49 | 1086 | timeout=600; |
nishimura_taku_pet | 24:9481c8f56a49 | 1087 | getcount=50; |
nishimura_taku_pet | 24:9481c8f56a49 | 1088 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1089 | getreply(); |
mori2020 | 50:8843bee40df5 | 1090 | ////*-*-*-5(replybuff); |
mori2020 | 50:8843bee40df5 | 1091 | ////*-*-*-5("\r\n+++++++++++++++++++\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1092 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1093 | //**** |
nishimura_taku_pet | 24:9481c8f56a49 | 1094 | i++; |
mori2020 | 50:8843bee40df5 | 1095 | ////*-*-*-5("%c",webbuff[i]); |
nishimura_taku_pet | 24:9481c8f56a49 | 1096 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1097 | } |
mori2020 | 50:8843bee40df5 | 1098 | //*-*-*-5("\n++++++++++ send web i= %dinfo ++++++++++\r\n",i); |
nishimura_taku_pet | 24:9481c8f56a49 | 1099 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1100 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1101 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1102 | void sendcheck() |
nishimura_taku_pet | 24:9481c8f56a49 | 1103 | { |
nishimura_taku_pet | 24:9481c8f56a49 | 1104 | weberror=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1105 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1106 | getcount=24; |
nishimura_taku_pet | 24:9481c8f56a49 | 1107 | time2.reset(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1108 | time2.start(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1109 | |
mori2020 | 49:178dcafb4f0e | 1110 | /* |
mori2020 | 49:178dcafb4f0e | 1111 | while(weberror==1 && time2.read() <5) { |
mori2020 | 49:178dcafb4f0e | 1112 | getreply(); |
mori2020 | 49:178dcafb4f0e | 1113 | if (strstr(replybuff, "SEND OK") != NULL) { |
mori2020 | 49:178dcafb4f0e | 1114 | weberror=0; // wait for valid SEND OK |
mori2020 | 49:178dcafb4f0e | 1115 | } |
mori2020 | 49:178dcafb4f0e | 1116 | } |
mori2020 | 49:178dcafb4f0e | 1117 | */ |
nishimura_taku_pet | 24:9481c8f56a49 | 1118 | if(weberror==1) { // restart connection |
nishimura_taku_pet | 24:9481c8f56a49 | 1119 | strcpy(cmdbuff, "AT+CIPMUX=1\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1120 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1121 | getcount=10; |
nishimura_taku_pet | 24:9481c8f56a49 | 1122 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1123 | getreply(); |
mori2020 | 50:8843bee40df5 | 1124 | //*-*-*-5(replybuff); |
nishimura_taku_pet | 24:9481c8f56a49 | 1125 | sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port); |
nishimura_taku_pet | 24:9481c8f56a49 | 1126 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1127 | getcount=10; |
nishimura_taku_pet | 24:9481c8f56a49 | 1128 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1129 | getreply(); |
mori2020 | 50:8843bee40df5 | 1130 | //*-*-*-5(replybuff); |
nishimura_taku_pet | 24:9481c8f56a49 | 1131 | } else { |
nishimura_taku_pet | 24:9481c8f56a49 | 1132 | sprintf(cmdbuff, "AT+CIPCLOSE=%s\r\n",channel); // close current connection |
nishimura_taku_pet | 24:9481c8f56a49 | 1133 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1134 | getreply(); |
mori2020 | 50:8843bee40df5 | 1135 | //*-*-*-5(replybuff); |
nishimura_taku_pet | 24:9481c8f56a49 | 1136 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1137 | time2.reset(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1138 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1139 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1140 | // Reads and processes GET and POST web data |
nishimura_taku_pet | 24:9481c8f56a49 | 1141 | void ReadWebData() |
nishimura_taku_pet | 24:9481c8f56a49 | 1142 | { |
mori2020 | 50:8843bee40df5 | 1143 | //*-*-*-5("+++++++++++++++++Read Web Data+++++++++++++++++++++\r\n"); |
nishimura_taku_pet | 30:c80da0ecc260 | 1144 | ThisThread::sleep_for(200); |
nishimura_taku_pet | 24:9481c8f56a49 | 1145 | esp.attach(NULL); |
nishimura_taku_pet | 24:9481c8f56a49 | 1146 | ount=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 1147 | DataRX=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 1148 | weberror=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 1149 | memset(webdata, '\0', sizeof(webdata)); |
nishimura_taku_pet | 24:9481c8f56a49 | 1150 | int x = strcspn (webbuff,"+"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1151 | if(x) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1152 | strcpy(webdata, webbuff + x); |
nishimura_taku_pet | 24:9481c8f56a49 | 1153 | weberror=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 1154 | int numMatched = sscanf(webdata,"+IPD,%d,%d:%s", &linkID, &ipdLen, type); |
mori2020 | 49:178dcafb4f0e | 1155 | //int i=0; |
mori2020 | 50:8843bee40df5 | 1156 | //*-*-*-5("+++++++++++++++++succed rec begin+++++++++++++++++++++\r\n"); |
mori2020 | 50:8843bee40df5 | 1157 | //*-*-*-5("%s",webdata); |
mori2020 | 50:8843bee40df5 | 1158 | //*-*-*-5("+++++++++++++++++succed rec end+++++++++++++++++++++\r\n"); |
nishimura_taku_pet | 43:243c1455f88a | 1159 | if( strstr(webdata, "Normal") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1160 | //*-*-*-5("++++++++++++++++++Normal++++++++++++++++++++"); |
nishimura_taku_pet | 43:243c1455f88a | 1161 | mode = SPEED; // スピードモード |
nishimura_taku_pet | 43:243c1455f88a | 1162 | flag_sp = 0; |
nishimura_taku_pet | 43:243c1455f88a | 1163 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 43:243c1455f88a | 1164 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
nishimura_taku_pet | 43:243c1455f88a | 1165 | }else if( strstr(webdata, "VeryFast") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1166 | //*-*-*-5("+++++++++++++++++++VeryFast+++++++++++++++++++"); |
nishimura_taku_pet | 43:243c1455f88a | 1167 | mode = SPEED; // スピードモード |
nishimura_taku_pet | 43:243c1455f88a | 1168 | flag_sp = 2; |
nishimura_taku_pet | 43:243c1455f88a | 1169 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 43:243c1455f88a | 1170 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
nishimura_taku_pet | 43:243c1455f88a | 1171 | }else if( strstr(webdata, "Fast") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1172 | //*-*-*-5("++++++++++++++++++++Fast++++++++++++++++++"); |
nishimura_taku_pet | 43:243c1455f88a | 1173 | mode = SPEED; // スピードモード |
nishimura_taku_pet | 43:243c1455f88a | 1174 | flag_sp = 1; |
nishimura_taku_pet | 43:243c1455f88a | 1175 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 43:243c1455f88a | 1176 | mode = beforeMode; // 現在のモードに前回のモードを設定 |
nishimura_taku_pet | 43:243c1455f88a | 1177 | }else{ |
nishimura_taku_pet | 43:243c1455f88a | 1178 | beforeMode = mode; |
nishimura_taku_pet | 43:243c1455f88a | 1179 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1180 | if( strstr(webdata, "GO") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1181 | //*-*-*-5("+++++++++++++++++前進+++++++++++++++++++++\r\n"); |
yangtzuli | 37:0cde453dce7d | 1182 | //delete avoi_thread; //障害物回避スレッド停止 |
yangtzuli | 37:0cde453dce7d | 1183 | //delete trace_thread; //ライントレーススレッド停止 |
molberry | 35:4cda290bdb87 | 1184 | run = ADVANCE; // 前進 |
molberry | 35:4cda290bdb87 | 1185 | mode = ADVANCE; // モード変更 |
molberry | 35:4cda290bdb87 | 1186 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1187 | } |
mori2020 | 49:178dcafb4f0e | 1188 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1189 | if( strstr(webdata, "LEFT") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1190 | //*-*-*-5("+++++++++++++++++左折+++++++++++++++++++++\r\n"); |
yangtzuli | 37:0cde453dce7d | 1191 | //delete avoi_thread; //障害物回避スレッド停止 |
yangtzuli | 37:0cde453dce7d | 1192 | //delete trace_thread; //ライントレーススレッド停止 |
molberry | 35:4cda290bdb87 | 1193 | run = LEFT; // 左折 |
molberry | 35:4cda290bdb87 | 1194 | mode = LEFT; // モード変更 |
molberry | 35:4cda290bdb87 | 1195 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1196 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1197 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1198 | if( strstr(webdata, "STOP") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1199 | //*-*-*-5("+++++++++++++++++停止+++++++++++++++++++++\r\n"); |
yangtzuli | 37:0cde453dce7d | 1200 | //delete avoi_thread; //障害物回避スレッド停止 |
yangtzuli | 37:0cde453dce7d | 1201 | //delete trace_thread; //ライントレーススレッド停止 |
molberry | 35:4cda290bdb87 | 1202 | run = STOP; // 停止 |
molberry | 35:4cda290bdb87 | 1203 | mode = STOP; // モード変更 |
molberry | 35:4cda290bdb87 | 1204 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1205 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1206 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1207 | if( strstr(webdata, "RIGHT") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1208 | //*-*-*-5("+++++++++++++++++右折+++++++++++++++++++++\r\n"); |
yangtzuli | 37:0cde453dce7d | 1209 | //delete avoi_thread; //障害物回避スレッド停止 |
yangtzuli | 37:0cde453dce7d | 1210 | //delete trace_thread; //ライントレーススレッド停止 |
molberry | 35:4cda290bdb87 | 1211 | run = RIGHT; // 右折 |
molberry | 35:4cda290bdb87 | 1212 | mode = RIGHT; // モード変更 |
molberry | 35:4cda290bdb87 | 1213 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1214 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1215 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1216 | if( strstr(webdata, "BACK") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1217 | //*-*-*-5("+++++++++++++++++後進+++++++++++++++++++++\r\n"); |
yangtzuli | 37:0cde453dce7d | 1218 | //delete avoi_thread; //障害物回避スレッド停止 |
yangtzuli | 37:0cde453dce7d | 1219 | //delete trace_thread; //ライントレーススレッド停止 |
molberry | 35:4cda290bdb87 | 1220 | run = BACK; // 後進 |
molberry | 35:4cda290bdb87 | 1221 | mode = BACK; // モード変更 |
molberry | 35:4cda290bdb87 | 1222 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1223 | } |
mori2020 | 50:8843bee40df5 | 1224 | //*-*-*-5("+++++++++++++++++succed+++++++++++++++++++++"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1225 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1226 | if( strstr(webdata, "AVOIDANCE") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1227 | //*-*-*-5("+++++++++++++++++AVOIDANCE+++++++++++++++++++++"); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1228 | if(avoi_thread->get_state() == Thread::Deleted) { |
molberry | 35:4cda290bdb87 | 1229 | delete avoi_thread; //障害物回避スレッド停止 |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1230 | avoi_thread = new Thread(avoidance); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1231 | avoi_thread -> set_priority(osPriorityHigh); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1232 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1233 | mode=AVOIDANCE; |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1234 | run = ADVANCE; |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1235 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1236 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1237 | if( strstr(webdata, "LINE_TRACE") != NULL ) { |
mori2020 | 50:8843bee40df5 | 1238 | //*-*-*-5("+++++++++++++++++LINET RACE+++++++++++++++++++++"); |
mori2020 | 50:8843bee40df5 | 1239 | //*-*-*-5("mode = LINE_TRACE\r\n"); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1240 | if(trace_thread->get_state() == Thread::Deleted) { |
molberry | 35:4cda290bdb87 | 1241 | delete trace_thread; //ライントレーススレッド停止 |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1242 | trace_thread = new Thread(trace); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1243 | trace_thread -> set_priority(osPriorityHigh); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1244 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1245 | mode=LINE_TRACE; |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1246 | display(); // ディスプレイ表示 |
nishimura_taku_pet | 24:9481c8f56a49 | 1247 | } |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1248 | if(mode != LINE_TRACE && trace_thread->get_state() != Thread::Deleted){ |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1249 | trace_thread->terminate(); |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1250 | } |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1251 | if(mode != AVOIDANCE && avoi_thread->get_state() != Thread::Deleted){ |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1252 | avoi_thread->terminate(); |
nishimura_taku_pet | 31:3665282561d6 | 1253 | servo.pulsewidth_us(1450); // サーボを中央位置に戻す |
nishimura_taku_pet | 26:0badbc9f9cb3 | 1254 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1255 | sprintf(channel, "%d",linkID); |
nishimura_taku_pet | 24:9481c8f56a49 | 1256 | if (strstr(webdata, "GET") != NULL) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1257 | servreq=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1258 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1259 | if (strstr(webdata, "POST") != NULL) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1260 | servreq=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1261 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1262 | webcounter++; |
nishimura_taku_pet | 24:9481c8f56a49 | 1263 | sprintf(webcount, "%d",webcounter); |
nishimura_taku_pet | 24:9481c8f56a49 | 1264 | } else { |
nishimura_taku_pet | 24:9481c8f56a49 | 1265 | memset(webbuff, '\0', sizeof(webbuff)); |
nishimura_taku_pet | 24:9481c8f56a49 | 1266 | esp.attach(&callback); |
nishimura_taku_pet | 24:9481c8f56a49 | 1267 | weberror=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1268 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1269 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1270 | // Starts and restarts webserver if errors detected. |
nishimura_taku_pet | 24:9481c8f56a49 | 1271 | void startserver() |
nishimura_taku_pet | 24:9481c8f56a49 | 1272 | { |
mori2020 | 50:8843bee40df5 | 1273 | //*-*-*-5("++++++++++ Resetting ESP ++++++++++\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1274 | strcpy(cmdbuff,"AT+RST\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1275 | timeout=8000; |
nishimura_taku_pet | 24:9481c8f56a49 | 1276 | getcount=1000; |
nishimura_taku_pet | 24:9481c8f56a49 | 1277 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1278 | getreply(); |
mori2020 | 50:8843bee40df5 | 1279 | //*-*-*-5(replybuff); |
mori2020 | 50:8843bee40df5 | 1280 | //*-*-*-5("%d",ount); |
nishimura_taku_pet | 24:9481c8f56a49 | 1281 | if (strstr(replybuff, "OK") != NULL) { |
mori2020 | 50:8843bee40df5 | 1282 | //*-*-*-5("\n++++++++++ Starting Server ++++++++++\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1283 | strcpy(cmdbuff, "AT+CIPMUX=1\r\n"); // set multiple connections. |
nishimura_taku_pet | 24:9481c8f56a49 | 1284 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1285 | getcount=20; |
nishimura_taku_pet | 24:9481c8f56a49 | 1286 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1287 | getreply(); |
mori2020 | 50:8843bee40df5 | 1288 | //*-*-*-5(replybuff); |
nishimura_taku_pet | 24:9481c8f56a49 | 1289 | sprintf(cmdbuff,"AT+CIPSERVER=1,%d\r\n", port); |
nishimura_taku_pet | 24:9481c8f56a49 | 1290 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1291 | getcount=20; |
nishimura_taku_pet | 24:9481c8f56a49 | 1292 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1293 | getreply(); |
mori2020 | 50:8843bee40df5 | 1294 | //*-*-*-5(replybuff); |
nishimura_taku_pet | 33:a6f1090e0174 | 1295 | ThisThread::sleep_for(500); |
nishimura_taku_pet | 24:9481c8f56a49 | 1296 | sprintf(cmdbuff,"AT+CIPSTO=%d\r\n",SERVtimeout); |
nishimura_taku_pet | 24:9481c8f56a49 | 1297 | timeout=500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1298 | getcount=50; |
nishimura_taku_pet | 24:9481c8f56a49 | 1299 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1300 | getreply(); |
mori2020 | 50:8843bee40df5 | 1301 | //*-*-*-5(replybuff); |
nishimura_taku_pet | 25:8ed98982faa7 | 1302 | ThisThread::sleep_for(5000); |
mori2020 | 50:8843bee40df5 | 1303 | //*-*-*-5("\n Getting Server IP \r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1304 | strcpy(cmdbuff, "AT+CIFSR\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1305 | timeout=2500; |
nishimura_taku_pet | 24:9481c8f56a49 | 1306 | getcount=200; |
nishimura_taku_pet | 24:9481c8f56a49 | 1307 | while(weberror==0) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1308 | SendCMD(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1309 | getreply(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1310 | if (strstr(replybuff, "0.0.0.0") == NULL) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1311 | weberror=1; // wait for valid IP |
nishimura_taku_pet | 24:9481c8f56a49 | 1312 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1313 | } |
mori2020 | 50:8843bee40df5 | 1314 | //*-*-*-5("\n Enter WEB address (IP) found below in your browser \r\n\n"); |
mori2020 | 50:8843bee40df5 | 1315 | //*-*-*-5("\n The MAC address is also shown below,if it is needed \r\n\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1316 | replybuff[strlen(replybuff)-1] = '\0'; |
mori2020 | 49:178dcafb4f0e | 1317 | //char* IP = replybuff + 5; |
nishimura_taku_pet | 24:9481c8f56a49 | 1318 | sprintf(webdata,"%s", replybuff); |
mori2020 | 50:8843bee40df5 | 1319 | //*-*-*-5(webdata); |
nishimura_taku_pet | 24:9481c8f56a49 | 1320 | led2=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1321 | bufflen=200; |
mori2020 | 49:178dcafb4f0e | 1322 | //bufflen=100; |
nishimura_taku_pet | 24:9481c8f56a49 | 1323 | ount=0; |
mori2020 | 50:8843bee40df5 | 1324 | //*-*-*-5("\n\n++++++++++ Ready ++++++++++\r\n\n"); |
nishimura_taku_pet | 33:a6f1090e0174 | 1325 | setup(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1326 | esp.attach(&callback); |
nishimura_taku_pet | 24:9481c8f56a49 | 1327 | } else { |
mori2020 | 50:8843bee40df5 | 1328 | //*-*-*-5("\n++++++++++ ESP8266 error, check power/connections ++++++++++\r\n"); |
nishimura_taku_pet | 24:9481c8f56a49 | 1329 | led1=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1330 | led2=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1331 | led3=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1332 | led4=1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1333 | while(1) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1334 | led1=!led1; |
nishimura_taku_pet | 24:9481c8f56a49 | 1335 | led2=!led2; |
nishimura_taku_pet | 24:9481c8f56a49 | 1336 | led3=!led3; |
nishimura_taku_pet | 24:9481c8f56a49 | 1337 | led4=!led4; |
nishimura_taku_pet | 25:8ed98982faa7 | 1338 | ThisThread::sleep_for(1000); |
nishimura_taku_pet | 24:9481c8f56a49 | 1339 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1340 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1341 | time2.reset(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1342 | time2.start(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1343 | } |
mori2020 | 50:8843bee40df5 | 1344 | |
nishimura_taku_pet | 24:9481c8f56a49 | 1345 | // ESP Command data send |
nishimura_taku_pet | 24:9481c8f56a49 | 1346 | void SendCMD() |
nishimura_taku_pet | 24:9481c8f56a49 | 1347 | { |
nishimura_taku_pet | 24:9481c8f56a49 | 1348 | esp.printf("%s", cmdbuff); |
nishimura_taku_pet | 24:9481c8f56a49 | 1349 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1350 | // Get Command and ESP status replies |
nishimura_taku_pet | 24:9481c8f56a49 | 1351 | void getreply() |
nishimura_taku_pet | 24:9481c8f56a49 | 1352 | { |
nishimura_taku_pet | 24:9481c8f56a49 | 1353 | memset(replybuff, '\0', sizeof(replybuff)); |
nishimura_taku_pet | 24:9481c8f56a49 | 1354 | time1.reset(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1355 | time1.start(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1356 | replycount=0; |
nishimura_taku_pet | 24:9481c8f56a49 | 1357 | while(time1.read_ms()< timeout && replycount < getcount) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1358 | if(esp.readable()) { |
nishimura_taku_pet | 24:9481c8f56a49 | 1359 | replybuff[replycount] = esp.getc(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1360 | replycount++; |
nishimura_taku_pet | 24:9481c8f56a49 | 1361 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1362 | } |
nishimura_taku_pet | 24:9481c8f56a49 | 1363 | time1.stop(); |
nishimura_taku_pet | 24:9481c8f56a49 | 1364 | } |
takuminomura | 48:3003ea51c619 | 1365 | |
tomotsugu | 8:a47dbf4fa455 | 1366 | /* mainスレッド */ |
yangtzuli | 0:0d0037aabe41 | 1367 | int main() { |
tomotsugu | 8:a47dbf4fa455 | 1368 | /* 初期設定 */ |
mori2020 | 49:178dcafb4f0e | 1369 | wifi_thread = new Thread(wifi); |
mori2020 | 49:178dcafb4f0e | 1370 | wifi_thread -> set_priority(osPriorityHigh); |
mori2020 | 49:178dcafb4f0e | 1371 | // setup(); |
nishimura_taku_pet | 16:ffc732a3cf92 | 1372 | avoi_thread = new Thread(avoidance); |
nishimura_taku_pet | 16:ffc732a3cf92 | 1373 | avoi_thread->terminate(); |
nishimura_taku_pet | 16:ffc732a3cf92 | 1374 | trace_thread = new Thread(trace); |
nishimura_taku_pet | 16:ffc732a3cf92 | 1375 | trace_thread->terminate(); |
tomotsugu | 8:a47dbf4fa455 | 1376 | mode = READY; // 現在待ちモード |
tomotsugu | 8:a47dbf4fa455 | 1377 | beforeMode = READY; // 前回待ちモード |
tomotsugu | 8:a47dbf4fa455 | 1378 | run = STOP; // 停止 |
tomotsugu | 8:a47dbf4fa455 | 1379 | flag_sp = NORMAL; // スピード(普通) |
tomotsugu | 10:d193030ce672 | 1380 | lcd.setBacklight(TextLCD::LightOn); // バックライトON |
nishimura_taku_pet | 33:a6f1090e0174 | 1381 | lcd.setAddress(0,1); |
nishimura_taku_pet | 33:a6f1090e0174 | 1382 | lcd.printf("Mode:SetUp"); |
mori2020 | 49:178dcafb4f0e | 1383 | // display(); // ディスプレイ表示 |
yangtzuli | 2:38825726cb1b | 1384 | |
yangtzuli | 0:0d0037aabe41 | 1385 | while(1){ |
tomotsugu | 8:a47dbf4fa455 | 1386 | bChange(); // バッテリー残量更新 |
yangtzuli | 0:0d0037aabe41 | 1387 | } |
yangtzuli | 0:0d0037aabe41 | 1388 | } |