[[2018a/Member]]
*課題 [#ebae0cfb]
下の図のようなコースを各チームで作成し、「ミッション」を遂行するためのロボットを作成せよ。
#ref(./課題2 コースの図.png,70%,コースの図)
*ロボット本体の説明 [#m397acd1]
#ref(./IMG_8116.jpg,20%,ロボットの写真)
#ref(./IMG_8117.JPG,20%,ロボットの写真)
*プログラミングの説明 [#i3ca63fc]
#define cross_stop Off(OUT_AC);Wait(100);
#define TURN_RIGHT(t) OnFwd(OUT_A);OnRev(OUT_C);Wait(t);Off(OUT_AC);
#define TURN_LEFT(t) OnFwd(OUT_C);OnRev(OUT_A);Wait(t);Off(OUT_AC);
#define go_straight(t) OnFwd(OUT_AC);Wait(t);Off(OUT_AC);
#define hold_can OnFwd(OUT_B);
#define releace_can OnRev(OUT_B);
**定義 [#f16699a2]
    #define cross_stop Off(OUT_AC);Wait(100);//交差点で止まる
    #define TURN_RIGHT(t) OnFwd(OUT_A);OnRev(OUT_C);Wait(t);Off(OUT_AC);//右にt秒曲がる
    #define TURN_LEFT(t) OnFwd(OUT_C);OnRev(OUT_A);Wait(t);Off(OUT_AC);//左にt秒曲がる
    #define go_straight(t) OnFwd(OUT_AC);Wait(t);Off(OUT_AC);//まっすぐt秒進む
    #define hold_can OnFwd(OUT_B);//缶をつかむ
    #define releace_can OnRev(OUT_B);//缶を放す

sub Line_Left()
{
    SetSensor(SENSOR_2,SENSOR_LIGHT);
     ClearTimer(0);
     while(FastTimer(0)<=30){
        if(SENSOR_2>=52){
         OnFwd(OUT_A);
         OnRev(OUT_C);
         Wait(5);
         Off(OUT_A);
         ClearTimer(0);
        }else if(SENSOR_2>=48){  
         OnFwd(OUT_A);
         Wait(5);
         Off(OUT_A);
         ClearTimer(0);
        }else if(SENSOR_2>=43){  
         OnFwd(OUT_C);
         Wait(5);
         Off(OUT_C);
         ClearTimer(0);
        }else if(SENSOR_2>=41){ 
         OnFwd(OUT_C);
         OnRev(OUT_A);
         Wait(5);
         Off(OUT_AC);  
         }
    }
    Off(OUT_AC);
}

sub Line_Right()
{
    SetSensor(SENSOR_2,SENSOR_LIGHT);
     ClearTimer(0);
     while(FastTimer(0)<=30){
         if(SENSOR_2>=52){
         OnFwd(OUT_C);
         OnRev(OUT_A);
         Wait(5);
         Off(OUT_AC);
         ClearTimer(0);
        }else if(SENSOR_2>=48){  
         OnFwd(OUT_C);
         Wait(5);
         Off(OUT_C);
         ClearTimer(0);
        }else if(SENSOR_2>=43){  
         OnFwd(OUT_A);
         Wait(5);
         Off(OUT_A);
         ClearTimer(0);
        }else if(SENSOR_2>=41){ 
         OnFwd(OUT_A);
         OnRev(OUT_C);
         Wait(5);
         Off(OUT_AC);
        
         }
    }
    Off(OUT_AC);
}

sub Line_Lefts()
{
    SetSensor(SENSOR_2,SENSOR_LIGHT);
     ClearTimer(0);
     while(FastTimer(0)<=20){
         if(SENSOR_2>=48){  
         OnFwd(OUT_A);
         Wait(5);
         Off(OUT_A);
         ClearTimer(0);
        }else if(SENSOR_2>=43){  
         OnFwd(OUT_C);
         Wait(5);
         Off(OUT_C);
         ClearTimer(0);       
         }
    }
    Off(OUT_AC);
}

sub Line_Rights()
{
    SetSensor(SENSOR_2,SENSOR_LIGHT);
     ClearTimer(0);
     while(FastTimer(0)<=20){
         if(SENSOR_2>=48){  
         OnFwd(OUT_C);
         Wait(5);
         Off(OUT_C);
         ClearTimer(0);
        }else if(SENSOR_2>=43){  
         OnFwd(OUT_A);
         Wait(5);
         Off(OUT_A);
         ClearTimer(0);
        }
    }
    Off(OUT_AC);
}

task main()
{
    Line_Right();
    cross_stop;
    go_straight(30);
    TURN_RIGHT(65);//A~B
    Line_Right();
    cross_stop;
    hold_can;
    TURN_LEFT(50);//B~J
    Line_Lefts();
    cross_stop;//J~K
    go_straight(30);
    Line_Lefts();
    cross_stop;//K~L
    go_straight(30);
    Line_Lefts();
    cross_stop;//L~I
    go_straight(30);
    TURN_LEFT(50); 
    Line_Left();
    cross_stop;
    go_straight(60);
    TURN_LEFT(65);//I~H
    Line_Right();
    cross_stop;
    go_straight(30);
    Line_Left();
    cross_stop;
    go_straight(30);
    TURN_LEFT(65);
    Line_Left();
    cross_stop;
    go_straight(30);
    TURN_RIGHT(65);//H~G
    Line_Left();
    cross_stop;
    TURN_RIGHT(50);//G~F
    Line_Right();
    Line_Rights();
    cross_stop;
    TURN_LEFT(65);
    releace_can;
    TURN_RIGHT(130);//F~D
    Line_Right();
    cross_stop;
    go_straight(30);
    TURN_RIGHT(65);
    Line_Right();
    cross_stop;//D~C
    go_straight(30);
    Line_Right();
    Off(OUT_ABC);//C~A
}

*まとめ [#ocdabd54]
**課題 [#leb45e01]
**感想 [#b7394c33]


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