Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: RemoteIR TextLCD
Diff: main.cpp
- Revision:
- 20:02bb875a9b13
- Parent:
- 19:c6f9f010bd9e
- Child:
- 21:68d38e8f64b5
diff -r c6f9f010bd9e -r 02bb875a9b13 main.cpp
--- a/main.cpp Wed Aug 05 02:07:18 2020 +0000
+++ b/main.cpp Wed Aug 05 02:31:16 2020 +0000
@@ -257,7 +257,6 @@
if(flag_sp > VERYFAST){ // スピード変更フラグが2より大きいなら
flag_sp -= 3 * (flag_sp / 3); // スピード変更フラグ調整
}
- //pc.printf(" motor\r\n");
ThisThread::sleep_for(30); // 30ms待つ
}
}
@@ -273,11 +272,8 @@
}
/* ライントレーススレッド */
-void trace(/*void const *argument*/){
+void trace(){
while(1){
- //if(mode==LINE_TRACE){ // 現在ライントレースモードなら
- //pc.printf("line trace\r\n");
-
/* 各センサー値読み取り */
int sensor1 = ss1;
int sensor2 = ss2;
@@ -330,7 +326,7 @@
}
/* 障害物回避走行スレッド */
-void avoidance(/*void const *argument*/){
+void avoidance(){
while(1){
watchsurrounding();
pc.printf("%d %d %d %d %d \r\n",SL,SLD,SC,SRD,SR);
@@ -425,12 +421,8 @@
t1=timer.read_ms();
t2=timer.read_ms();
while(echo.read() == 0&&(t1-t2)<10){
-
t1=timer.read_ms();
led1 = 1;
- if(mode!=AVOIDANCE){ // 現在障害物回避モードでないなら
- break;
- }
}
timer.stop();
timer.reset();
@@ -447,16 +439,14 @@
}
if((t1-t2)>=10){
- DT=100;
+ run = STOP;
}
- //pc.printf("私はDTである。%d\r\n",DT);
led1 = 0;
return DT;
}
/* 障害物検知関数 */
void watchsurrounding(){
- //pc.printf("watchsurrounding\r\n");
SC = watch();
if(SC < limit){ // 正面20cm以内に障害物がある場合
run = STOP; // 停止
@@ -465,19 +455,13 @@
ThisThread::sleep_for(180); // 250ms待つ
SLD = watch();
if(SLD < limit){ // 左前20cm以内に障害物がある場合
- //if(mode == AVOIDANCE) // 現在障害物回避モードなら
- run = STOP; // 停止
- //else
- //return;
+ run = STOP; // 停止
}
servo.pulsewidth_us(2400); // サーボを左に90度回転
ThisThread::sleep_for(120); // 250ms待つ
SL = watch();
if(SL < limit){ // 左20cm以内に障害物がある場合
- //if(mode == AVOIDANCE) // 現在障害物回避モードなら
- run = STOP; // 停止
- //else
- //return;
+ run = STOP; // 停止
}
servo.pulsewidth_us(1450);
ThisThread::sleep_for(120);
@@ -486,29 +470,22 @@
run = STOP;
}
servo.pulsewidth_us(925); // サーボを右に40度回転
- ThisThread::sleep_for(180); // 250ms待つ
+ ThisThread::sleep_for(190); // 250ms待つ
SRD = watch();
if(SRD < limit){ // 右前20cm以内に障害物がある場合
- //if(mode == AVOIDANCE) // 現在障害物回避モードなら
- run = STOP; // 停止
- //else
- //return;
+ run = STOP; // 停止
}
servo.pulsewidth_us(500); // サーボを右に90度回転
ThisThread::sleep_for(120); // 250ms待つ
SR = watch();
if(SR < limit){ // 右20cm以内に障害物がある場合
- //if(mode == AVOIDANCE) // 現在障害物回避モードなら
- run = STOP; // 停止
- //else
- //return;
+ run = STOP; // 停止
}
servo.pulsewidth_us(1450); // サーボを中央位置に戻す
ThisThread::sleep_for(120); // 100ms待つ
if(SC < limit || SLD < limit || SL < limit || SRD < limit || SR < limit){ // 20cm以内に障害物を検知した場合
flag_a = 1; // 障害物有無フラグに1をセット
}
- //pc.printf(" watchsurrounding\r\n");
}
/* ディスプレイ表示関数 */