marvin:lab3
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
marvin:lab3 [2008/09/19 10:55] – rieper | marvin:lab3 [2008/10/09 21:21] – rieper | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | === Lab rapport 3=== | + | ===== Lab rapport 3===== |
+ | **Date:** September 19th 2008\\ | ||
+ | **Duration of activity:** 8-12\\ | ||
+ | **Participants: | ||
- | **Lesson 3** | + | **Purpose** In this lesson we will use the NXT sound sensor to turn the LEGO 9797 car into a sound controlled |
- | + | ||
- | In this lesson we will use the NXT sound sensor to turn the LEGO 9797 car into a sound controlled | + | |
car. | car. | ||
- | **Test of the Sound Sensor** | + | ====Test of the Sound Sensor==== |
- | The purpose of this test is to make a simple test of the microfon | + | The purpose of this test is to make a simple test of the microphone |
- | The modifications of the program is shown here: | + | |
+ | The modifications of the program is shown here: | ||
<code java> | <code java> | ||
SoundSensor s = new SoundSensor(SensorPort.S1); | SoundSensor s = new SoundSensor(SensorPort.S1); | ||
- | int soundLevel; | + | int soundLevel, max; |
- | + | | |
LCD.drawString(" | LCD.drawString(" | ||
- | |||
while (! Button.ESCAPE.isPressed()) { | while (! Button.ESCAPE.isPressed()) { | ||
- | soundLevel = s.readValue(); | + | |
- | LCD.drawInt(soundLevel,3,7,0); | + | while (! Button.RIGHT.isPressed() && ! Button.ESCAPE.isPressed()) { |
- | LCD.refresh(); | + | soundLevel = s.readValue(); |
+ | if(soundLevel > max) max = soundLevel; | ||
+ | LCD.drawInt(max,3,7,0); | ||
+ | LCD.refresh(); | ||
+ | } | ||
| | ||
Thread.sleep(5); | Thread.sleep(5); | ||
} | } | ||
+ | LCD.clear(); | ||
+ | LCD.drawString(" | ||
+ | LCD.refresh(); | ||
</ | </ | ||
- | The testdata | + | The test data is shown on the picture below, which shows the amplitudes measured |
+ | |||
+ | {{: | ||
+ | |||
+ | The maximum readings were 93, and normal background noise were measured to 5-10.\\ | ||
+ | Looking at the readings, the microphone characteristics can be seen to resemble that of a cardoid characteristic (stronger at the front, weaker at the sides, end weakest behind). | ||
+ | |||
+ | ====Sound Recording==== | ||
+ | We ' | ||
+ | The sound was that of Bent speaking directly into the microphone, thus utilizing the entire span of the power spectrum.\\ | ||
+ | The recorded samples can be seen below (MatLab plot):\\ | ||
+ | {{: | ||
+ | Notice that the time resolution is poor due to the low sampling time. When playing back in Wave format it is impossible to recognize any spoken words. | ||
+ | |||
+ | |||
+ | ====Sound Control==== | ||
+ | Below is the source code we used for testing the sound control: | ||
+ | <code java> | ||
+ | public class SoundCtrCar | ||
+ | { | ||
+ | private static int soundThreshold = 80; | ||
+ | private static SoundSensor sound = new SoundSensor(SensorPort.S2); | ||
+ | |||
+ | private static | ||
+ | { | ||
+ | int soundLevel; | ||
+ | |||
+ | Thread.sleep(500); | ||
+ | do | ||
+ | { | ||
+ | soundLevel = sound.readValue(); | ||
+ | LCD.drawInt(soundLevel, | ||
+ | LCD.refresh(); | ||
+ | } | ||
+ | while ( soundLevel < soundThreshold && ! Button.ESCAPE.isPressed()); | ||
+ | } | ||
+ | |||
+ | public static void main(String [] args) throws Exception | ||
+ | { | ||
+ | LCD.drawString(" | ||
+ | LCD.refresh(); | ||
+ | | ||
+ | while (! Button.ESCAPE.isPressed()) | ||
+ | { | ||
+ | waitForLoudSound(); | ||
+ | LCD.drawString(" | ||
+ | LCD.refresh(); | ||
+ | Car.forward(100, | ||
+ | |||
+ | waitForLoudSound(); | ||
+ | LCD.drawString(" | ||
+ | LCD.refresh(); | ||
+ | Car.forward(100, | ||
+ | |||
+ | waitForLoudSound(); | ||
+ | LCD.drawString(" | ||
+ | LCD.refresh(); | ||
+ | Car.forward(0, | ||
+ | |||
+ | waitForLoudSound(); | ||
+ | LCD.drawString(" | ||
+ | LCD.refresh(); | ||
+ | Car.stop(); | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | The code was modified to break out of the innermost loops upon '' | ||
+ | |||
+ | We tested the program with a threshold of 50, but the car activated the next state by the noise of the motors.\\ | ||
+ | We measured the motors running at about 40-60 in noise level, and changed the threshold to 80 accordingly. | ||
+ | |||
+ | Click the image to see a movie of the sound controlled car in action:\\ | ||
+ | [[http:// | ||
- | {{: |
marvin/lab3.txt · Last modified: 2008/10/09 21:33 by rieper