[[2019a/Member]]
#contents
*課題について [#q7dad8f6]

*ロボの構造について [#l7c270ac]

&ref(2019a/Member/TT/Mission2/851472E2-7F0A-4DF1-BA67-F49996158D35.jpeg,50%,ロボの前部)
*サブルーチンと関数について [#e4969a8a]
 int z;

 sub follow_leftline()           // 線の左側トレース
 {
  SetSensor(SENSOR_2, SENSOR_LIGHT);
  ClearTimer(0);
  while(FastTimer(0)<z){
                        if(SENSOR_2>44){OnFwd(OUT_A);OnRev(OUT_C);ClearTimer(0);}
                        else if(SENSOR_2>42){OnFwd(OUT_A);ClearTimer(0);}
                        else if(SENSOR_2>38){OnFwd(OUT_AC);ClearTimer(0);}
                        else if(SENSOR_2>36){OnFwd(OUT_C);ClearTimer(0);}
                        else if(SENSOR_2>32){OnFwd(OUT_C);OnRev(OUT_A);}
                        }
 }

 sub follow_rightline()           // 線の右側トレース
 {
  SetSensor(SENSOR_2, SENSOR_LIGHT);
  ClearTimer(0);
  while(FastTimer(0)<z){
                        if(SENSOR_2>44){OnFwd(OUT_C);OnRev(OUT_A);ClearTimer(0);}
                        else if(SENSOR_2>42){OnFwd(OUT_C);ClearTimer(0);}
                        else if(SENSOR_2>38){OnFwd(OUT_AC);ClearTimer(0);}
                        else if(SENSOR_2>36){OnFwd(OUT_A);ClearTimer(0);}
                        else if(SENSOR_2>32){OnFwd(OUT_A);OnRev(OUT_C);}
                         }
 }

 sub back_follow_right()           // 車体が反転したときの線の右側トレース
 {
  SetSensor(SENSOR_2, SENSOR_LIGHT);
  ClearTimer(0);
  while(FastTimer(0)<z){
                         if(SENSOR_2>44){OnFwd(OUT_C);OnRev(OUT_A);ClearTimer(0);}
                         else if(SENSOR_2>42){OnRev(OUT_A);ClearTimer(0);}
                         else if(SENSOR_2>38){OnRev(OUT_AC);ClearTimer(0);}
                         else if(SENSOR_2>36){OnRev(OUT_C);ClearTimer(0);}
                         else if(SENSOR_2>32){OnFwd(OUT_A);OnRev(OUT_C);}
                         }
 }


 sub migikaiten()                         // 右回転
 {
 OnFwd(OUT_AC);
 Wait(20);
 Off(OUT_AC);
 OnFwd(OUT_A);
 OnRev(OUT_C);
 Wait(40);
 Off(OUT_AC);
 OnFwd(OUT_AC);
 Wait(20);
 Off(OUT_AC);
 }
*プログラムについて [#sdf4ece8]
 task main()
 {
  SetSensor(SENSOR_2, SENSOR_LIGHT);
  z=35;
  follow_rightline();
  Off(OUT_AC);
  Wait(100);
  OnFwd(OUT_AC);
  Wait(30);
  Off(OUT_AC);
  z=20;
  follow_leftline();
  Off(OUT_AC);
  Wait(100);
  OnFwd(OUT_AC);
  Wait(20);
  Off(OUT_AC);
  
  OnFwd(OUT_A);OnRev(OUT_C);
  Wait(160);
  Off(OUT_AC);
  OnRev(OUT_AC);
  Wait(30);
  Off(OUT_AC);
  Wait(100);
  z=20;
  back_follow_right();
  Off(OUT_AC);
  OnRev(OUT_AC);
  Wait(30);
  Off(OUT_AC);
  OnRev(OUT_B);
  Wait(10);
  Off(OUT_B);
 
  OnFwd(OUT_A);
  OnRev(OUT_C);
  Wait(30);
  Off(OUT_AC);
  z=20;
  follow_rightline();
  Off(OUT_AC);
  Wait(100);
  OnFwd(OUT_AC);
  Wait(20);
  Off(OUT_AC); 

  z=20;
  follow_leftline();
  Off(OUT_AC);
  Wait(100);
  migikaiten();

  z=20;
  follow_leftline();
  Off(OUT_AC);
  Wait(100);
  migikaiten();

 
 

  z=20;
  follow_leftline();
  Off(OUT_AC);
  Wait(100);
  OnFwd(OUT_C);OnRev(OUT_A);
  Wait(90);
  Off(OUT_AC);

  z=20;
  follow_leftline();
  Off(OUT_AC);
  Wait(100);
  OnFwd(OUT_C);OnRev(OUT_A);
  Wait(90);
  Off(OUT_AC);
 
  OnFwd(OUT_A);OnRev(OUT_C);
  Wait(40);
  Off(OUT_AC);  

  z=20;
  follow_rightline();
  Off(OUT_AC);

  OnFwd(OUT_AC);
  Wait(30);
  Off(OUT_AC);
 
  z=20;
  follow_rightline();
  Off(OUT_AC);

  OnFwd(OUT_A);OnRev(OUT_C);
  Wait(110);
  Off(OUT_AC);
 
  OnFwd(OUT_B);
  Wait(10);
  Off(OUT_B);

 }
*感想・反省 [#yec2badb]

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