Saturday, 22 September 2007

NXT Programming - Lesson 3


Date: 2007.09.20
Duration of activity: 4 hours
Group members: Alessandro, Daniela, Samuele


Goals of this session:
Trying the lego sound sensor


Very full lesson!
The first time without any problem and in which all the tools are perfectly arranged!
We start mounting the sensor on the car as described in the building instruction and trying it with the sample programs SonicSensorTest.java and SoundCtrCar.java. Ok, all is working: it's a lucky day!
We can go on with the second sample program: we think that the best way to check the ESCAPE button state also during the inner loops is to create a ButtonListener instance that modifies the value of a control variable. To make the code more compact we used the method Locomotion.drive instead of specific motion functions (forward(), left(), ...). The resulting code is the following:
SoundCtrCar.java


Before going on with the main goal of the lesson, we begin to deal with I/O methods, especially for file writing. The goal is: to sample readings from the sound sensor on a file, download it on the pc and use the recording file to create a graph.
After a quick reading to the lejos API, we make the first attempts: the primary hitch is manage the little amount of memory, because of that the program raises an exception after only three seconds of recording. We trace the amount of free memory during the program execution: the problem doesn't concern the I/O functions, but the operations used to build the strings.
Once solved this problem, found a trick to write string on file and discovered the application to download the file on the pc (thank you Gert!), we code the java implementation of Toledo's experiment:
ClapDetector.java
After tuning the threshold value (we set them 10% under Toledo's values), we obtain a really working clap detector!.
What about the sampling on the file? It seems it works, except a little detail:
in the beginning of the recording file we can see some junk characters:
maybe the flush() and close() functions of lejos implementation aren't still perfect.
After cleaning manually the file, we process it using gnuplot and we obtain this wonderful graph!

Good work, we can go home: this time the gate is open :-)

No comments: