NXT Programming
Lesson 3
In this lesson we will use the NXT sound sensor
to turn the LEGO 9797 car into a sound controlled car.
|
|
Figure 1 The NXT sound sensor.
|
Test of the Sound Sensor
First, you should mount the sensor on the LEGO 9797 car as described in
LEGO Mindstorms Education NXT Base Set 9797 building
instruction page 24 to page 26. Second, program, compile and upload
a simple sensor test
program similar to the
SonicSensorTest.java.
Place the car at a fixed position and make sounds of different
loudness and at different
distances. Use this to give a description of the readings from the
sound sensor.
Data logger
A data logger, [1], is a mechanisme that can be used to collect and record
data from e.g. a sensor for later inspection. In the leJOS system a data
logger can be implemented to collect data and record them in a flash file.
An example of a simple data logger is DataLogger.java.
By means of this data logger e.g. sound data can be collected and recorded in a file
Sample.txt as shown in the data collection program
SoundSampling.java. The data in the file can then
be transfered to the PC by means of the tool nxjbrowse. The sampled data can
then be used to plot a graph of the sound level data.
Sound Controlled Car
As a first application of the sound sensor try the program
SoundCtrCar.java. The program uses a simple
class
Car.java
to move the car forward, left, right, etc. Describe the behaviour of the
car as you make sounds e.g. by shouting or clapping. Describe how the
program interpretes readings from the sound sensor as loud sounds.
In the program 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. Try this in the program.
Clap Controlled Car
Sivan Toledo has investigated how the sound sensor can be used to
detect claps. Through an investigation of a sequence of sound sensor readings
during a clap he suggest the following method to detect a clap:
A clap is a pattern that starts with a low-amplitude sample (say below
50),
followed by a very-high amplitude sample (say above 85) within
25 milliseconds, and then returns back to low (below 50) within
another 250 milliseconds.
Try to use his method to detect claps and compare it to the method
used in the program SoundCtrCar.java. Use the DataLogger class to
record and investigate clap patterne.
Party Finder Robot
Try to mount two sound sensors and use the readings from these sensors to always drive towards
the location with loud sound.
References
Last update: 10-02-12