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