1.ロボットの紹介

使用したキット

LEGO マインドストーム

制作に当たり注意した点

&refhttp://yakushi.shinshu-u.ac.jp/robotics/?plugin=attach&pcmd=open&file=image.jpeg&refer=2013a%2FMember%2Fd.ichi%2FMission1;

2.コースの攻略

#lefhttp://yakushi.shinshu-u.ac.jp/robotics/?plugin=ref&page=2013a%2FMission1&src=robotics-2013a-mission1.jpg

右回り

左回り

3.プログラム

#define black1 39
#define black2 45
#define white1 60
#define white2 65
#define go_forward OnFwd(OUT_BC,40)
#define turn_right1 OnFwd(OUT_B,40);Off(OUT_C);
#define turn_right2 OnFwd(OUT_B,28);OnRev(OUT_C,28);
#define turn_left1 OnFwd(OUT_C,40);Off(OUT_B);
#define turn_left2 OnFwd(OUT_C,28);OnRev(OUT_B,28);
#define STEP 1
#define nMAX 220
#define short_break Off(OUT_BC);Wait(1000);


task main () 
{
    SetSensorLight(S3);
    int nOnline=0;
    long t0 = CurrentTick();
    int n=0;

    while (CurrentTick()-t0 <= 8000) {

        if (SENSOR_3 < black1) {
            turn_right2;
        } else if (SENSOR_3 < black2) {
            turn_right1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_left1;
        } else {
            turn_left2;
        }
       Wait(STEP);
    }
       OnFwd(OUT_A,50);Wait(500);Off(OUT_A);



    while (CurrentTick()-t0 <= 35000) {

        while(nOnline < nMAX && CurrentTick()-t0 <= 35000) {
            if (SENSOR_3 < black1) {
            turn_right2;
            nOnline++;
      } else {
          if (SENSOR_3 < black2) {
            turn_right1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_left1;
        } else {
            turn_left2;
          }
        nOnline=0;
        }
       Wait(STEP);
    }
    turn_left2;Wait(nMAX*STEP);
    OnFwd(OUT_BC,40);Wait(200);
    nOnline=0;
  }turn_left1;Wait(100);


    while (CurrentTick()-t0 <= 42000) {

        while(nOnline < nMAX && CurrentTick()-t0 <= 42000) {
            if (SENSOR_3 < black1) {
            turn_left2;
            nOnline++;
      } else {
          if (SENSOR_3 < black2) {
            turn_left1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_right1;
        } else {
            turn_right2;
          }
        nOnline=0;
        }
       Wait(STEP);
    }
    turn_right2;Wait(nMAX*STEP);
    OnFwd(OUT_BC,40);Wait(200);
    nOnline=0; 
  }turn_right1;Wait(200);


    while (CurrentTick()-t0 <= 50000) {

        while(nOnline < nMAX && CurrentTick()-t0 <= 50000) {
            if (SENSOR_3 < black1) {
            turn_right2;
            nOnline++;
      } else {
          if (SENSOR_3 < black2) {
            turn_right1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_left1;
        } else {
            turn_left2;
          }
        nOnline=0;
        }
       Wait(STEP);
    }
    turn_left2;Wait(nMAX*STEP);
    OnFwd(OUT_BC,40);Wait(200);
    nOnline=0;
  }


    while (n<2) {

        while(nOnline < nMAX && n<2) {
            if (SENSOR_3 < black1) {
            turn_right2;
            nOnline++;
      } else {
          if (SENSOR_3 < black1) {
            turn_right1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_left1;
        } else {
            turn_left2;
          }
        nOnline=0;
        }
       Wait(STEP);
    }
    turn_left2;Wait(nMAX*STEP);
    OnFwd(OUT_BC,40);Wait(200);
    nOnline=0;n++;
  }
    OnRev(OUT_BC,50);Wait(500);OnFwd(OUT_C,50);OnRev(OUT_B,50);Wait(300);
    OnFwd(OUT_C,50);OnRev(OUT_B,50);until(SENSOR_3 < 50);
    long t1 = CurrentTick();

      while (CurrentTick()-t1 <= 4000) {

        if (SENSOR_3 < black1) {
            turn_left2;
        } else if (SENSOR_3 < black2) {
            turn_left1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_right1;
        } else {
            turn_right2;
        }
       Wait(STEP);
    }
    turn_right1;Wait(270);Off(OUT_BC);OnRev(OUT_A,50);Wait(300);Off(OUT_A);
    OnRev(OUT_BC,50);Wait(400);OnFwd(OUT_B,50);OnRev(OUT_C,50);Wait(300);
    OnFwd(OUT_B,50);OnRev(OUT_C,50);until(SENSOR_3 < 50);
    long t2 = CurrentTick();

        while (CurrentTick()-t2 <= 6500) {

        if (SENSOR_3 < black1) {
            turn_left2;
        } else if (SENSOR_3 < black2) {
            turn_left1;
        } else if (SENSOR_3 < white1) {
            go_forward;
        } else if (SENSOR_3 < white2) {
            turn_right1;
        } else {
            turn_right2;
        }
       Wait(STEP);
    }
    Off(OUT_BC);
}

4.その他


添付ファイル: fileimage.jpeg 166件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-07-12 (金) 17:24:38