... | ... | @@ -54,3 +54,39 @@ One solution to avoid different distances (to some extent) when driving on the A |
|
|
##### Picture 2: Alignment of sensors.
|
|
|
|
|
|
|
|
|
[![image alt text](http://img.youtube.com/vi/Yf35GVgVinQ/0.jpg)](http://www.youtube.com/watch?v=Yf35GVgVinQ)
|
|
|
##### Video 2: with pid and only one light sensor
|
|
|
|
|
|
|
|
|
As seen in video 2 (with pid and only one light sensor), it is difficult for the Lego car to choose a direction on the plateaus. If successful, it will continue up the ramp, if not, it will continue outside the course and fall down to the floor. The reason to this, is that it only gets measurements from one light sensor that tries to stay on the black line. Where the black line splits in two (on the plateau) it is therefore a random decision of which black line it will end up follow. Furthermore, another problem with using only one light sensor occurs when the light sensor has to detect if the Lego car is on the top plateau. Using only one light sensor to do this is impossible since the only way to detect this with this kind of sensor is by measuring a black or white value. Since these measurements are taken throughout the track, it cannot detect if it is on top of the ramp.
|
|
|
|
|
|
To overcome some of these obstacles we choose to implement two sensors. Instead of making the car turn towards the black line, it turns away and then trying to keep the line in between them.
|
|
|
|
|
|
The first problem seen in the video with the PIDcontroller happens on the first plateau where the line split. By using two sensors and some hard coding, we implement a switch-case for each of the plateau’s (code beneath). At each plateau, one way or the other, the two sensors will reach a condition where both sensors reads a value that is equivalent to the calibrated black threshold. When this occurs, a counter decides which time this happens, and executes the code. For example, on the first plateau, the sensors will at some point read black at the same time, as seen in picture 3 below.
|
|
|
|
|
|
|
|
|
![the point where both sensors touch a black line](http://gitlab.au.dk/uploads/u4099/legolabtimadala/25e09a454e/the_point_where_both_sensors_touch_a_black_line.jpg)
|
|
|
##### Picture 3: The moment where both sensors complies with the black threshold.
|
|
|
|
|
|
|
|
|
This sets the counter to one (since this is the first measurement where the criteria for the black threshold is fulfilled by both sensors ). Subsequently, it executes the following code:
|
|
|
|
|
|
´´´
|
|
|
|
|
|
switch (counter){
|
|
|
|
|
|
case 1:
|
|
|
Car.forward(70, 70);
|
|
|
Thread.sleep(300); //0
|
|
|
Car.forward(100, 50);
|
|
|
Thread.sleep(1200); //750
|
|
|
Car.forward(70, 70);
|
|
|
Thread.sleep(800); // 1000
|
|
|
counter = counter + 1;
|
|
|
turnTime = (int) System.currentTimeMillis();
|
|
|
powerLeft = 65;
|
|
|
powerRight = 80;
|
|
|
break;
|
|
|
´´´
|
|
|
##### Codesnippet 1 [4]
|
|
|
|