終了する度にデータが消えてしまうためここに記録

#define BLACK 40              //閾値
#define SHORTCUT_TIME 300     //近道手前の移動時間
#define STRAIGHT_TIME 600     //2週目に入る前の軌道修正の時間
#define SE(t) PlayTone(t,20); //ポイントで音を鳴らす
#define c 523                 //ド
#define d 587                 //レ
#define e 659                 //ミ
#define f 698                 //ファ
#define g 784                 //ソ
#define a 880                 //ラ
#define b 988                 //シ
#define C 1047                //高いド
int count;                    //カウント

sub go_ahead()                //前進       
{OnFwd(OUT_A+OUT_C);}

sub go_back()                 //後退
{OnRev(OUT_A+OUT_C);}

sub spin_right()              //右折
{OnFwd(OUT_A); OnRev(OUT_C);}

sub spin_left()               //左折
{OnFwd(OUT_C); OnRev(OUT_A);}



void switchback()     //スタート〜鋭角
{
    while(count==0){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_back();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left(); Wait(30); go_ahead(); Wait(80); count++; SE(c);}
    }
}

void hairpin1()     //ヘアピン(1)
{
    while(count==1){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(30); count++; SE(d);}     //Waitで線を通り過ぎないとカウント回数が増えてしまう
    }

    while(count==2){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(30); count++; SE(e);}
    }
}

void enter_rotary()     //ロータリー進入
{
    while(count==3){
    go_ahead();
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {SE(f); go_ahead(); Wait(50); spin_right(); Wait(50); go_ahead(); Wait(10); count++;}
    }
}

void rotary1()     //ロータリー(1)
{
    while(count==4){
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(20); count++; SE(g);}
    }

    while(count==5){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(50); spin_right(); Wait(45); count++; SE(a);}
    }
}

void corner1()     //直角前  
{
    ClearTimer(0);   
    while(count==6 && FastTimer(0)<=SHORTCUT_TIME){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    }

    while(count==6 && FastTimer(0)>SHORTCUT_TIME){     //近道進入
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {go_ahead(); Wait(60); spin_left(); Wait(50); go_ahead(); Wait(50); count++; SE(b);}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    }
}

void shortcut()     //近道
{
    while(count==7){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead(); Wait(20);}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(50); spin_left(); Wait(50); go_ahead(); Wait(10); count++; SE(C);}
    }
}

void corner2()     //直角後
{
    while(count==8){
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(50); spin_right(); Wait(50); go_ahead(); Wait(10); count++; SE(b);}
    }
}

void rotary2()     //ロータリー(2)
{
    while(count==9){
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(20); count++; SE(a);}
    }

    while(count==10){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(50); spin_right(); Wait(60); count++; SE(g);}
    }
}

void hairpin2()     //ヘアピン(2)
{
    while(count==11){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(50); count++; SE(f);}
    }

    while(count==12){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(30); count++; SE(e);}
    }

    while(count==13){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(120); spin_right(); Wait(100); count++; SE(d);}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead();}
    }
}

void straight()     //1周目〜2週目
{
    ClearTimer(0);
    while(count==14 && FastTimer(0)<=STRAIGHT_TIME){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {spin_right();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead();}
    }

    while(count==14 && FastTimer(0)>STRAIGHT_TIME){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead(); Wait(80); spin_right(); Wait(100); go_ahead(); Wait(70); count=count-13; SE(c);}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {go_ahead();}
    }
}

void goal()     //ゴール
{
    while(count==14){     
    if(SENSOR_1 > BLACK && SENSOR_3 > BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 > BLACK)
    {spin_left();}
    if(SENSOR_1 > BLACK && SENSOR_3 <= BLACK)
    {go_ahead();}
    if(SENSOR_1 <= BLACK && SENSOR_3 <= BLACK)
    {Off(OUT_A+OUT_C); SE(c);}
    }
}

task main()
{
    SetSensor(SENSOR_1,SENSOR_LIGHT);
    SetSensor(SENSOR_3,SENSOR_LIGHT);
    count = 0;

    switchback();        //スタート
    hairpin1();
    enter_rotary();
    rotary1();
    corner1();
    shortcut();
    corner2();
    rotary2();
    hairpin2();
    straight();          //1週目〜2週目 
    hairpin1();
    enter_rotary();
    rotary1();
    corner1();
    shortcut();
    corner2();
    rotary2();
    hairpin2();
    goal();              //ゴール
}


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS