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: mbed
Revision 1:5bd831747630, committed 2019-11-13
- Comitter:
- takumi64
- Date:
- Wed Nov 13 12:36:05 2019 +0000
- Parent:
- 0:617b5fe8f980
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 12 01:02:51 2019 +0000
+++ b/main.cpp Wed Nov 13 12:36:05 2019 +0000
@@ -10,8 +10,8 @@
InterruptIn enc_L(D11);//フォトインタラプタ左
AnalogIn sensor_R(A0);//進行方向右のフォトリフレクタセンサー
-AnalogIn sensor_L(A1);//進行方向左のセンサー
-AnalogIn sensor_C(A2);//中央配置のセンサー
+AnalogIn sensor_L(A2);//進行方向左のセンサー
+AnalogIn sensor_C(A1);//中央配置のセンサー
DigitalOut led(LED1);
@@ -92,27 +92,40 @@
}
//制御(maenoshin)
void control (int Left, int Center, int Right, int sec,float duty){
- if(Left == 0 && Center == 1 && Right == 0){//全速前進だ!
- machine_Forward(AIN1,AIN2,BIN1,BIN2,duty);
- printf("Direction%d:Forward\n",sec);
+ if(Left == 0 && Center == 0 && Right == 0){//all white [stop]
+ machine_Stop(AIN1,AIN2,BIN1,BIN2);
+ printf("Direction [%d] : Stop[all white] \n -- \n",sec);
+ }
+ else if(Left == 1 && Center == 1 && Right == 1){//all black [stop]
+ machine_Stop(AIN1,AIN2,BIN1,BIN2);
+ printf("Direction [%d] : Stop[all black] \n -- \n",sec);
}
- if(Left == 1 && Center == 1 && Right == 0){//左折
+ else if(Left == 0 && Center == 1 && Right == 0){//全速前進だ!
+ machine_Forward(AIN1,AIN2,BIN1,BIN2,duty);
+ printf("Direction [%d] : Forward \n A \n",sec);
+ }
+ else if(Left == 1 && Center == 1 && Right == 0){//左折
Left_rotation(AIN1,AIN2,BIN1,BIN2,duty);
- printf("Direction%d:Left turn\n",sec);
+ printf("Direction [%d] : Left turn\n ->\n",sec);
}
- if(Left == 0 && Center == 1 && Right == 1){//右折
+ else if(Left == 0 && Center == 1 && Right == 1){//右折
Right_rotation(AIN1,AIN2,BIN1,BIN2,duty);
- printf("Direction%d:Right turn\n",sec);
+ printf("Direction [%d] : Right turn\n <-\n",sec);
}
- if(Left == 1 && Center == 0 && Right == 0){//左折(急)
+ else if(Left == 1 && Center == 0 && Right == 0){//左折(急)
Left_rotation(AIN1,AIN2,BIN1,BIN2,duty);
- printf("Direction%d:Left turn hurry!\n",sec);
+ printf("Direction [%d] : Left turn hurry!\n\n",sec);
}
- if(Left == 0 && Center == 0 && Right == 1){//右折(急)
+ else if(Left == 0 && Center == 0 && Right == 1){//右折(急)
Right_rotation(AIN1,AIN2,BIN1,BIN2,duty);
- printf("Direction%d:Right turn hurry!\n",sec);
+ printf("Direction [%d] : Right turn hurry!\n\n",sec);
}
- else{ printf("Direction%d:error\n",sec);
+ else{ printf("Direction [%d] : error\n[x]\n",sec);
+ printf(" <Left:[%d],Center:[%d],Right[%d]>\n",Left,Center,Right);
+ printf(" sensor_Right:L432[%.3f]>\n",sensor_R*3.3F);//電圧測定
+ printf(" sensor_Left:L432[%.3f]>\n",sensor_L*3.3F);//電圧測定
+ printf(" sensor_Center:L432[%.3f]>\n",sensor_C*3.3F);//電圧測定
+ sec++;
}
}
@@ -130,27 +143,32 @@
machine_Stop(AIN1,AIN2,BIN1,BIN2);
int sec =0;
-
+ int Center = 0;
+ int Right = 0;
+ int Left =0;
while(1) {
float duty = 0.9f;//デューティー比90%
- int Center = 0;
- int Right = 0;
- int Left =0;
- if(sensor_C*3.3f>1.0f){//中央センサーが黒
+ int pre_C = Center;
+ int pre_R = Right;
+ int pre_L = Left;
+ if(sensor_C*3.3f<1.0f){//中央センサーが黒
Center = 1;
}else{Center =0;}
- if(sensor_L*3.3f>1.0f){//左センサーが黒
+ if(sensor_L*3.3f<1.0f){//左センサーが黒
Left = 1;
}else{Left =0;}
- if(sensor_R*3.3f>1.0f){//右センサーが黒
+ if(sensor_R*3.3f<1.0f){//右センサーが黒
Right = 1;
}else{Right =0;}
- control(Left,Center,Right,sec,duty);
- wait (5);
- machine_Stop(AIN1,AIN2,BIN1,BIN2);
- wait (2);
- sec++;
+ if( Center == pre_C && Right == pre_R && Left == pre_L){
+ }
+ else{
+ control(Left,Center,Right,sec,duty);
+ }
+ //wait (5);
+ //machine_Stop(AIN1,AIN2,BIN1,BIN2);
+ //wait (2);
@@ -190,10 +208,5 @@
// printf("Direction:Back\n");
// }
//}
-
- printf("sensor_Right:L432[%.3f]>\n",sensor_R*3.3F);//電圧測定
- printf("sensor_Left:L432[%.3f]>\n",sensor_L*3.3F);//電圧測定
- printf("sensor_Center:L432[%.3f]>\n",sensor_C*3.3F);//電圧測定
- wait(3);
}
}
\ No newline at end of file