User Tools

Site Tools


marvin:lab3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
marvin:lab3 [2008/09/19 09:18] – created riepermarvin:lab3 [2008/10/09 21:33] (current) rieper
Line 1: Line 1:
-=== Lab rapport 3===+===== Lab rapport 3===== 
 +**Date:** September 19th 2008\\ 
 +**Duration of activity:** 8-12\\ 
 +**Participants:** Bent and Johnny\\ 
  
-**Lesson 3**+**Purpose** In this lesson we will use the NXT sound sensor to turn the LEGO 9797 car into a sound controlled 
 +car.
  
-I denne øvelse skal der laves bilder kan kontrolleres vhamikrofonen.+====Test of the Sound Sensor==== 
 +The purpose of this test is to make a simple test of the microphone sensitivity to sound coming from different directions. The microphone is placed in the center of a closed room of 3x3m and a key bundle is used as our sound generator. It was found that clapping with our hands made greater variance to the sound levelwhile the noise from the key bundle proved to give quite constant sound levels. By the view of the microphone one would expect it to have more sensitivity to sounds coming from and the test proved that these expectations were trueIn order to read the input of the microphone the code was modified to write the maximum value on the display whenever both the escape key and the right key on the NXT had been pressed.
  
-**Delopgave1: Test of the Sound Sensor** +The modifications of the program is shown here: 
-Firstyou should mount the sensor on the LEGO 9797 car as described in LEGO Mindstorms +<code java> 
-Education NXT Base Set 9797 building instruction page 24 to page 26Secondprogramcompile +SoundSensor s = new SoundSensor(SensorPort.S1); 
-and upload simple sensor test program similar to the SonicSensorTest.java. Place the car at fixed +int soundLevelmax; 
-position and make sounds of different loudness and at different distancesUse this to give +    
-description of the readings from the sound sensor.+LCD.drawString("Level: ", 0, 0); 
 +while (! Button.ESCAPE.isPressed()) {     
 +    max = 0; 
 +    while (! Button.RIGHT.isPressed() && ! Button.ESCAPE.isPressed()) { 
 + soundLevel = s.readValue(); 
 + if(soundLevel > max) max = soundLevel;  
 + LCD.drawInt(max,3,7,0); 
 + LCD.refresh(); 
 +    } 
 +     
 +    Thread.sleep(5); 
 +
 +LCD.clear(); 
 +LCD.drawString("Program stopped", 0, 0); 
 +LCD.refresh(); 
 +</code> 
 + 
 +The test data is shown on the picture below, which shows the amplitudes measured ''s.readValue'' 
 + 
 +{{:marvin:lab3-measurement.jpg?350}} 
 + 
 +The maximum readings were 93, and normal background noise were measured to 5-10.\\ 
 +Looking at the readingsthe microphone characteristics can be seen to resemble that of a cardoid characteristic (stronger at the frontweaker at the sides, end weakest behind). 
 + 
 +====Sound Recording==== 
 +We 'recorded' some sound, by dumping the raw values to text file every 5 ms.\\ 
 +The sound was that of Bent speaking directly into the microphone, thus utilizing the entire span of the power spectrum.\\ 
 +The recorded samples can be seen below (MatLab plot):\\ 
 +{{:marvin:Lab3-micsamples.png}}\\ 
 +Notice that the time resolution is poor due to the low sampling timeWhen playing back in Wave format it is impossible to recognize any spoken words. Yet the microphone is suitable for recognizing clapping sounds and the like, where you basically just want to measure the amplitude level. 
 + 
 + 
 +====Sound Controlled Car==== 
 +Below is the source code we used for testing the sound control: 
 +<code java
 +public class SoundCtrCar  
 +
 +    private static int soundThreshold = 80; 
 +    private static SoundSensor sound = new SoundSensor(SensorPort.S2); 
 +  
 +    private static  void waitForLoudSound() throws Exception 
 +    { 
 +        int soundLevel; 
 + 
 +        Thread.sleep(500); 
 +        do 
 +        { 
 +     soundLevel = sound.readValue(); 
 +     LCD.drawInt(soundLevel,4,10,0); 
 +     LCD.refresh();  
 +        } 
 +        while ( soundLevel < soundThreshold && ! Button.ESCAPE.isPressed()); 
 +    } 
 +    
 +    public static void main(String [] args) throws Exception 
 +    { 
 +        LCD.drawString("dB level: ",0,0); 
 +        LCD.refresh(); 
 +         
 +        while (! Button.ESCAPE.isPressed()) 
 +        { 
 +     waitForLoudSound();         
 +     LCD.drawString("Forward ",0,1); 
 +     LCD.refresh();  
 +     Car.forward(100, 100); 
 +      
 +     waitForLoudSound();         
 +     LCD.drawString("Right   ",0,1); 
 +     LCD.refresh();  
 +     Car.forward(100, 0); 
 +      
 +     waitForLoudSound();         
 +     LCD.drawString("Left    ",0,1); 
 +     LCD.refresh(); 
 +     Car.forward(0, 100); 
 +      
 +     waitForLoudSound();         
 +     LCD.drawString("Stop    ",0,1); 
 +     LCD.refresh();  
 +     Car.stop(); 
 +       } 
 +       Car.stop(); 
 +       LCD.clear(); 
 +       LCD.drawString("Program stopped", 0, 0); 
 +       LCD.refresh();  
 +   } 
 +
 +</code> 
 +The code was modified to break out of the innermost loops upon ''ESCAPE.keyPressed()'', instead of using ''ButtonListener'', since the button listener seemed a bit overkill for the apparent application. 
 + 
 +We tested the program with a threshold of 50, but the car activated the next state by the noise of the motors.\\ 
 +We measured the motors running at about 40-60 in noise level, and changed the threshold to 80 accordingly. 
 + 
 +Click the image to see movie of the sound controlled car in action:\\ 
 +[[http://www.youtube.com/v/o1V42sYXdH8|{{:marvin:lab3-movie.jpg}}]] 
 + 
 +====Conclusion==== 
 +The microphone was sensitive towards the direction of the sound, see the figure under "Test of the Sound Sensor". We also found that the sampling time was far too low for recoring of speech, but the purpose of the microphone in this exercise was to detect clapping sounds, which it handles very well. By measurements on the readings from the sensor we found that the motors noise level was about 40-60, and therfore the threshold for handclap detection was set to 80.
marvin/lab3.txt · Last modified: 2008/10/09 21:33 by rieper