... | ... | @@ -41,13 +41,30 @@ We noticed whilst doing the exercise that it was important to clap right in fron |
|
|
As the clap is recognized as a loud sound, if we didn't clap close enough, the sound would be to weak and not recognized as a clap.
|
|
|
|
|
|
### Exercise 4
|
|
|
TBD: Add codesnippet of ButtonListener implementation
|
|
|
Instead of polling the ESCAPE button in every loop of the SoundCtrCar application, a ButtonListener was implemented.
|
|
|
In the code snippet below, the main part of the modification is shown.
|
|
|
A static volatile boolean is used to store the event of a button press.
|
|
|
The value is updated by the ButtonListener, when the ESCAPE button is pressed.
|
|
|
The boolean is used to break both the inner and outer loops if the button is pressed.
|
|
|
The full code is found in [2].
|
|
|
|
|
|
```java
|
|
|
static volatile boolean isButtonPressed = false;
|
|
|
...
|
|
|
Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
public void buttonPressed(Button b) {
|
|
|
isButtonPressed = true;
|
|
|
}
|
|
|
|
|
|
public void buttonReleased(Button b) {}
|
|
|
}
|
|
|
);
|
|
|
```
|
|
|
|
|
|
### Exercise 5
|
|
|
The figure below shows four consecutive claps, measured with the NXT sound sensor. The pattern starts out at low amplitude and rises quickly (within the 25ms) to an amplitude above 85%. The length of the four claps varies between approximately 85ms and 175ms and then returns back to low (below 50%).
|
|
|
|
|
|
![Clap characteristics](https://gitlab.au.dk/rene2014/lego/raw/master/Week5/Measurements/ClapMeasurements.png)
|
|
|
![Figure 3 - Clap characteristics](https://gitlab.au.dk/rene2014/lego/raw/master/Week5/Measurements/ClapMeasurements.png)
|
|
|
|
|
|
In the SoundCtrCar.java a state change occurs whenever a sound level is recorded as 90% or above. The duration of the sound is not taken into account thus a constant sound above this limit would also trigger a state change. A sleep functionality has been implemented in order to keep the program from running quickly through every state at high sounds.
|
|
|
|
... | ... | @@ -94,6 +111,7 @@ while(!Button.ESCAPE.isDown()) |
|
|
Thread.sleep(dt);
|
|
|
}
|
|
|
```
|
|
|
The full code is found in [3].
|
|
|
|
|
|
The gains for the vehicle is chosen empirically to:
|
|
|
```java
|
... | ... | @@ -101,14 +119,24 @@ static float Kp = 5.0f, |
|
|
Ki = 0f,
|
|
|
Kd = 0.5f;
|
|
|
```
|
|
|
This means that the integral part of the PID controller is not used.
|
|
|
This is chosen, since it seemed to have an unfortunate effect on the control even when a Ki value of 0.001 was used.
|
|
|
|
|
|
The performance of our Party Finding Robot is shown in the following video.
|
|
|
|
|
|
[![Party Seeking Robot video](http://img.youtube.com/vi/RL0ZnIF1B_o/0.jpg)](http://www.youtube.com/watch?v=RL0ZnIF1B_o)
|
|
|
|
|
|
|
|
|
|
|
|
## Conclusion
|
|
|
The NXT sound sensor was used both to determine characteristics of a clap and to control the LEGO car with various sound controlled applications.
|
|
|
|
|
|
We experienced some non-linearities in the use of the sensor, which we did not fully understand.
|
|
|
This could be investigated further later.
|
|
|
|
|
|
We were very successful with implementing a Party Finder Robot using a PD controller and the DifferentialPilot class in the leJOS API.
|
|
|
The calibration and choice of gain parameters could probably be optimized to give an even better performance.
|
|
|
|
|
|
## References
|
|
|
[1] http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson3.dir/Lesson.html
|
|
|
|
|
|
[2] https://gitlab.au.dk/rene2014/lego/raw/master/Week5/exercise3soundctrcar/src/SoundCtrCar.java
|
|
|
[3] https://gitlab.au.dk/rene2014/lego/raw/master/Week5/exercise6partyfinder/src/exercise6partyfinder/PartyFinder.java |
|
|
\ No newline at end of file |