Duration of activity: 3 hours
Group members participating: Lukas, Daniela, Helene
Goals:
- Perform exercises from Lab Session 4
Plan:
- Mount the light sensor on the car.
- Do exercises 1-6
Exercise 1 - Black white detection
We mounted the light sensor on the car . We wrote a program using the BlackWhiteSensor.java.
Source code:
Exercise1.java
We calibrated the sensor by using the black and white areas of one of the lab tables. We then tried to check how good our program is at distinguishing between black and white surfaces. The sensor could distinguish between black and white surfaces, and to some degree dark and light colors, like yellow being detected as white and blue being detected as black. When a color was gray or its brightness right between black and white, the robot would print "not sure" on the display, which happened on the green goal-area of the lab tables. This means that it should be possible to make a distinction between white, green/gray and black, because there is enough difference between the intensities of the colors.
------------------------------------------------------------------------------------------------------------------
Exercise 2 - Line follower with calibration
We uploaded the LineFollowerCal.java and we observed the car's behavior.
The car is able to follow the black line. When it detects green it starts turning left. This can be explained by the fact that the program interprets the green color as being white.
Video 1
------------------------------------------------------------------------------------------------------------------
Exercise 3 - Three color sensor with calibration
We wrote a program that classifies sensor values as either white, black or green.
We made a class BlackWhiteGreenSensor.java based on the code of BlackWhiteSensor.java class.
We assumed, due to previous lab experiments and the first exercise, that the sensor value for green would be somewhere between the black and white values. We therefore defined two threshold values as the median between the readings of green and black and the readings of green and white:
blackGreenValue = (blackLightValue + greenLightValue)/2; greenWhiteValue = (greenLightValue + whiteLightValue)/2;
BlackWhiteGreenSensor.java
The BlackWhiteGreenSensor.java was then used in the following program in order to detect the three different colors:
Exercise3.java
We then uploaded the new program to the nxt car and made calibration of the three colors. Afterwards we tested that our program, and it was able to distinguish between the three colors when putting the sensor on the black, white and green surfaces of the lab tables.
------------------------------------------------------------------------------------------------------------------------
Exercise 4 - Line follower that stops in the green goal zone
We used the BlackWhiteGreenSensor.java class to make a program that follows a black line and stop at at a green area at the end of the line.
The while loop of the first LineFollower program was the following:
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();
} else {
Car.forward(0,power);
}
Thread.sleep(10);}
When running the program, we noticed how the car at times stopped on the edge of the black line, as it can be seen in the following video:
linefollower1.mp4
We argued that this happened, because on the edge of the line, the sensor catches both black and white light and the value returned (an average of black and white values over the sensed area) is interpreted as green in the logic of our program.
We then tried to make some changes to the program. In the new version of the program, when a sensor value is classified as green, we check for how long we have seen green. We let the car stop only if the time we have seen green is bigger than 70 ms. In this way we want to make sure that the car is really on a green spot, since if the car is in the edge of the line, the following readings should be either black or white. The entire code can be seen in the following link:
LineFollower2.java
We tested the program, and observed that the car now behaved as required by the exercise. The behavior with the new program can be seen in the following video:
linefollower2.mp4
-------------------------------------------------------------------------------------------------------------
Exercise 5 - PID line follower
We tried to implement PID control for the car. We did this by implementing the proportional, integral and derivative error as in lab session 2 exercise 5 (lab2). We then tried to find constants for the proportional, integral and derivative gain. We did this by trying different values and adjusting one the gains of the different factors.
We found some values where the car could drive along the line and stop in the green area. But we did not succeed in finding values that made the car drive smooth along the line.
Also, we had to let the robot drive slowly in order to drive correctly. When we tried to change the minimum speed to make it drive faster, it would consistently driver right though the line. At the end of the lab session, we did not find a set of values to let it drive fast and correctly.
We were missing some kind of methodology to come up with some set of values that would work nicely.
The source code for our PID line follower can be found here: PIDLineFollower
-------------------------------------------------------------------------------------------------------------
Exercise 6
We did't have the time to do this exercise.
Conclusions
Detecting colors with a light sensor can be tricky. Due to the fact that the returned values measure the light intensity, colors that reflect light with similar intensities are difficult to distinguish.
Furthermore, since the light intensity is measured over an area, black and white detection can also be messed up by the fact that the value returned is an average of the light intensities of the area. But the sensor was good enough do differentiate between white green and black, unless we would have a perfect PID controller that lets the robot drive perfectly on the line, then the measured light-intensity could be a gray value that always would match green. Then we would need to switch to two light sensors or a color-sensor.
Finding values for the gains of the PID controllers was hard, we could let the robot drive along the line, but it was neither smooth nor fast. We need to find a methodology to work towards a set of values that works. Maybe we need to slightly change the way the values are used for powering the motors or try to use the data-logger to get more detailed information on the oscillation and the value of the proportional, derivative and integral term and how they interact.
Exercise 5 - PID line follower
We tried to implement PID control for the car. We did this by implementing the proportional, integral and derivative error as in lab session 2 exercise 5 (lab2). We then tried to find constants for the proportional, integral and derivative gain. We did this by trying different values and adjusting one the gains of the different factors.
We found some values where the car could drive along the line and stop in the green area. But we did not succeed in finding values that made the car drive smooth along the line.
Also, we had to let the robot drive slowly in order to drive correctly. When we tried to change the minimum speed to make it drive faster, it would consistently driver right though the line. At the end of the lab session, we did not find a set of values to let it drive fast and correctly.
We were missing some kind of methodology to come up with some set of values that would work nicely.
The source code for our PID line follower can be found here: PIDLineFollower
-------------------------------------------------------------------------------------------------------------
Exercise 6
We did't have the time to do this exercise.
Conclusions
Detecting colors with a light sensor can be tricky. Due to the fact that the returned values measure the light intensity, colors that reflect light with similar intensities are difficult to distinguish.
Furthermore, since the light intensity is measured over an area, black and white detection can also be messed up by the fact that the value returned is an average of the light intensities of the area. But the sensor was good enough do differentiate between white green and black, unless we would have a perfect PID controller that lets the robot drive perfectly on the line, then the measured light-intensity could be a gray value that always would match green. Then we would need to switch to two light sensors or a color-sensor.
Finding values for the gains of the PID controllers was hard, we could let the robot drive along the line, but it was neither smooth nor fast. We need to find a methodology to work towards a set of values that works. Maybe we need to slightly change the way the values are used for powering the motors or try to use the data-logger to get more detailed information on the oscillation and the value of the proportional, derivative and integral term and how they interact.
No comments:
Post a Comment