Duration of activity: 5 hrs and 30 min
Group members participating: Alexander Rasmussen and Søren Ditlev
Lesson 4
Black White Detection
Goal:
Make a system that is able to distinguish between black and white
Plan:
Write a program that uses the BlackWhiteSensor.java class and the light sensor to detect the reflection level of black and white surfaces
White Surface
|
Black surface
|
Conclusion:
The system is able to detect the difference between black and white and is responding rapidly.
Line Follower with Calibration
Goal:
To make a system that can follow a line in a black and white environment
Plan:
Conclusion:
The car was able to follow a black line in a white environment.
ThreeColorSensor with Calibration
Goal:
Make a system that can distinguish between three colors: black, green and white
Plan:
Modify the BlackWhiteSensor.java class to calibrate for black and green, green and white. Thus making three different intervals.
Results:
To calibrate the sensor to recognise green we modified the BlackWhiteSensor.java to instead of having 1 threshold value, to have 2. By doing this it was possible to distinguish the different colors with black being below black green Threshold white being over green white threshold and green being in between.
Code from modified sensor class:
public boolean black() {
return (ls.readValue() < blackGreenThreshold);
}
public boolean white() {
return (ls.readValue() > greenWhiteThreshold);
}
public boolean green() {
return (ls.readValue() > blackGreenThreshold && ls.readValue() < greenWhiteThreshold);
}
Green surface
|
Conclusion:
The system is able to distinguish between the three colors black, green and white. However if the sensor is placed directly over a black/white transition it might return green.
Line Follower that stops in a Goal Zone
Goal:
Make a system that can follow a line and in black/white environment and stop once the color green is detected
Plan:
Results:
To stop the car we added an if statement checking for green color and stopping if true. Because the sesnor relies on a light value the transition between the black and white can give a reading which reads green, we managed to prevent it from stopping in these cases by implementing a counter, so that it had to be green in 10 ms before it took action.
Code from modified linefollower:
while (! Button.ESCAPE.isDown())
{
LCD.drawInt(sensor.light(),4,10,2);
LCD.refresh();
if(sensor.green()){
count++;
if(count > 100){
Car.stop();
LCD.drawString("Green!", 0, 0);
count = 0;
}
}
else if ( sensor.black() ){
LCD.drawString("Black!", 0, 0);
Car.forward(power, 0);
count = 0;
}else{
LCD.drawString("white!", 0, 0);
Car.forward(0, power);
count = 0;
}
Thread.sleep(1);
}
Conclusion:
The system works, but sometimes it stops because it detects green in a black/white transition. To combat this we added a counter that register the same value 10 times. This solved that transition problem, but had the side effect that the system did not always follow the line correctly.
PID Line Follower
Goal:
Make a linefollower system that follow a line smoothly and runs as fast a possible.
Plan:
Implement a PID controller to control the system and tune it using a PID guide[1]
Results:
Video: [3]
Values:
Parameters
|
Values
|
TP
|
90
|
KP
|
7
|
Ki
|
0.3f
|
KD
|
107
|
Conclusion:
By using the PID guide we were able to calculate the k values, once the k values were found we gradually turned up the TP value(motor power) in order to make the system drive as fast as possible without losing track of the line.
The system follows a line fast and smoothly, but if the system loses track of the line completely it just drive around in cycles. This is because the system adds the errors from the previous measurements in order to correct for futures reading, if multiple errors is measured in a row the collected sum of errors makes the algorithm skewed. The system is therefore unable to distinguish between balck and white.
Color Sensor
Goal:
Use the color sensor to make a lineFolllower system that functions in a black/white environment and stops in a green field.
Plan:
Results:
To implement the lineFollower using the color sensor, we used the same type of algorithm as in the lineFollower using the light sensor. Instead of using light values and distinguish the colors by calibrating threshold values, we used the color sensors function getColor.
while (! Button.ESCAPE.isDown())
{
Inner:
switch (cs.getColorID()){
case Color.BLACK:
LCD.drawString(""+cs.getColorID(), 0, 0);
Car.forward(power, 0);
break Inner;
case Color.WHITE:
LCD.drawString(""+cs.getColorID(), 0, 0);
Car.forward(0, power);
break Inner;
case Color.GREEN:
LCD.drawString(""+cs.getColorID(), 0, 0);
Car.stop();
break Inner;
}
}
Conclusion:
Unlike a light sensor, the color sensor does not make the mistake of detecting green when it is placed directly a black/white transitions. Therefor it was not necessary to make corrections like in the previous lineFfollowers, where multiple readings had to be detected as same color so that the system would not stop on back/white transitions.
References:
[3]PID lineFollower video: http://www.youtube.com/watch?v=hAY40lBeOB8&feature=youtu.be
Ingen kommentarer:
Send en kommentar