- 追加された行はこの色です。
- 削除された行はこの色です。
中央線です。松本駅から名古屋まで直通っす。
**ロボコン [#ead41f2e]
#define blackline 30
int frag;
int stage;
int timer;
sub linetrace (){
if ((SENSOR_1 <= blackline) && (SENSOR_2 <= blackline)){
if ((SENSOR_1 <= blackline) && (SENSOR_3 <= blackline)){
OnRev(OUT_A + OUT_C);
Wait(020);
Wait(030);
frag++;
}
else{
if ((SENSOR_1 <= blackline) && (SENSOR_3 >= blackline)){
OnFwd (OUT_A);OnRev (OUT_C);
}
if ((SENSOR_1 >= blackline) && (SENSOR_3 <= blackline)){
OnFwd (OUT_C);OnRev (OUT_A);
}
if ((SENSOR_1 >= blackline) && (SENSOR_3 >= blackline)){
OnRev (OUT_A + OUT_C);
}
}
}
sub hold_can (){
OnFwd (OUT_A+OUT_C);
Wait (timer + 250);
Wait (timer);
Off (OUT_A+OUT_C);
Wait (020);
OnRev (OUT_B);
Wait (150);
}
sub port_can (){
OnFwd (OUT_A+OUT_C);
Wait (timer);
Off (OUT_A+OUT_C);
OnFwd (OUT_B);
Wait (250);
Off (OUT_B);
ClearTimer (1);
while (FastTimer (1) <= 300){
SendMessage (1);
}
OnFwd (OUT_A+OUT_C);
Wait (040);
Off (OUT_A+OUT_C);
}
sub go_straight (){
OnFwd (OUT_A+OUT_C);
}
sub go_down (){
OnRev (OUT_A+OUT_C);
}
sub turn_R (){
Off (OUT_A + OUT_C);OnRev (OUT_A+OUT_C);Wait (007);OnFwd (OUT_A);Wait (080);Off (OUT_A+OUT_C);
}
sub turn_L (){
}
sub turn_L (){
Off (OUT_A + OUT_C);OnRev (OUT_C+OUT_A);Wait (007);OnFwd (OUT_C);Wait (080);Off (OUT_A+OUT_C);
}
task main(){
SetSensor (SENSOR_1, SENSOR_LIGHT);
SetSensor (SENSOR_3, SENSOR_LIGHT);
frag=0;
stage=1;
timer=0;
while (true){
if (stage == 1){
if (frag == 0 || 3 || 4 || 7){
linetrace ();
}
if (frag == 1){
linetrace ();
ClearTimer (0);
}
if (frag == 2){
timer = FastTimer (0);
turn_R ();
frag = 3;
}
if (frag == 5){
turn_L ();
hold_can ();
linetrace ();
}
if (frag == 6){
turn_L ();
frag = 7;
}
if (frag == 8){
turn_R ();
port_can ();
stage++;
frag = 0;
}
}
if (stage == 2){
if (frag == 0 || 3 || 7){
linetrace ();
}
if (frag == 1){
linetrace ();
ClearTimer (0);
}
if (frag == 2){
timer = FastTimer (0);
turn_R ();
frag = 3;
}
if (frag == 4){
OnFwd (OUT_A+OUT_C);
Wait (timer/2);
Off (OUT_A+OUT_C);
turn_L ();
hold_can ();
linetrace ();
}
if (frag == 5){
turn_L ();
frag = 7;
}
if (frag == 8){
turn_R ();
port_can ();
stage++;
frag = 0;
}
}
}
}