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