2006a/C2/課題3右

written by itos

Program no.2

This program is made as the second program of the c2-R group.

Function of this program

The machine can trace such strong light as that of a flashlight.

The machine uses two light sensors, which are set light and left.

And the two sensors sense the lightness of the surroundings.

If the lightness of the right side is stronger than that of lest, the machine is programmed to turn right until the left one becomes stronger.

And vise versa.

The machine repeat this choice and movement again and again.

The machine can search strong light when it lose sight of strong light.

If the lightness two both light sensors sense is under 33, this machine stop tracing and go around to search the strongest way of the lughtness.

Then the machine return to the strongest way and go straight.

(The value '33' was not found instantly. We two experimented many times to find the best value to devide tracing light and searching light.)

The machine can ring the sound.

When the machine goes around to search, sound rings.

Plus, this sound is decided by the lightness of the front part of the machine.

I tried this once, but no sound was heard.

So we thought for a long time and found that the sound was extremely high or low.

As a solution of this problem, we decided to use around the center part of the width of the sound the machine can ring.

Other Points

When I use this program for the machine, I change the place of the light sensors.

I place them so that they can sense the light only from the way they are set.

To be concrete, I turned the right sensor to right and left sensor to left.

Thanks to this invention, the tracing of the machine became smoother and more certain.

This is the PROGRAM!

#define THRESHOLD 40           // Decision Standard
#define ROUND 20               // Round Standard
#define DECIDEBORDER 33        // The border value to devide tracing light and searching light.
#define AROUND_TIME 210        // The time the machine takes to round


 int light_strongest ;
 int time_strongest ;
 int sound_height ;

task playsound()
{

  while (true)
  {
     PlayTone( 3000 - (2000 * sound_height /100) , 100); Wait(110);
  }
}


task main ()
{
   
   SetSensor(SENSOR_1, SENSOR_LIGHT);
   SetSensor(SENSOR_3, SENSOR_LIGHT);


               OnFwd(OUT_A+OUT_C);

               light_strongest = SENSOR_1;

   while (true) {
       if (SENSOR_1 < THRESHOLD && ( SENSOR_1 > DECIDEBORDER || SENSOR_2 > DECIDEBORDER )) {     // When the light is stronger on the right side.
           Rev(OUT_A);
           until(SENSOR_1 > THRESHOLD);
           Fwd(OUT_A);

       } 
       if (SENSOR_3 < THRESHOLD && ( SENSOR_1 > DECIDEBORDER || SENSOR_2 > DECIDEBORDER )) {   //  When the light is stronger on the left side.
           Rev(OUT_C);
           until(SENSOR_3 > THRESHOLD);
           Fwd(OUT_C);

       }
       if (SENSOR_1 < DECIDEBORDER && SENSOR_2 < DECIDEBORDER ) 
       {                                                                  //  Search!
                   sound_height = SENSOR_3;         // Start Sound.
                   start playsound ;
           

   
               ClearTimer(0);

               OnFwd(OUT_A);
               OnRev(OUT_C);
               
               while(FastTimer(0) < AROUND_TIME)
               {
                  if(SENSOR_1>light_strongest)
                  {
                    light_strongest = SENSOR_1;
                    time_strongest = FastTimer(0);
                   }
                }


               OnFwd(OUT_C);
               OnRev(OUT_A);
               
               Wait( AROUND_TIME - time_strongest );
       
                     stop playsound ;
               
               Fwd(OUT_A);
    
       }

   }

}

Please give us any comment, wheter it is good or bad.



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2006-07-12 (水) 16:27:34