8/19 avoidance update 8/20 update
Dependencies: RemoteIR TextLCD
Diff: main.cpp
- Revision:
- 35:4cda290bdb87
- Parent:
- 34:040474bf6fe0
- Child:
- 36:66d42cf30dac
--- a/main.cpp Mon Aug 17 02:53:18 2020 +0000 +++ b/main.cpp Mon Aug 17 07:57:25 2020 +0000 @@ -694,9 +694,9 @@ strcat(webbuff, "<style type=\"text/css\">.noselect{ width:100px;height:60px;}.light{ width:100px;height:60px;background-color:#00ff66;}</style>"); strcat(webbuff, "</head><body><center><p><strong>Robot Car Remote Controller"); strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level "); - if(b > 30) { + if(b > 30) { //残電量表示 sprintf(webbuff, "%s%3d", webbuff, b); - } else { + } else { //30%より下の場合残電量を赤文字 strcat(webbuff, "<font color=\"red\">"); sprintf(webbuff, "%s%3d", webbuff, b); strcat(webbuff, "<\font>"); @@ -706,8 +706,8 @@ strcat(webbuff, "<br>"); strcat(webbuff, "<table><tr><td></td><td>"); - switch(mode) { - case ADVANCE: + switch(mode) { //ブラウザ更新時の現在の車の状態からボタンの点灯判定 + case ADVANCE: //前進 strcat(webbuff, "<button id='gobtn' type='button' class=\"light\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -723,7 +723,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - case LEFT: + case LEFT: //左折 strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"light\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -739,7 +739,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - case STOP: + case STOP: //停止 strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -755,7 +755,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - case RIGHT: + case RIGHT: //右折 strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -771,7 +771,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - case BACK: + case BACK: //後進 strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -787,7 +787,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - case AVOIDANCE: + case AVOIDANCE: //障害物回避 strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -803,7 +803,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"noselect\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - case LINE_TRACE: + case LINE_TRACE: //ライントレース strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -819,7 +819,7 @@ strcat(webbuff, "AVOIDANCE</button></td><td>"); strcat(webbuff, "<button id='tracebtn' type='button' class=\"light\" value=\"LINE_TRACE\" onClick='send_mes(this.id,this.value)' >LINE_TRACE"); break; - default: + default: //その他 strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\" value=\"GO\" onClick='send_mes(this.id,this.value)'>GO"); strcat(webbuff, "</button></td><td></td></tr><tr><td>"); strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\" onClick='send_mes(this.id,this.value)' >LEFT"); @@ -840,29 +840,29 @@ strcat(webbuff, "<strong>Speed</strong>"); strcat(webbuff, "<table><tr><td>"); //ready示速度だけ点灯 - switch (flag_sp) { - case 0: + switch (flag_sp) { //現在の速度のボタン表示 + case 0: //ノーマル strcat(webbuff, "<button id='sp1btn' type='button' class=\"light\" value=\"Normal\" onClick='send_mes_spe(this.id,this.value)' >Normal"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"Fast\" onClick='send_mes_spe(this.id,this.value)' >Fast"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"VeryFast\" onClick='send_mes_spe(this.id,this.value)' >VeryFast"); break; - case 1: + case 1: //ファスト strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"Normal\" onClick='send_mes_spe(this.id,this.value)' >Normal"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp2btn' type='button' class=\"light\" value=\"Fast\" onClick='send_mes_spe(this.id,this.value)' >Fast"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"VeryFast\" onClick='send_mes_spe(this.id,this.value)' >VeryFast"); break; - case 2: + case 2: //ベリーファスト strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"Normal\" onClick='send_mes_spe(this.id,this.value)' >Normal"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"Fast\" onClick='send_mes_spe(this.id,this.value)' >Fast"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp3btn' type='button' class=\"light\" value=\"VeryFast\" onClick='send_mes_spe(this.id,this.value)' >VeryFast"); break; - default: + default: //その他 strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"Normal\" onClick='send_mes_spe(this.id,this.value)' >Normal"); strcat(webbuff, "</button></td><td>"); strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"Fast\" onClick='send_mes_spe(this.id,this.value)' >Fast"); @@ -875,7 +875,7 @@ strcat(webbuff, "</center>"); strcat(webbuff, "</body>"); strcat(webbuff, "</html>"); - strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); + strcat(webbuff, "<script language=\"javascript\" type=\"text/javascript\">"); //機能 strcat(webbuff, "function htmlacs(url) {"); strcat(webbuff, "var xhr = new XMLHttpRequest();"); @@ -883,7 +883,7 @@ strcat(webbuff, "xhr.send(\"\");"); strcat(webbuff, "}"); - strcat(webbuff, "function send_mes(btnmes,btnval){"); + strcat(webbuff, "function send_mes(btnmes,btnval){"); //mode変更ボタン入力時の点灯消灯判定 strcat(webbuff, "console.log(btnval);"); strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); @@ -899,7 +899,7 @@ strcat(webbuff, "}"); strcat(webbuff, "}"); - strcat(webbuff, "function send_mes_spe(btnmes,btnval){"); + strcat(webbuff, "function send_mes_spe(btnmes,btnval){"); //speed変更ボタン入力時の点灯消灯判定 strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;"); strcat(webbuff, "htmlacs(url);"); strcat(webbuff, "console.log(url);"); @@ -966,7 +966,6 @@ } - void sendcheck() { weberror=1; @@ -1026,44 +1025,54 @@ pc.printf("+++++++++++++++++succed rec end+++++++++++++++++++++\r\n"); if( strstr(webdata, "GO") != NULL ) { pc.printf("+++++++++++++++++前進+++++++++++++++++++++\r\n"); - run = ADVANCE; // 前進 - mode = ADVANCE; // モード変更 - display(); // ディスプレイ表示 + delete avoi_thread; //障害物回避スレッド停止 + delete trace_thread; //ライントレーススレッド停止 + run = ADVANCE; // 前進 + mode = ADVANCE; // モード変更 + display(); // ディスプレイ表示 } if( strstr(webdata, "LEFT") != NULL ) { pc.printf("+++++++++++++++++左折+++++++++++++++++++++\r\n"); - run = LEFT; - mode = LEFT; - display(); // ディスプレイ表示 + delete avoi_thread; //障害物回避スレッド停止 + delete trace_thread; //ライントレーススレッド停止 + run = LEFT; // 左折 + mode = LEFT; // モード変更 + display(); // ディスプレイ表示 } if( strstr(webdata, "STOP") != NULL ) { pc.printf("+++++++++++++++++停止+++++++++++++++++++++\r\n"); - run = STOP; - mode = STOP; - display(); // ディスプレイ表示 + delete avoi_thread; //障害物回避スレッド停止 + delete trace_thread; //ライントレーススレッド停止 + run = STOP; // 停止 + mode = STOP; // モード変更 + display(); // ディスプレイ表示 } if( strstr(webdata, "RIGHT") != NULL ) { pc.printf("+++++++++++++++++右折+++++++++++++++++++++\r\n"); - run = RIGHT; - mode = RIGHT; - display(); // ディスプレイ表示 + delete avoi_thread; //障害物回避スレッド停止 + delete trace_thread; //ライントレーススレッド停止 + run = RIGHT; // 右折 + mode = RIGHT; // モード変更 + display(); // ディスプレイ表示 } if( strstr(webdata, "BACK") != NULL ) { pc.printf("+++++++++++++++++後進+++++++++++++++++++++\r\n"); - run = BACK; - mode = BACK; - display(); // ディスプレイ表示 + delete avoi_thread; //障害物回避スレッド停止 + delete trace_thread; //ライントレーススレッド停止 + run = BACK; // 後進 + mode = BACK; // モード変更 + display(); // ディスプレイ表示 } pc.printf("+++++++++++++++++succed+++++++++++++++++++++"); if( strstr(webdata, "AVOIDANCE") != NULL ) { pc.printf("+++++++++++++++++AVOIDANCE+++++++++++++++++++++"); if(avoi_thread->get_state() == Thread::Deleted) { - delete avoi_thread; + delete avoi_thread; //障害物回避スレッド停止 avoi_thread = new Thread(avoidance); avoi_thread -> set_priority(osPriorityHigh); } @@ -1075,7 +1084,7 @@ pc.printf("+++++++++++++++++LINET RACE+++++++++++++++++++++"); pc.printf("mode = LINE_TRACE\r\n"); if(trace_thread->get_state() == Thread::Deleted) { - delete trace_thread; + delete trace_thread; //ライントレーススレッド停止 trace_thread = new Thread(trace); trace_thread -> set_priority(osPriorityHigh); }