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 YKNCT_Movement SBDBT BNO055 YKNCT_MD YKNCT_I2C
Diff: main.cpp
- Revision:
- 17:5b4080915375
- Parent:
- 16:ea3008995c41
- Child:
- 18:61d3a2b78aee
--- a/main.cpp Wed Mar 18 09:29:44 2020 +0000 +++ b/main.cpp Thu Mar 19 05:01:52 2020 +0000 @@ -35,7 +35,7 @@ int XCooMove(int Tar,int Err); /* ライン補正 */ -void LineCor(void); +int LineCor(int Line_Dire); /* */ void SubOmuni(int X,int Y,int R); @@ -57,6 +57,8 @@ /* 自動yaw補整目標角度 */ double TarTheta=0; +/* ライン補正移動方向 */ +int Line_Dire=0; /* クラス定義 ----------------------------------------------------------------*/ @@ -195,7 +197,7 @@ if(UB) auto_mode++; break; - /* 〇〇の処理 */ + /* X座標移動処理 */ case 1: /* 動作終了時次のステップに */ if(XCooMove(1000,50)==0) @@ -203,6 +205,14 @@ break; + /* ライン補正処理 */ + case 2: + /* ライン補正完了後次のステップに */ + if(LineCor(Line_Dire)==1) + auto_mode++; + + break; + /* 終了処理 */ default: auto_mode=0; @@ -407,46 +417,51 @@ * @引数 なし * @返り値 なし *******************************************************************************/ -void LineCor(void) +int LineCor(int Line_Dire) { /* xの操作量 */ int val_x=0; /* 左側,右側の前回の値 */ - int LastLf,LastRi; + static int Last_val; /* ライン補正初期化フラグ */ static bool LineFlag=0; if(LineFlag==0) { - LastLf=1; - LastRi=0; + /* 初期値設定 0…左 1…右 */ + Last_val=Line_Dire; /* 初期化フラグ立てる */ LineFlag=1; } /* どちらもラインに乗っていない状態 */ if(In.Get(2)==0&&In.Get(3)==0) { - if(LastLf==1) val_x-=10; - if(LastRi==1) val_x+=10; + if(Last_val==0) val_x-=10; + if(Last_val==1) val_x+=10; } /* どちらかがラインに乗っている状態 */ - if(In.Get(2)==0&&In.Get(3)==1) { + if(In.Get(2)==1||In.Get(3)==1) { /* 左側のみ */ - if(In.Get(2)==1&&In.Get(3)==0) + if(In.Get(2)==1&&In.Get(3)==0) { val_x-=10; + Last_val=0; + } /* 右側のみ */ - else if(In.Get(2)==0&&In.Get(3)==1) + else if(In.Get(2)==0&&In.Get(3)==1) { val_x+=10; + Last_val=1; + } /* どちらも乗っている */ else /* フラグ回収 */ LineFlag=0; - - /* 今回の値を代入 */ - LastLf=In.Get(2); - LastRi=In.Get(3); } SubOmuni(val_x,0,0); + + /* 到達 */ + if(LineFlag==0) return 1; + /* 未到達 */ + else return 0; } \ No newline at end of file