*課題説明 [#be765b6a]
http://yakushi.shinshu-u.ac.jp/robotics/?plugin=ref&page=2016a%2FMission2&src=2016a-mission2.png
私選んだ経路はB地点からC地点へ
B地点 → R右折 → Q直進 → Q直進 →P右折 → S右折 → C地点
*プログラムの説明 [#ga3245d8]
定義
#define RIGHT OnRev(OUT_C);OnFwd(OUT_A); //右旋回
#define LEFT OnRev(OUT_A);OnFwd(OUT_C); //左旋回
#define TURN_RIGHT OnFwd(OUT_A);Off(OUT_C); //右折
#define TURN_LEFT OnFwd(OUT_C);Off(OUT_A); //左折
#define STREIGHT OnFwd(OUT_AC); //直進
#define TMAX 20
task main()
{
int t;
t = 0;
SetSensor(SENSOR_2, SENSOR_LIGHT);
while(t <= 11){
ClearTimer(0);
while(FastTimer(0) < TMAX){
if(SENSOR_2 > 54){ //とても白いとき右旋回
RIGHT;ClearTimer(0);
} else if (SENSOR_2 < 42){ //とても黒いとき左旋回
LEFT;
} else if (SENSOR_2 > 50){ //少し白いとき右折
TURN_RIGHT;ClearTimer(0);
} else if (SENSOR_2 < 44){ //少し黒いとき左折
TURN_LEFT;ClearTimer(0);
} else { //黒線の境目で直進
STREIGHT;ClearTimer(0);
}
}
メインタスクのプログラム
t = t + 1;
if(t == 1){ //R右折
Off(OUT_AC);Wait(100);
TURN_RIGHT;Wait(150);
Off(OUT_AC);Wait(100);
} else if(t == 2){ //一つ目の角を左折
LEFT;Wait(100);
} else if(t == 3){ //Q直進
Off(OUT_AC);Wait(100);
STREIGHT;Wait(30);
Off(OUT_AC);Wait(100);
} else if(t == 4){ //Q直進
Off(OUT_AC);Wait(100);
STREIGHT;Wait(30);
Off(OUT_AC);Wait(100);
} else if(t == 5){ //P右折
Off(OUT_AC);Wait(100);
TURN_RIGHT;Wait(100);
Off(OUT_AC);Wait(100);
} else if(t == 6){ //S右折
Off(OUT_AC);Wait(100);
TURN_RIGHT;Wait(100);
Off(OUT_AC);Wait(100);
}
}
STREIGHT;Wait(30);Off(OUT_AC); //C到着
}