... | ... | @@ -27,9 +27,9 @@ |
|
|
> We made a program similar to the SonicSensorTest called SoundSensorTest, but changed it to use the sound sensor and
|
|
|
> get the readings using the readValue() method of the SoundSensor class.
|
|
|
>
|
|
|
>```
|
|
|
>public class SoundSensorTest
|
|
|
>{
|
|
|
> ```
|
|
|
> public class SoundSensorTest
|
|
|
> {
|
|
|
> public static void main(String [] args)
|
|
|
> throws Exception
|
|
|
> {
|
... | ... | @@ -50,86 +50,103 @@ |
|
|
> LCD.drawString("Program stopped", 0, 0);
|
|
|
> Thread.sleep(2000);
|
|
|
> }
|
|
|
>}
|
|
|
> }
|
|
|
>
|
|
|
>```
|
|
|
> ```
|
|
|
>
|
|
|
>#### Results
|
|
|
> #### Results
|
|
|
>
|
|
|
>First we clapped at different distances to the sensor in order to measure from how far the sensor Will pick up >sound. We soon realized that the measurements were very inconsistent as it is impossible to make two or more >identical claps in a row.
|
|
|
> First we clapped at different distances to the sensor in order to measure from how far the sensor Will pick up
|
|
|
> sound. We soon realized that the measurements were very inconsistent as it is impossible to make two or more
|
|
|
> identical claps in a row.
|
|
|
>
|
|
|
>To compensate for the inconsistency we decided to use a smartphone and transmit a constant tone. The setup is showed >in the picture below. The car was placed on a table in the middle of the room and loudness were measured from >different distances:
|
|
|
> To compensate for the inconsistency we decided to use a smartphone and transmit a constant tone. The setup is
|
|
|
> showed in the picture below. The car was placed on a table in the middle of the room and loudness were measured
|
|
|
> from different distances:
|
|
|
>
|
|
|
> ![Skærmbillede 2015-03-02 kl. 09.56.58](http://gitlab.au.dk/uploads/group->22/lego/fcb16f422c/Sk%C3%A6rmbillede_2015->03-02_kl._09.56.58.png)
|
|
|
> ![G1](http://gitlab.au.dk/uploads/group-22/lego/093160e740/G1.png)
|
|
|
>
|
|
|
>Fig. 1: Picture of the setup. The robot was placed on a table and the phone was pointed towards the robot. After >each sensor reading the distance to the phone was increased.
|
|
|
> Fig. 1: Picture of the setup. The robot was placed on a table and the phone was pointed towards the robot. After
|
|
|
> each sensor reading the distance to the phone was increased.
|
|
|
>
|
|
|
>| Distance (approx metres) | Sensor Reading (dB) |
|
|
|
>| -------- | -------- |
|
|
|
>| 0 | 81 |
|
|
|
>| 0,5 | 40 |
|
|
|
>| 1 | 35 |
|
|
|
>| 2 | 20 |
|
|
|
>| 3 | 15-20 |
|
|
|
>| 4 | 9-11 |
|
|
|
> | Distance (approx metres) | Sensor Reading (dB) |
|
|
|
> | -------- | -------- |
|
|
|
> | 0 | 81 |
|
|
|
> | 0,5 | 40 |
|
|
|
> | 1 | 35 |
|
|
|
> | 2 | 20 |
|
|
|
> | 3 | 15-20 |
|
|
|
> | 4 | 9-11 |
|
|
|
>
|
|
|
>#### Skriv noget tekst her om tabellen!
|
|
|
> #### Skriv noget tekst her om tabellen!
|
|
|
> ---
|
|
|
># Exercise 2 - Data logger
|
|
|
> # Exercise 2 - Data logger
|
|
|
>
|
|
|
>#### Task
|
|
|
> #### Task
|
|
|
>
|
|
|
>To use the datalogger to record data from the sound sensor.
|
|
|
> To use the datalogger to record data from the sound sensor.
|
|
|
>
|
|
|
>#### Plan
|
|
|
> #### Plan
|
|
|
>
|
|
|
>We use the program DataLogger.java from lesson 1 to record data from the program SoundSampler.java. Then we will >process the data and make a graph using excel.
|
|
|
> We use the program DataLogger.java from lesson 1 to record data from the program SoundSampler.java. Then we will
|
|
|
> process the data and make a graph using excel.
|
|
|
>
|
|
|
>#### Result
|
|
|
> #### Result
|
|
|
>
|
|
|
>The DataLogger was used to log data from the sound sensor. The experiment consisted of a period of 10 seconds in >which consecutive snaps were made with the fingers. The graph below shows the results:
|
|
|
> The DataLogger was used to log data from the sound sensor. The experiment consisted of a period of 10 seconds in
|
|
|
> which consecutive snaps were made with the fingers. The graph below shows the results:
|
|
|
>
|
|
|
>![Skærmbillede 2015-03-02 kl. 10.34.35](http://gitlab.au.dk/uploads/group-22/lego/c97aea11de/Sk%C3%A6rmbillede_2015->03-02_kl._10.34.35.png)
|
|
|
>Fig. Recording of a sequence of four finger snaps. The graph shows data logged from the NXT while running the >SoundSampler program.
|
|
|
> ![T1](http://gitlab.au.dk/uploads/group-22/lego/a2d284cc77/T1.png)
|
|
|
> Fig. Recording of a sequence of four finger snaps. The graph shows data logged from the NXT while running the
|
|
|
> SoundSampler program.
|
|
|
>
|
|
|
>The graph shows four distinct spikes in the sound level caused by the finger snapping. The spikes peak at 30-50
|
|
|
>(db?) before the sound level goes back to its normal. The background noise measured is about 2-10 (db?).It is
|
|
|
>interesting to note that the spikes increase faster than they fade away. This observation can be due to resonance or >echo from the sound waves which take some milliseconds to fade away.
|
|
|
> The graph shows four distinct spikes in the sound level caused by the finger snapping. The spikes peak at 30-50
|
|
|
> (db?) before the sound level goes back to its normal. The background noise measured is about 2-10 (db?).It is
|
|
|
> interesting to note that the spikes increase faster than they fade away. This observation can be due to resonance
|
|
|
> or echo from the sound waves which take some milliseconds to fade away.
|
|
|
>
|
|
|
> ---
|
|
|
>## Exercise 3 - Sound Controlled Car
|
|
|
> ## Exercise 3 - Sound Controlled Car
|
|
|
>
|
|
|
>#### Task
|
|
|
> #### Task
|
|
|
>
|
|
|
>Use the program SoundCtrCar.java to control the car using sound commands.
|
|
|
> Use the program SoundCtrCar.java to control the car using sound commands.
|
|
|
>
|
|
|
>#### Plan
|
|
|
> #### Plan
|
|
|
>
|
|
|
>To run the program and observe how the robot responds to different sound input.
|
|
|
> To run the program and observe how the robot responds to different sound input.
|
|
|
>
|
|
|
>#### Result
|
|
|
> #### Result
|
|
|
>
|
|
|
>The test was conducted on a table where the car was controlled using voice commands. When the car detected the first >spike it would drive forward, when it heard the second it would turn left, on the third it would turn right and on >the fourth it would stop.
|
|
|
> The test was conducted on a table where the car was controlled using voice commands. When the car detected the
|
|
|
> first spike it would drive forward, when it heard the second it would turn left, on the third it would turn right
|
|
|
> and on the fourth it would stop.
|
|
|
>
|
|
|
>As every word has its own sound profile It could be interesting to investigate if the robot could interpret and act >differently on various voice commands. For instance it might be possible for the robot to recognize the difference >in length of words. However if different words are of equal length it might be difficult.
|
|
|
> As every word has its own sound profile It could be interesting to investigate if the robot could interpret and act
|
|
|
> differently on various voice commands. For instance it might be possible for the robot to recognize the difference
|
|
|
> in length of words. However if different words are of equal length it might be difficult.
|
|
|
>
|
|
|
> ---
|
|
|
>## Exercise 4 - ButtonListener
|
|
|
> ## Exercise 4 - ButtonListener
|
|
|
>
|
|
|
>#### Task
|
|
|
> #### Task
|
|
|
>
|
|
|
>In the program SoundCtrCar.java the ESCAPE button is polled in the outermost loop so that the ESCAPE button can be >used to stop the program. This does not work when the program loops in one of the four inner loops. You can make the >ESCAPE button always work as a program terminator if you also poll the state of the button in the inner loops. But >you can also use the ButtonListener mechanism to listen for the ESCAPE button and exit when ESCAPE is pressed. A >simple example of a ButtonListener can be seen in the leJos tutorial, [4]. Try this in the program.
|
|
|
> In the program SoundCtrCar.java the ESCAPE button is polled in the outermost loop so that the ESCAPE button can be
|
|
|
> used to stop the program. This does not work when the program loops in one of the four inner loops. You can make
|
|
|
> the ESCAPE button always work as a program terminator if you also poll the state of the button in the inner loops.
|
|
|
> But you can also use the ButtonListener mechanism to listen for the ESCAPE button and exit when ESCAPE is pressed.
|
|
|
> A simple example of a ButtonListener can be seen in the leJos tutorial, [4]. Try this in the program.
|
|
|
>
|
|
|
>#### Plan
|
|
|
> #### Plan
|
|
|
>
|
|
|
>To implement the ButtonListener from [4] of the Lab Lesson 3 guide.
|
|
|
> To implement the ButtonListener from [4] of the Lab Lesson 3 guide.
|
|
|
>
|
|
|
>#### Result
|
|
|
> #### Result
|
|
|
>
|
|
|
>We implemented the ButtonListener example in the SoundCtrCar program as seen in the code below.
|
|
|
> We implemented the ButtonListener example in the SoundCtrCar program as seen in the code below.
|
|
|
>
|
|
|
>```
|
|
|
>Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
> ```
|
|
|
> Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
> public void buttonPressed(Button b) {
|
|
|
>
|
|
|
> System.exit(0);
|
... | ... | @@ -141,11 +158,11 @@ |
|
|
> }
|
|
|
> });
|
|
|
>
|
|
|
>```
|
|
|
>In order to make the program terminate we use the S
|
|
|
> ```
|
|
|
> In order to make the program terminate we use the S
|
|
|
>
|
|
|
> ---
|
|
|
>## Exercise 5 - Clap Controlled Car
|
|
|
> ## Exercise 5 - Clap Controlled Car
|
|
|
>
|
|
|
> ---
|
|
|
>## Exercise 6 - Party Finder Robot
|
... | ... | |