目次
#contents


*課題の説明 [#w9d35255]

 詳しい説明は[[2014a/Mission1]]


*ロボット本体 [#m8994562]

 **プログラム

#define THRESHOLD 40 
#define HIPOWER 7
#define LOWPOWER 2
#define set_power_H SetPower(OUT_AC,HIPOWER);
#define set_power_L SetPower(OUT_AC,LOWPOWER);
#define go_forward set_power_H; OnFwd(OUT_AC); // 前進
#define turn_left1 set_power_L; OnFwd(OUT_C); OnRev(OUT_A); // 左折(強め)
#define turn_left0 set_power_L; OnFwd(OUT_C); Off(OUT_A); // 左折(弱め)
#define turn_right1 set_power_L; OnFwd(OUT_A); OnRev(OUT_C); // 右折(強め)
#define turn_right0 set_power_L; OnFwd(OUT_A); Off(OUT_C); // 右折(弱め)
#define STEP 1 // 1回の判断で動作させる時間
#define Max 50 // カーブでの繰り返し最大値
#define short_break Off(OUT_AC); Wait(500) // 小休憩
#define cross_time 200 // 交差点通過にかかる時間
#define cross_line set_power_L; Wait(cross_time) // 交差点進行


task main()

{
   SetSensor(SENSOR_2,SENSOR_LIGHT);
   
   int n;

   n=0; //続けて黒になった回数をカウント

   while(true)  { // 黒検出の回数がMax回未満の時、ライントレースする

                    while( n < Max )  {

                                         if (SENSOR_2 < THRESHOLD-15) {

                                          turn_left1; 

                                          n++;   // カウントを増やす             }


                    else  {
                       
                             if(SENSOR_2 < THRESHOLD-8) {
                                     
                                                          turn_left1;

                              } else if (SENSOR_2 < THRESHOLD-3)    {

                                                        turn_left0;

                              } else if (SENSOR_2 < THRESHOLD+3)    {

                                                         go_forward;

                              } else if (SENSOR_2 < THRESHOLD+8)    {

                                                         turn_right0;

                              }  else {
    
                                            turn_right1;              }
 

                                            n=0;     }

                                           Wait(STEP);           }

                                            short_break; // 小休憩

                                           turn_right1;

                                           Wait(Max*STEP); // 進路修正

                                           cross_line; 交差点進行

                                           n=0; // カウントをリセット
                         
                                                                     } 

                                                                                         }
    


























 **画像



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