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.
Revision 11:8fe62237a6a6, committed 2020-07-27
- Comitter:
- tomotsugu
- Date:
- Mon Jul 27 05:30:43 2020 +0000
- Parent:
- 10:8f933ed27db0
- Commit message:
- avoidance
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jul 27 05:01:04 2020 +0000
+++ b/main.cpp Mon Jul 27 05:30:43 2020 +0000
@@ -37,9 +37,9 @@
/* 超音波センサ関数 */
int watch(){
trig = 0;
- thread_sleep_for(0.5); // 5ms待つ
+ ThisThread::sleep_for(5); // 5ms待つ
trig = 1;
- thread_sleep_for(1.5); // 15ms待つ
+ ThisThread::sleep_for(15); // 15ms待つ
trig = 0;
while(echo.read() == 0){
}
@@ -52,7 +52,6 @@
DT = 400;
}
timer.reset(); // 距離計測タイマーリセット
- thread_sleep_for(3); // 30ms待つ
return DT;
}
@@ -63,33 +62,33 @@
run = STOP; // 停止
}
servo.pulsewidth_us(1925); // サーボを左に40度回転
- thread_sleep_for(25); // 250ms待つ
+ ThisThread::sleep_for(250); // 250ms待つ
SLD = watch();
if(SLD < limit){ // 左前20cm以内に障害物がある場合
run = STOP; // 停止
}
servo.pulsewidth_us(2400); // サーボを左に90度回転
- thread_sleep_for(25); // 250ms待つ
+ ThisThread::sleep_for(250); // 250ms待つ
SL = watch();
if(SL < limit){ // 左20cm以内に障害物がある場合
run = STOP; // 停止
}
servo.pulsewidth_us(1450);
- thread_sleep_for(10);
+ ThisThread::sleep_for(100); // 100ms待つ
servo.pulsewidth_us(925); // サーボを右に40度回転
- thread_sleep_for(25); // 250ms待つ
+ ThisThread::sleep_for(250); // 250ms待つ
SRD = watch();
if(SRD < limit){ // 右前20cm以内に障害物がある場合
run = STOP; // 停止
}
servo.pulsewidth_us(500); // サーボを右に90度回転
- thread_sleep_for(25); // 250ms待つ
+ ThisThread::sleep_for(250); // 250ms待つ
SR = watch();
if(SR < limit){ // 右20cm以内に障害物がある場合
run = STOP; // 停止
}
servo.pulsewidth_us(1450); // サーボを中央位置に戻す
- thread_sleep_for(10); // 100ms待つ
+ ThisThread::sleep_for(100); // 100ms待つ
if(SC < limit || SLD < limit || SL < limit || SRD < limit || SR < limit){ // 20cm以内に障害物を検知した場合
flag = 1; // フラグに1をセット
}
@@ -98,7 +97,6 @@
/* 障害物回避走行 */
void avoidance(void const *argument){
while(1){
- watchsurrounding();
if(flag == 0){ // 障害物がない場合
run = ADVANCE; // 前進
}
@@ -176,12 +174,13 @@
}
}
flag = 0; // フラグを0にセット
+ watchsurrounding();
}
}
int main()
{
- Thread thread1(avoidance,NULL,osPriorityHigh);
+ Thread thread1(avoidance,NULL,osPriorityAboveNormal);
while(true){
}
}
\ No newline at end of file