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
Diff: main.cpp
- Revision:
- 5:c399920d36c4
- Parent:
- 4:559b7eab7305
- Child:
- 6:bded3770fbf7
--- a/main.cpp Tue Dec 03 04:04:14 2019 +0000
+++ b/main.cpp Tue Dec 03 04:52:36 2019 +0000
@@ -1,5 +1,5 @@
#include "mbed.h"
-#define STR(var) #var
+
//走行用プログラムver4(P制御)
//11/1
//モータードライバー+回転数計測プログラム
@@ -119,23 +119,23 @@
motorReverse(BIN1,BIN2,duty_basic-duty_ad);
}
-/*
+
//右急カーブ
void Right_high_rotation(PwmOut AIN1,PwmOut AIN2,PwmOut BIN1,PwmOut BIN2,float duty) {
- motorReverse(AIN1,AIN2,duty);
- motorReverse(BIN1,BIN2,duty+0.2f);
+ motorStop(AIN1,AIN2);
+ motorReverse(BIN1,BIN2,duty);
}
//左急カーブ
void Left_high_rotation(PwmOut AIN1,PwmOut AIN2,PwmOut BIN1,PwmOut BIN2,float duty) {
- motorReverse(AIN1,AIN2,duty+0.2f);
- motorReverse(BIN1,BIN2,duty);
+ motorReverse(AIN1,AIN2,duty);
+ motorStop(BIN1,BIN2);
}
-*/
+
//最終的には
@@ -179,9 +179,10 @@
REVERSE
};
-int mode = STRAIGHT;
+int mode;
+int pre_mode;
-void Check_reflecter(AnalogIn sensor_R, AnalogIn sensor_L,AnalogIn sensor_C, int mode){
+void Check_reflecter(AnalogIn sensor_R, AnalogIn sensor_L,AnalogIn sensor_C){
int R_on_off =0;//左右の白黒
int L_on_off =0;
int C_on_off =0;
@@ -202,43 +203,45 @@
if(L_on_off==0 && C_on_off==0 && R_on_off==0)//線の外
{
- printf("I'm going out of line! Previous condition is %s \n",STR(mode));
+ printf("I'm going out of line! Previous condition is %d \n",pre_mode);
+ mode = pre_mode;
}
else if(L_on_off==1 && C_on_off==0 && R_on_off==0)//急左折
{
mode = SHARP_L;
- printf("%s\n",STR(mode));
+ printf("SHARP_L\n");
}
else if(L_on_off==0 && C_on_off==0 && R_on_off==1)//急右折
{
mode = SHARP_R;
- printf("%s\n",STR(mode));
+ printf("SHARP_R\n");
}
else if(L_on_off==1 && C_on_off==0 && R_on_off==1)//黒白黒、エラー、back
{
mode = REVERSE;
- printf("%s\n",STR(mode));
+ printf("REVERSE\n");
}
else if(L_on_off==0 && C_on_off==1 && R_on_off==0)//前進
{
mode = STRAIGHT;
- printf("%s\n",STR(mode));
+ printf("STRAIGHT\n");
}
else if(L_on_off==1 && C_on_off==1 && R_on_off==0)//左折
{
mode = LEFT;
- printf("%s\n",STR(mode));
+ printf("LEFT\n");
}
else if(L_on_off==0 && C_on_off==1 && R_on_off==1)//右折
{
mode = RIGHT;
- printf("%s\n",STR(mode));
+ printf("RIGHT\n");
}
else if(L_on_off==1 && C_on_off==1 && R_on_off==1)//all black(空中or十字部)よって直進
{
mode = STRAIGHT;
- printf("%s\n",STR(mode));
+ printf("STRAIGHT\n");
}
+ pre_mode = mode;
}
@@ -259,11 +262,11 @@
}
else if (mode ==SHARP_L)
{
- Left_rotation(AIN1,AIN2,BIN1,BIN2,duty_basic,duty_ad_sharp);
+ Left_high_rotation(AIN1,AIN2,BIN1,BIN2,duty_basic);
}
else if (mode ==SHARP_R)
{
- Right_rotation(AIN1,AIN2,BIN1,BIN2,duty_basic,duty_ad_sharp);
+ Right_high_rotation(AIN1,AIN2,BIN1,BIN2,duty_basic);
}
else if (mode == REVERSE)
{
@@ -306,12 +309,14 @@
*/
int main() {
- AIN1.period(0.001);
- AIN2.period(0.001);
- BIN1.period(0.001);
- BIN2.period(0.001);
+ AIN1.period(0.01);
+ AIN2.period(0.01);
+ BIN1.period(0.01);
+ BIN2.period(0.01);
machine_Stop(AIN1,AIN2,BIN1,BIN2);
+ mode = STRAIGHT;
+
/* enc_R.rise(&event_handler_R);
enc_R.fall(&event_handler_R);
@@ -321,10 +326,10 @@
while(1) {
wait(0.01);
- float duty_basic = 0.145f;
+ float duty_basic = 0.130f;
float duty_ad = 0.02f;
float duty_ad_sharp = 0.04f;
- Check_reflecter(sensor_R,sensor_L,sensor_C,mode);
+ Check_reflecter(sensor_R,sensor_L,sensor_C);
Conditional_branch(duty_basic,duty_ad,duty_ad_sharp);
printf("sensor_Right:L432[%.3f]>\n",sensor_R*3.3F);//電圧測定
printf("sensor_Left:L432[%.3f]>\n",sensor_L*3.3F);//電圧測定