Thursday, 16 February 2012

Legolab 3 - soundsensor

Legolab 3

Date:16-02-12
Duration: 3 hours
Group members participating: Tore, Kristian, Troels


Goal
- Mount the sound sensor.
- Test the sound sensor.
- Use the sound sensor to control the robot.


Plan
1. Mount the sound sensor.
2. Compile and upload a rewritten version of the SonicSensor (*2) program to test the sound sensor.
3. Run the Data Logger program (*3) and analyse the output from the sensor and sample.txt
4. Run the Sound Controlled Car program (*4).
5. Examine the sound graph of a clap


Results
1. The sound sensor was mounted according to the book (*1). Seen in the picture below. We have the lightsensor and ultrasonic sensor mounted as well.


2. 
We rewrote the SonicSensor program slightly, so it used a sound senser instead:
      LCD.drawString("Sound level ", 0, 0);       
      while (! Button.ESCAPE.isPressed())
      {
          LCD.drawInt(sound.readValue(),3,13,0)
          Thread.sleep(300);
      }

 The readings are a percentage based scale. High sounds close to the device gives us a high percentage close to 100 while lower sounds gives lower values. It seems to be very dependent on the direction of the sensor compared to the sound source. If the sound origin appears in a cone in front of the microphone the sound appears higher than from sounds appearing from the sides and behind the machine.

3. 
We modified the code of the program so the output data was written one sample at a line, this was done in a simple way by changing the value  

private int itemsPerLine = 1

The reason for this was to make it easier to analyse later on. We converted the .txt file to a .csv file and loaded it in excel. We used excel to create the graph below. The graph shows our experiments with sound and the different sound sources we used. It also represents different positions for the sound source. If the sound source was closer to the microphone it will have a bigger spike on the graph and the opposite the longer the source was away. At the same note the sound also had a smaller spike if the sound source was on the side or behind the microphone. Which means it has a cone-like reading area in front of the microphone where it works best. We made the same sound in different places relative to the sensor. On the graph we se the spikes according to the sounds. The spike at ~800 is right behind the sensor. The next spike is 10 cm in front of the sensor, the next two spikes at 2097 and 2359 is the same distance moved 10 cm to the left and to the right. The next three spikes at 3145, 3407 and 3669 is at a distance of 50 cm. The last three spikes at 4193, 4455, 4800 is at 100 cm, front, to the left and to the right. We see that each time we increase the distance, the fluctuation decreases. It appears we did not move far enough to either side to really see the effect.




4.
 We ran the sound controlled car program (*4) on the NXT. The car reacts on high sounds which is reflected in the following line:

private static int soundThreshold = 90;

If the sound exceeds 90 the program will react and take the next order in line. It starts by moving forward, right, left and then stops in the aforementioned order.
To stop the car we had to hold down the escape button while clapping at the car to make it go through the different states. Only after the last state was it possible to stop the program. To change this we inserted a buttonlistener in the main method:

Button.ESCAPE.addButtonListener(new ButtonListener() {

             public void buttonPressed(Button b) {}


             public void buttonReleased(Button b) {

                 System.exit(0);

             }

           });



This made us able to stop the program by pres-releasing the escape button.


5. 
The SoundSampling program takes samples every 5 ms. The graph below shows our clap





We se the clap-attack start at around 19 and within 25 ms the clap has reached high-amplitude at 85-95. After 175 ms the clap-amplitude starts to decay returning back to low-amplitude after ~375 ms. Our clap is a little longer than Sivan Toledo, but otherwise the theory holds.



Status
The sound sensor works as one would expect with high numbers for high amplitude sounds, although it seems to cut off at a value of 93 as seen in the first graph, and more clearly in the clap sample graph at the interval [55,61].
Next project could be creating an algorithm to filter claps from other loud sounds. After this one could, as suggested in this weeks lab-exercises, mount two sound sensors and make the robot drive in the direction of a clap.


References
*1  LEGO Mindstorms education
*2 http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson2.dir/SonicSensorTest.java
*3 http://legolab.cs.au.dk/DigitalControl.dir/NXT/src/DataLogger.java
*4 http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson3.dir/SoundCtrCar.java

No comments:

Post a Comment