Lesson 3

Date: 21st of February, 2013
Participating group members: Kenneth Baagøe Kristiansen, Morten Djernæs Bech, Thomas Winding
Activity duration: 5 hours

Overall goal
The overall goal of this lesson is to familiarize ourselves with the NXT sound sensor by doing the exercises described here.

Exercise 1
Goal
The goal is to mount the microphone sensor and try to see how it works.

Plan
Follow the instruction on how to mount the sensor in manual and upload program, and try with sound levels and distances.

Result
A loud sound very close the sensor gives us a reading of 90. A similar loud sound at half a meter gives us reading between 20 and 50, it differs a lot.

Conclusion
Very close to the sensor the read outs are pretty constant, the further away from the source of the sound, the lower the read outs, while also varying a lot more.

Exercise 2
Goal
The goal in this exercise is to use a datalogger for saving sound data. Furthermore we will sketch a graph explaining this data.

Plan
Implement the datalogger, implement the SoundSampling.java, and download the sample.txt. Using the data gathered, plot a graph and analyze it.

Result
soundMeasurements
As time passes the robot moves further away from the source of the sound, starting at a distance of 15cm and ending at a distance of 100cm.

Conclusion
As can be seen from the graph there is a logarithmic development in the value measured by the sensor. The slight inconsistencies in the values measured can be attributed to ambient noise, like other students talking and experimenting with sounds as well, and the fact that we moved the robot manually which means that the velocity away from the sound source was not constant.

Exercise 3
Goal
The goal in this exercise is to make our first application using the sound sensor. We’ll observe how the car responds to shouting and clapping.

Plan
Implement the SoundCtrCar.java and use it with the simple class Car.java.
Test the behaviour of the car and watch what happens.

Result
The car would move around keeping the same direction until a clap or a noise/sound was made loud enough making the car turn the other direction.
A demonstration of the car is shown in exercise 4.

Conclusion
Before running the program, we looked at the code so we had an idea of what it was supposed to do. Testing it, it behaved as we expected, shifting between the different states (forward, left, right, stop) when making sounds that went above the threshold. We discovered that it only reacted to quite loud sounds, basically e.g. clapping had to be done very close to the sensor to get a reaction from the robot. What we didn’t expect was that we were unable to stop the program by any other means than removing the battery.

Exercise 4
Goal
The goal in this exercise create a ButtonListener which listens for the ESCAPE button and exit the program when its pressed.

Plan
Implement the ButtonListener in the car using a simple example from the leJos tutorial. Observe what happens.

Result
We implemented a boolean, called running, in our code to indicate whether or not the program should be running.
boolean

Additionally we added the boolean to the condition for the while loop in the waitForLoudSound() method to make sure the program exits the loop when the escape button is pressed.
soundLevelThreshold

Afterwards we added a ButtonListener to the escape button that switches the above boolean so the program knows when to stop.
buttonListener

This video shows our result which is available on YouTube (http://youtu.be/DFqBGQ9PoaE)

Our modified SoundCtrCar.java: SoundCtrCar.java

Conclusion
As the video illustrates, the behaviour of the program is as followed:
1st clap makes the car start running forward. 2nd clap makes the car turn right until the 3rd clap which makes the car turn left. The car is stopped by the 4th and last clap. With our button listener on the Escape button implemented it is now also possible to actually end the execution of the program as opposed to Exercise 3.

Exercise 5
Goal
Sivan Toledo has investigated how the sound sensor can be used to detect claps.
The goal in this exercise is making the car able to detect claps and compare Sivan Toledo’s method with the one used in SoundCtrCar.java.

Plan
We will implement the methods and observe the car using the different methods.

Result
This video shows our result which is available on YouTube (http://youtu.be/9JpNqvhbjNY).

As can be heard and seen in the video it’s not working perfectly.

Conclusion
The method used to detect claps in SoundCtrCar.java is simpler compared to the method proposed by Sivan Toledo. The method used in SoundCtrCar simply detects a single loud sound and then acts, while in comparison, Sivan Toledo’s method detects an increase in sound by first listening for a lower sound volume, then a high volume, e.g. the clap, and then a low sound volume again.

This difference in the methods to detect volumes means that the robot, with implementations of the two different methods, would have a differing behaviour. With the method proposed in SoundCtrCar, in an environment with a constant loud sound would repeatedly change between its different states (forward, left, right, stop) while, with our implementation of Sivan Toledos clap-detection, it would remain in one state (either forward or stop) since there would be no rises in sound volume.

Exercise 6
Goal
The goal in this exercise is to make the car drive towards the location in which the sound is coming from.

Plan
We’ll mount a second sound sensor to the car, making the car have two, and check where the sound is coming from – turning in that direction.

Result
This video shows our result which is available on YouTube (http://youtu.be/5dJ_PsrVmq0)

Source code for our Party Robot: PartyRobot.java

Conclusion
Having the sound sensors pointing straight forward gave us som trouble making the car follow the claps correctly. This we assume was because both sound sensors picked up the clapping sound and thus had a chance of either continuing to go forward or even turning the wrong way. By placing the sensors at a larger angle away from each other (as demonstrated in the video above), we made the car follow the claps without any trouble, which confirms our assumption.

Leave a Reply