jessvi created page: Lab3 authored by Jesper Kurtzmann Svith's avatar Jesper Kurtzmann Svith
......@@ -258,17 +258,48 @@
> ##### Fig. 11: Picture showing how we mounted the two sound sensors on the NXT robot.
>
> The two sound sensors were mounted on the opposite sides of the robot facing away from each other at a 90 degree
> angle (perpendicular to each other), as can be seen in fig. ??.
> angle (perpendicular to each other), as can be seen in (see fig. 11).
>
> We wrote a class called NoiseFinder using eclipse with the LejOs plugin. The class imported a number of LejOs
> features, but primarily sensorPort and soundSensor were the ones we used during this exercise.
> The primary feature of the class was to constantly compare the decibel measurements of the two sound sensors with a
> set decibel threshold. If the noise level on one of sound sensors was above the given threshold, and larger than
> that of the opposite sound sensor, the robot would turn in the direction of the loudest noise. This was simply done
> with three part if, else if & else loop [fig. ??]. This of course meant that the robot only could drive to the
> with three part if, else if & else loop [see fig. 11]. This of course meant that the robot only could drive to the
> right, left and straight ahead. If no sound was detected above the sound threshold, the robot would simply drive
> straight ahead at a reasonable pace.
>
> ```
while (! Button.ESCAPE.isDown())
{
Thread.sleep(5);
soundLevelRight = soundRight.readValue();
LCD.drawInt(soundLevelRight,4,10,0);
soundLevelLeft = soundLeft.readValue();
LCD.drawInt(soundLevelLeft,4,10,0);
//dlR.writeSample(soundLevelRight);
//dlL.writeSample(soundLevelLeft);
if (soundLevelRight > soundLevelLeft && soundLevelRight > soundThreshold) { //Ser i hvilken side hvor lydniveauet er højest og drejer derefter.
LCD.drawString("Noise is right ",0,1);
Car.forward(90, 60);
}
else if (soundLevelLeft > soundLevelRight && soundLevelLeft > soundThreshold) {
LCD.drawString("Noise is left ",0,1);
Car.forward(60, 90);
}
else {
Car.forward(70, 71);
}
}
```
>
> #### Results
>
> ![G2](http://gitlab.au.dk/uploads/group-22/lego/b618e3191d/G2.png)
......
......