|
|
|
#Group-22: Lab Notebook 2 - Installing PID controller on Megatron
|
|
|
|
|
|
|
|
**Date:** 03/3/2015
|
|
|
|
|
|
|
|
**Group members participating:**-
|
|
|
|
Christian Bonde Andersen
|
|
|
|
Nikolaj Cilleborg Haulrik
|
|
|
|
Rasmus Meldgaard Petersen
|
|
|
|
Claus Hedeager Rasmussen
|
|
|
|
Jesper Kurtzmann Svith
|
|
|
|
|
|
|
|
**Activity duration:** 3
|
|
|
|
|
|
|
|
**Overall goal**
|
|
|
|
|
|
|
|
|
|
|
|
**Overall plan**
|
|
|
|
|
|
|
|
|
|
|
|
#Exercise 1
|
|
|
|
|
|
|
|
**Task**
|
|
|
|
To mount the sound sensor and run a test using a modified version of SonicSensorTest.java. Test the sensor with different loudness and under different circumstances and describe the readings.
|
|
|
|
|
|
|
|
**Plan**
|
|
|
|
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 static void main(String [] args)
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
|
|
|
|
SoundSensor SS = new SoundSensor(SensorPort.S1);
|
|
|
|
|
|
|
|
//Set to dB mode
|
|
|
|
SS.setDBA(false);
|
|
|
|
|
|
|
|
LCD.drawString("SoundSensor ", 0, 0);
|
|
|
|
LCD.drawString("SoundLvL(dB) ", 0, 2);
|
|
|
|
|
|
|
|
while (! Button.ESCAPE.isDown())
|
|
|
|
{
|
|
|
|
LCD.drawInt(SS.readValue(), 3, 13, 2);
|
|
|
|
|
|
|
|
Thread.sleep(300);
|
|
|
|
}
|
|
|
|
LCD.clear();
|
|
|
|
LCD.drawString("Program stopped", 0, 0);
|
|
|
|
Thread.sleep(2000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
**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.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
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 Readings (dB)
|
|
|
|
0
|
|
|
|
81
|
|
|
|
0.5
|
|
|
|
40
|
|
|
|
1
|
|
|
|
35
|
|
|
|
2
|
|
|
|
20
|
|
|
|
3
|
|
|
|
15-20
|
|
|
|
4
|
|
|
|
9-11
|
|
|
|
|
|
|
|
|
|
|
|
#Exercise 2
|
|
|
|
|
|
|
|
**Task**
|
|
|
|
To use the datalogger to record data from the sound sensor.
|
|
|
|
|
|
|
|
**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.
|
|
|
|
|
|
|
|
**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:
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Exercise 3 - sound controlled car
|
|
|
|
|
|
|
|
**Task**
|
|
|
|
Use the program SoundCtrCar.java to control the car using sound commands.
|
|
|
|
|
|
|
|
**Plan**
|
|
|
|
To run the program and observe how the robot responds to different sound input.
|
|
|
|
|
|
|
|
**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.
|
|
|
|
|
|
|
|
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 - button listener
|
|
|
|
|
|
|
|
**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.
|
|
|
|
|
|
|
|
**Plan**
|
|
|
|
To implement the ButtonListener from [4] of the Lab Lesson 3 guide.
|
|
|
|
|
|
|
|
**Result**
|
|
|
|
We implemented the ButtonListener example in the SoundCtrCar program as seen in the code below.
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
|
public void buttonPressed(Button b) {
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void buttonReleased(Button b) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
```
|
|
|
|
In order to make the program terminate we use the S
|
|
|
|
|
|
|
|
# Exercise 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Exercise 6
|
|
|
|
|
|
|
|
|
|
|
|
Conclusion
|
|
|
|
|
|
|
|
|
|
|
|
References
|
|
|
|
|