目次
#contents

*課題 [#hbb493e2]
今回の課題はライントレースをするロボットを作ることである。~
詳しくは

*ロボット本体の説明 [#uba70732]

**本体の説明 [#uf3ba687]

2つのモーター(A,C)を用いて本体の前後、旋回、回転の動作を行っている。~

*プログラムの説明 [#f225120f]
**定義の説明 [#odd73086]
 #define BLACK 41  //これより小さかったら黒
 #define WHITE 50  //これより大きかったら白
 #define RIGHT_H OnFwd(OUT_A); OnRev(OUT_C);//右旋回
 #define RIGHT_L OnFwd(OUT_A); Off(OUT_C);//右回転
 #define LEFT_H OnFwd(OUT_C); OnRev(OUT_A);//左旋回
 #define LEFT_L OnFwd(OUT_C); Off(OUT_A);//左回転
 #define go_forward(t) OnFwd(OUT_AC);Wait(t);Off(OUT_AC);
 #define STEP 1
 
 sub line_trace()
 {
   ClearTimer(0); 
    while(FastTimer(0) <50){
     if (SENSOR_2 < BLACK) {         //黒
          RIGHT_H;
       } else if (SENSOR_2 < BLACK ) {   //黒よりのグレー
          RIGHT_L;
       } else if (SENSOR_2 > WHITE ) {   //白よりのグレー
          LEFT_L;
          ClearTimer(0);
       } else if (SENSOR_2 >= WHITE) {     //白
          LEFT_H ;
          ClearTimer(0);
       } else {                            //それ以外
       OnFwd(OUT_AC);
       ClearTimer(0);
       }
       Wait(STEP);
    }
    Off(OUT_AC);
    ClearTimer(0);
    PlaySound(SOUND_UP);
    Wait(100);
 } 
 
 sub line_left()
 {
  while (FastTimer(0) <  140 ) {
      LEFT_L;
    }
    ClearTimer(0);
 }

 sub line_left_H()
 {
    while (FastTimer(0) < 250) {
      LEFT_H;
    }
    ClearTimer(0);
 }
 
 task main()
 {
  SetSensor(SENSOR_2, SENSOR_LIGHT);
  go_forward(120);
  line_trace();
  line_left();
  line_trace();
  line_left();
  line_trace();
  line_left();
  line_trace();
  line_left_H();
  go_forward(120);
  line_trace();
 }


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