[[2019a/Member]] #define Deep_turn_R OnRL(-speed,speed); //Deepで両車輪を回し、深く曲がる #define turn_R OnRL(0,speed); //片方の車輪のみを動かす #define Straight OnRL(speed,speed); //直進 #define Deep_turn_L OnRL(speed,-speed); #define turn_L OnRL(speed,0); #define turning_R OnRL(-speed,speeed);; //時計回りに回転 #define turning_L OnRL(speed,-speed); //反時計回りに回転 #define cross_line OnFwd(OUT_BC,15);Wait(400); //交差点を横切る void R_trace(int Z){ //道の右側をトレースして交差点で停止する SetSensorLight(S1); long t0; t0=CurrentTick(); //タイマーをセット while (CurrentTick()-t0<Z) { //Z/1000秒以上連続して右に曲がるまで永続する if (SENSOR_1 < Baced-15) { //基準の明るさからー15の時の動作(黒線の上) Deep_turn_R; } else if (SENSOR_1 < Baced-5) {turn_R;//基準の明るさからー5のとき(やや黒線より) t0=CurrentTick();} else if (SENSOR_1 < Baced+5) {Straight; //いい感じの位置 t0=CurrentTick();} else if (SENSOR_1 < Baced+10) {turn_L; //黒線からやや離れている t0=CurrentTick();} else {Deep_turn_L; //黒線から完全に離れている t0=CurrentTick();} } turning_L; //左に旋回 Wait(400); cross_line; //直進して交差点を渡る } 右側をトレースして交差点をわたるサブ関数~ Z/1000秒以上連続して右に曲がるまで続けると交差点と判断するようになっている。~ コースのL〜K、F〜B間で使用。黄緑色の部分で作動する ***左側のトレース1 [#a2cabf16] void L_trace_A(int X){ //上記のR_traceの左バージョン SetSensorLight(S1); long t0; t0=CurrentTick(); while (CurrentTick()-t0<X) { if (SENSOR_1 < Baced-15) { Deep_turn_L; } else if (SENSOR_1 < Baced-5) {turn_L; t0=CurrentTick();} else if (SENSOR_1 < Baced+5) {Straight; t0=CurrentTick();} else if (SENSOR_1 < Baced+10) {turn_R; t0=CurrentTick();} else {Deep_turn_R; t0=CurrentTick();} } turning_R; //右旋回 Wait(400); cross_line; //交差点の横断 } こちらはR_traceと違い左側をトレースしながら移動するようになっている~ 連続して左に曲がり続ける(黒が続く)と交差点と判断される~ コースのM〜K、J〜Gで使用。基本の左側トレース。紫色の区間 ***左側トレース2 [#e0804cf8] void L_trace_B(int Y){ //左側トレース第二弾 SetSensorLight(S1); long t0; t0=CurrentTick(); while (CurrentTick()-t0<Y) { if (SENSOR_1 < Baced-15) {Deep_turn_R; t0=CurrentTick();} else if (SENSOR_1 < Baced-5) {turn_L; t0=CurrentTick();} else if (SENSOR_1 < Baced+5) {Straight; t0=CurrentTick();} else if (SENSOR_1 < Baced+10) {turn_R; t0=CurrentTick();} else {Deep_turn_R; //上記のものと違い、白を感知して右に連続して曲がり続けたときに止まるようになっている } } turning_L; //左旋回 Wait(200); }