[[2005/B7]]

目次
#contents

* 最初のプログラム [#qf51e1e9]

 // 最初のプログラム
 //
 //    作成者:かずま
 //    作成日:2005-10-14
 
 task main()
 {
     OnFwd(OUT_A+OUT_C);     //  AとCのモータを正回転
     Wait(300);              //  プログラムの実行を3秒待つ
     Off(OUT_A+OUT_C);       //  AとCのモーターを止める
 }


#comment


* 正方形に沿って動くロボット [#g57bcd35]

 // 正方形に沿って動くロボット
 //
 //    作成者:かずま
 //    作成日:2005-10-21
 
 task main()
 {
     repeat(4)
     {
         OnFwd(OUT_A+OUT_C);     //  AとCのモータを正回転
         Wait(200);              //  プログラムの実行を2秒待つ
         Off(OUT_A+OUT_C);       //  AとCのモータを止める
         OnFwd(OUT_A);           //  Aのモーターを正回転
         OnRev(OUT_C);           //  Cのモーターを逆回転
         Wait(100);              //  プログラムの実行を1秒待つ
         Off(OUT_A+OUT_C);       //  AとCのモーターを逆回転
     }
 }


#comment


*光を追いかけるプログラム [#n14ec8fa]

 #define AROUND_TIME 500        // ロボが一周するのにかかる時間を定義
 #define gosa 15                // 光センサの反応誤差を考慮
 #define search_frequency 20    // サーチの範囲を定義
 
 int light=0;
 int turn=0;
 
 void turn_right(int t)
 {
     OnFwd(OUT_A);
     OnRev(OUT_C);
     Wait(t);
     Off(OUT_A+OUT_C);
 }
 
 void turn_left(int t)
 {
     OnRev(OUT_A);
     OnFwd(OUT_C);
     Wait(t);
     Off(OUT_A+OUT_C);
 }
 
 sub search()
 {
     turn=turn + search_frequency;
     turn_right(turn);
     turn=turn + search_frequency;    
     turn_left(turn);
 }
 
 task main()
 {
     SetSensor(SENSOR_1, SENSOR_LIGHT);
     
     ClearTimer(0);
 
     OnFwd(OUT_A);
     OnRev(OUT_C);
 
     while(Timer(0) <= AROUND_TIME/10)
     {
         if(SENSOR_1 > light)
         {
             light=SENSOR_1;
             ClearTimer(0);
         }
 
         if(Timer(0) == AROUND_TIME/10)
         {
             Off(OUT_A+OUT_C);
         }
     }
     while(Timer(0) > AROUND_TIME/10)
     {
	 while(light - gosa <= SENSOR_1 <= light + gosa)
         {
             turn=0;
             OnFwd(OUT_A+OUT_C);
         }
	 
	 while((SENSOR_1 < light - gosa) || (SENSOR_1 > light + gosa))
         {
             search();
         }	
     }
 }

・なんでかうまくいかない…orz


#comment


*光を追いかけるプログラム2 [#tff3accb]

 #define AROUND_TIME 500
 #define gosa 12
 #define search_frequency 20
 #define error 12
 #define search_range 20
 
 int light=0;
 int time=0;
 int move_time=0;
 int turn=0;
 
 void turn_right(int t)
 {
     OnFwd(OUT_A);
     OnRev(OUT_C);
     Wait(t);
 }
 
 void turn_left(int t)
 {
     OnRev(OUT_A);
     OnFwd(OUT_C);
     Wait(t);
 }
 
 sub search()
 {
     turn=turn + search_frequency;
     turn=turn + search_range;
     turn_right(turn);
     turn=turn + search_frequency;
     turn=turn + search_range;
     turn_left(turn);
 }
 
 task main()
 {
     SetSensor(SENSOR_1, SENSOR_LIGHT);
     
     ClearTimer(0);
 
     OnFwd(OUT_A);
     OnRev(OUT_C);
 
     while(Timer(0) <= AROUND_TIME/10)
     {
         if(SENSOR_1 > light)
         {
             light=SENSOR_1;
             time=Timer(0);
	     
	     if(time <= AROUND_TIME/20)
	     {
	         move_time=time;
	     }
	     
	     if(time > AROUND_TIME/20)
	     {
	         move_time=AROUND_TIME/10 - time;
	     }
         }
 
         if(Timer(0) == AROUND_TIME/10)
         {
             Off(OUT_A+OUT_C);
         }
     }
 
     while(AROUND_TIME/10 < Timer(0) <= AROUND_TIME/10 + time)
     while(AROUND_TIME/10 < Timer(0) <= AROUND_TIME/10 + move_time)
     {
         if(time <= AROUND_TIME/20)
         {
             turn_right(time);
             turn_right(move_time);
             Off(OUT_A+OUT_C);
         }
 
         if(time > AROUND_TIME/20)
         {
             turn_left(AROUND_TIME/10 - time);
             turn_left(move_time);
             Off(OUT_A+OUT_C);
         }
     }
     while(Timer(0) > AROUND_TIME/10 + time)
 
     while(Timer(0) > AROUND_TIME/10 + move_time)
     {
         while(light - gosa <= SENSOR_1 <= light + gosa)
         while(light - error <= SENSOR_1 <= light + error)
         {
             turn=0;
             OnFwd(OUT_A+OUT_C);
         }
 
         while((SENSOR_1 < light - gosa) || (SENSOR_1 > light + gosa))
         while((SENSOR_1 < light - error) || (SENSOR_1 > light + error))
         {
             search();
         }
     }
 }

・上のがうまくいかないのに発展型を作ってしもた。当然うまくいかない…orzなぜじゃぁぁぁぁぁぁぁ!!!


#comment


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