[[2019a/Member]]

 #define t_r OnFwd(OUT_A);OnRev(OUT_C);Wait(60);Off(OUT_AC);ClearTimer(0);
 int s;
 sub follow_line_left()
 {
  while(FastTimer(0)<s)
  {
   if(SENSOR_2>42){OnFwd(OUT_A);OnRev(OUT_C);ClearTimer(0);}
   else if(SENSOR_2>40){OnFwd(OUT_A);ClearTimer(0);}
   else if(SENSOR_2>36){OnFwd(OUT_AC);ClearTimer(0);}
   else if(SENSOR_2>34){OnFwd(OUT_C);ClearTimer(0);}
   else{OnFwd(OUT_C);OnRev(OUT_A);}
  }
 }
 sub follow_line_right()
 {
  while(FastTimer(0)<s)
  {
   if(SENSOR_2>42){OnFwd(OUT_C);OnRev(OUT_A);ClearTimer(0);}
   else if(SENSOR_2>40){OnFwd(OUT_C);ClearTimer(0);}
   else if(SENSOR_2>36){OnFwd(OUT_AC);ClearTimer(0);}
   else if(SENSOR_2>34){OnFwd(OUT_A);ClearTimer(0);}
   else{OnFwd(OUT_A);OnRev(OUT_C);}
  }
 }
 sub cross_line()
 {
  Off(OUT_AC);Wait(100);
  OnFwd(OUT_AC);Wait(20);
  ClearTimer(0);
 }
 task main()
 {
  s=22;
  SetSensor(SENSOR_2,SENSOR_LIGHT);
  ClearTimer(0);
  follow_line_left();
  Off(OUT_AC);Wait(100);
  OnFwd(OUT_A);OnRev(OUT_C);Wait(40);
  OnFwd(OUT_AC);Wait(20);
  ClearTimer(0);
  s=24;
  follow_line_right();
  Off(OUT_AC);Wait(50);
  OnFwd(OUT_AC);Wait(30);
  t_r
  follow_line_right();
  Off(OUT_AC);Wait(50);
  OnFwd(OUT_AC);Wait(30);
  t_r
  OnRev(OUT_AC);Wait(30);Off(OUT_AC);
  s=20;
  follow_line_right();
  Off(OUT_AC);
  Wait(100);
  t_r
  s=18;
  follow_line_right();
  cross_line();
  follow_line_right();
  cross_line();
  follow_line_right();
  Off(OUT_AC);
  OnFwd(OUT_A);OnRev(OUT_C);Wait(50);
  OnRev(OUT_AC);Wait(20);
  follow_line_right();
  Off(OUT_AC);
  OnFwd(OUT_A);OnRev(OUT_C);Wait(50);Off(OUT_AC);
  OnRev(OUT_AC);Wait(100);Off(OUT_AC);
  OnRev(OUT_B);Wait(10);Off(OUT_B);
  s=23;
  ClearTimer(0);
  follow_line_right();
  cross_line();
  follow_line_right();
  cross_line();
  follow_line_left();
  Off(OUT_AC);
  OnFwd(OUT_A);OnRev(OUT_C);Wait(110);
  Off(OUT_AC);Wait(80);
  OnFwd(OUT_B);Wait(10);
  Off(OUT_ABC);
 }


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