... | ... | @@ -28,12 +28,12 @@ We will first mount the black and white sensor in the LEGO 9797 car. Afterwards |
|
|
|
|
|
#### Results
|
|
|
|
|
|
| "Color" | Light Value |
|
|
|
| -------- | ----------- |
|
|
|
| Black | 39+-1 |
|
|
|
| White | 58+-1 |
|
|
|
| Grey | 55+-1 |
|
|
|
| Green | 47+-1 |
|
|
|
| "Color" | Light Sample1| Light Sample2| Light Sample3|
|
|
|
| -------- | ------------ | ------------ | ------------ |
|
|
|
| Black | 39 | 38 | 37 |
|
|
|
| White | 57 | 59 | 57 |
|
|
|
| Grey | 55 | 56 | 54 |
|
|
|
| Green | 46 | 46 | 47 |
|
|
|
|
|
|
##### Table 1: Light values
|
|
|
|
... | ... | @@ -81,8 +81,45 @@ Second: We implement the methods for the motors. |
|
|
|
|
|
As seen in the video the car detects both the black line, and the white and green zones - in which it stops perfectly. The car has some problems when going from the ramp and down the hill.
|
|
|
|
|
|
The below codesnippet is the implemented code, the thresholds for the colors are calibrated each time the program starts, furthermore they are allowed to differ +-2 in relation to the detected value.
|
|
|
|
|
|
```
|
|
|
public class carLineFollower1 {
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
BlackWhiteSensor sensor = new BlackWhiteSensor(SensorPort.S3);
|
|
|
int power = 80;
|
|
|
|
|
|
sensor.calibrate();
|
|
|
|
|
|
LCD.clear();
|
|
|
LCD.drawString("Light: ", 0, 2);
|
|
|
|
|
|
while (! Button.ESCAPE.isDown())
|
|
|
{
|
|
|
LCD.drawInt(sensor.light(),4,10,2);
|
|
|
LCD.refresh();
|
|
|
if ( sensor.black() )
|
|
|
Car.forward(power, 0);
|
|
|
else if (sensor.white()){
|
|
|
Car.forward(0, power);
|
|
|
}
|
|
|
else if (sensor.green()){
|
|
|
Car.stop();
|
|
|
}
|
|
|
Thread.sleep(10);
|
|
|
}
|
|
|
Car.stop();
|
|
|
LCD.clear();
|
|
|
LCD.drawString("Program stopped", 0, 0);
|
|
|
LCD.refresh();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
##### CodeSnippet1: Implemented code for the three color sensor + line follower that stop in green zone.[6]
|
|
|
|
|
|
|
|
|
#### Conclusion
|
|
|
Because of the increase in the height of the sensor when going from the ramp and downhill, the robot detects another light percentage, and thereby it don’t know what to do with this value. This could maybe solved by increasing the sample interval so it won’t check as quickly or forcing the motors to run for a very small interval of time, instead of, as it is now, only run when detecting the right value. This would require some more testing, and hopefully more solutions will come next time we look at this experiment.
|
|
|
Because of the increase in the height of the sensor when going from the ramp and downhill, the robot detects another light percentage, and thereby it don’t know what to do with this value. This could maybe be solved by increasing the sample interval so it won’t check as quickly or forcing the motors to run for a very small interval of time, instead of, as it is now, only run when detecting the right value. Further, using a mean as the threshold for the black and white could solve the problem. However, this would require some more testing, and hopefully more solutions will come next time we look at this experiment.
|
|
|
|
|
|
### Exercise 5 - PID Line Follower
|
|
|
|
... | ... | @@ -153,7 +190,7 @@ public class PIDCarController { |
|
|
|
|
|
// Saves the current error so it can be the lastError next time
|
|
|
lastError = error;
|
|
|
Thread.sleep(5);
|
|
|
Thread.sleep(5);
|
|
|
}
|
|
|
Car.stop();
|
|
|
LCD.clear();
|
... | ... | @@ -162,7 +199,7 @@ public class PIDCarController { |
|
|
}
|
|
|
}
|
|
|
```
|
|
|
##### CodeSnippet1: The implement code in our PID controlled line follower program.
|
|
|
##### CodeSnippet2: The implement code in our PID controlled line follower program.[7]
|
|
|
|
|
|
#### Conclusion
|
|
|
|
... | ... | @@ -187,4 +224,5 @@ Lastly, we will check if it Is possible to use the color sensor for both followi |
|
|
3. [Video 1: LineFollowerCal.java[1] test.](http://www.youtube.com/watch?v=lHlDTTMl_9s)
|
|
|
4. [Video 2: Car following line and stops in green zone.](http://www.youtube.com/watch?v=a1tTYuLr3_0)
|
|
|
5. [Video 3: Line Follower with PID controller.] (https://www.youtube.com/watch?v=Qi-XYG67Eiw&feature=youtu.be)
|
|
|
6. [CodeSnippet1: The implement code in our PID controlled line follower program.](?????) |
|
|
\ No newline at end of file |
|
|
6. [CodeSnippet1: Implemented code for the three color sensor + line follower that stop in green zone.](???)
|
|
|
7. [CodeSnippet2: The implement code in our PID controlled line follower program.](?????) |
|
|
\ No newline at end of file |