torsdag den 16. september 2010

Week 3 in LEGO lab

Date: 16. September
Duration of activity: 3 hours
Groups members participating: Heine Stokholm and Mads Møller Jensen

Goals of the day:

  • Mount the soundsensor to our 9797 LEGO car, and test the sensor
  • Use a datalogger
  • Reconstruct the car into soundcontrolled car
  • Try to make the car controlled by claps


The sound sensor:
We have mounted the soundsensor (microphone) to the car and uploaded our MicSensorTest.java to it. The program recorded the input from the sensor, and wrote the value (between 0-100) to the LCD display.
The MicSensorTest program was just a rewriting of the SonicSensorTest we used last week to test the Sonic Sensor.
http://www.cs.au.dk/~mmjensen/legolab/MicSensorTest.java

No problems or surprises here, as we saw the display changing in accordance with the amplitude of the sounds we made.

Datalogger:
Our second assigment of the day was to use a datalogger on our LEGO car. So we uploaded SoundSampling.java to do so. After running the program we could connect to our car and get access to a log file. This file contained a lot of measurements from the microphone. Now we had the possibillity to log a specific sound and see the amplitude as a function of time.
Here is our result for a clap:
In the log file it was very easy to see where the clap was, so this is just a little piece of the entire log file. The program wrote to the log file every 5th ms, so even though we only logged a few seconds the log file was huge.

Sound controlled car:
After this we uploaded the SoundCtrCar.java file to our car. The program listened to sound and made the car go forward, go left, go right and stop in that sequence. If the microphone measured a sound over 90 it did the next thing the sequence and looping the whole thing. The problem with the original program was that the only time it was possible to hit the exit button and make the program quit was at the end of the loop.
To change this we had two approaches.
First approach: We implemented that the program should listen to the exit button every time it listened to the input from the microphone. This gave made us able to quit the program all the time. This can be seen here:

http://www.cs.au.dk/~mmjensen/legolab/SoundCtrCar.java

Second approach: We made the program implement the ButtonListener interface and this approach had the same effect as the first.

http://www.cs.au.dk/~mmjensen/legolab/SoundCtrCarListener.java

Clap controlled car:
Then came the fun part of the day: we tried to change the SoundCtrCar to only register claps. We used Sivan Toledo definition of claps and it are as follows:

     "A clap is a pattern that starts with a low-amplitude sample (say below 50), followed by a very-high amplitude sample (say above 85) within 25 milliseconds, and then returns back to low (below 50) within another 250 milliseconds."

This definition corresponds very good with the graph we created above.

We changed the waitForLoudSound() method from the SoundCtrCar to register claps instead like this:


private static  void waitForLoudSound() throws Exception
    {
  int clap = 0; 
        int soundLevel;
        Thread.sleep(500);
        do
        {
   if(Button.ESCAPE.isPressed()){
    System.exit(0);
   }
   soundLevel = sound.readValue();
            LCD.drawInt(soundLevel,4,10,0);
   if (clap == 0 && soundLevel < 50){
    clap = 1;
    Thread.sleep(25);
   } else if(clap == 1 && soundLevel > 85){
    clap = 2;
    Thread.sleep(250);
   } else if(clap == 2 && soundLevel <50){
    clap = 3;
   } else {
    clap = 0;
   }
        }
        while ( clap < 3 );
    }
 
We basically wait the time stated in the definition and then check if the next requirement is true. As you can see in the video below it works reasonably well but there are problems. It would probably be better to loop until the next requirement is true and restart if the time goes over the time specified in the definition.

The entire code can be seen here:
http://www.cs.au.dk/~mmjensen/legolab/ClapCtrCar.java

 

Ingen kommentarer:

Send en kommentar