概要
以下のURLを参照
http://yakushi.shinshu-u.ac.jp/robotics/?2014a%2FMission1
ゴールからスタートに向かうコースを担当する
真ん中:移動時、バーを上げている状態
右:ボールを取る時、バーを下げて囲むようにする そのまま移動してボールを転がしながら運び、目的地まで持っていく
部分ごとにプログラムを変えた。 それぞれの部分でのライントレースにかかる時間を考慮して、1つずつステージをクリアしていく。 オレンジ色の所で交差点判断するプログラムにして効率よくクリアする。 黄色の所でボールをとる。 設計上、ボールをとった後、シュートすることが難しい。なのでバーを上げた後、急発進し、ボールに車体ごとぶつかり、押すような形でシュートする。
#define bri 55 #define s1 30 #define s2 25 #define onRL(x,y) OnFwd(OUT_A,x);OnFwd(OUT_C,y); #define go onRL(s1,s1); #define left1 onRL(s2,-s2); #define left0 onRL(s1,0); #define right0 onRL(0,s1); #define right1 onRL(-s2,s2); #define nMAX 100 #define part1 10000 #define cross1 3000 #define part2 5000 #define part3 5000 #define cross2 2500 #define part4 8000 #define cross3 2500 #define part5 5500 #define part6 3500 #define time 1000 #define step 1 #define catch OnFwd(OUT_B,10);Wait(time);Off(OUT_B); #define shot OnRev(OUT_B,10);Wait(time);Off(OUT_B);OnFwd(OUT_AC,100);Wait(200);Off(OUT_AC);
task main () {
SetSensorLight(S3); long t0 = CurrentTick(); //ラインの左側をトレースする。 int left_count = 0; //左判断が連続で発生すると、0.5秒間左に旋回する
while(CurrentTick() - t0 <= part1){ //赤の部分、part1は全体で10秒ほどかかる if(left_count >= 300){ left1;Wait(500);left_count = 0; } else{ if(SENSOR_3 < bri -25){ left1;left_count++;} else if(SENSOR_3 < bri -15){ left0;left_count++;} else{ if(SENSOR_3 < bri -5){ go;} else if(SENSOR_3 < bri +5){ right0;} else { right1;} left_count = 0; } Wait(step); } }
long t1 = CurrentTick(); int count = 0;
while(CurrentTick() - t1 <= cross1){ //最初の交差点、 if(count >= nMAX){ //ここは余裕をもって3秒かけてクリアする right1; Wait(nMAX*step); go; Wait(300); count = 0; } else{ if(SENSOR_3 < bri -15){ left0; //left0なのは交差点に差し掛かった時、 count++; //左旋回だとラインからずれてしまうのをふせぐため } else{ if(SENSOR_3 < bri -5){ go;} else if(SENSOR_3 < bri){ right0;} else { right1;} count = 0; } Wait(step); } }
catch; //黄色の位置、ここでバーを下ろし、ボールを取る
long t2 = CurrentTick();
while(CurrentTick() - t2 <= part2) { //緑の部分、10秒かける if(SENSOR_3 < bri -25){ //ここは前半と後半に分ける left1;} else if(SENSOR_3 < bri -15){ left0;} else if(SENSOR_3 < bri -7){ go;} else if(SENSOR_3 < bri){ right0;} else { right1;} Wait(step); }
long t3 = CurrentTick();
while(CurrentTick() - t3 <= part3) { //緩やかな右カーブなので、 if(SENSOR_3 < bri -20){ //旋回要素をなくした left0;} else if(SENSOR_3 < bri -10){ go;} else if(SENSOR_3 < bri){ right0;} Wait(step); }
long t4 = CurrentTick();
while(CurrentTick() - t4 <= cross2){ //2回目の交差点 if(count > nMAX){ right1; Wait(count); go; Wait(400); } else{ if(SENSOR_3 < bri -15){ left0; count++; } else{ if(SENSOR_3 < bri -7){ go;} else if(SENSOR_3 < bri ){ right0;} else { right1;} count =0; } Wait(step); } }
long t5 = CurrentTick();
while(CurrentTick() - t5 <= part4){ //紫の部分、大きな円の内側を走る最低限の if(SENSOR_3 < bri -10){ //コマンドだけにした 8秒かける left1;} else { go;} Wait(step); }
long t6 = CurrentTick();
while(CurrentTick() - t6 <= cross3){ //3回目の交差点 if(count > nMAX){ right1; Wait(count); go; Wait(400); } else{ if(SENSOR_3 < bri -15){ left0; count++; } else{ if(SENSOR_3 < bri -5){ go;} else if(SENSOR_3 < bri){ right0;} else { right1;} count =0; } Wait(step); } }
long t7 = CurrentTick();
while(CurrentTick() - t7 <= part5){ //5.5秒かけて同じく円の内側を走る if(SENSOR_3 < bri -10){ left1;} else { go;} Wait(step); }
long t8 = CurrentTick();
while(CurrentTick() - t8 <= part6){ //最後のカーブ、3.5秒かける if(SENSOR_3 < bri -15){ left0;} else if(SENSOR_3 < bri -5){ right0;} else{ right1;} Wait(step); }
shot; //シュートする }
このプログラムでおおよそクリアできた。 反省点としては、このプログラムはこのコースでしか使用できないことだ。 効率的ではあるが、適応性に欠ける。 なので、次はどんなコースもトレースでき、ボールをとり、シュートができる設計を考えたい。