tirsdag den 4. marts 2014

Week 5 - Lesson 4

Date: 28/2-2014 (round 1), 4/3-2014 (round 2)

Duration of activity: 10.15 - 16.30 (round 1), 10.30 - 13.00 (round 2)


Group members participating:

Benjamin, Christina, Levi


Goal for the lab session:

Complete all the exercises for this weeks lab session [0].


Plan for the activities: Go through the exercises one by one, completing them to the extent possible.


Results obtained during lab session:

Black White Detection


We have made a program that use and test the class BlackWhiteSensor.java. After the car had been calibrated, we placed the car with the light sensor over different areas on a board with black, white, green and blue colors.


When placing the car around the board and measuring on the colors black, white and green, we got very different readings depending on the flatness of the paper board and maybe also depending on how dirty the paper board was. The span of readings for each of the colors are as follows:

Black: 34-40,

Green: 44-50

White: 57-60



A video that shows the calibration and testing of the program is here:


Line Follower with Calibration
The program LineFollowerCal.java is an an application of the BlackWhiteSensor class.
The behavior when running the calibrated LineFollower is shown in the video below:

ThreeColorSensor with Calibration


We have made a program ThreeColorSensor [1] that can detect three colors: black, green and white.
As shown in the black white exercise, the three colors have a threshold range distant from each other. Furthermore we also know that the green threshold range is between black and white. In the code we utilize this knowledge, by instead of calibrating all three colors, we only calibrate on the green color. This way for the green color we define a threshold range by measuring a value in the calibration, and then set the top threshold to measured value + 2, and bottom threshold to measured value - 2. When the value is above the top threshold, the color is white, and when it is below the bottom threshold, the color is black.



The program is able to detect the color green

Line Follower that stops in a Goal Zone

We copied LineFollowerCal, made it use our custom ThreeColorSensor, and added an else if statement that would check if there was a green value measured. If so, the car would drive forward with 0 speed, and thus 'float' to stop (instead of instant braking). This way there is a chance that the car will float forward to a new color, in case it would measure a value within the green threshold range on the edge between the black and the white area.



A video that shows the program running with it first being calibrated to the green color in the goal zone is shown here:




In the video it can be seen that the car stops within about 1 sec after driving into the light green goal area. When the car stops the light sensor is about 5 cm into the green zone area. This is because the car makes the ‘float stop’ instead an immediate stop, which makes the car come to a stop a bit later.


A video that shows the car running with the same program, except for the car being stopped (with Car.stop()) when reaching green lights is shown here:

It is clear that the car stops much faster when reaching the green zone area than with the float stop.
Another influence on the running of the car when making a full stop instead of a ‘float stop’ is that the car runs less smooth on the black line on the white area, because is sometimes in the border between black and white gets a reading that the program interprets as having gone over a green area. When this happens the car makes a full stop, before driving a bit forward again because it got a new reading of either black or white. This makes the driving a more jagged and run less smooth. A video that shows that the cars runs jagged is here:

Sometimes though, no new reading says that the car has reached a black or white area before the car actually stops fully, causing the car to stand still, and not beginning to drive again, if not someone gently redirects the car away from the edge.
A video that shows this is here:


We tried putting the car on another track with a black line and some green zones, but the green color on this track was different from the light green that the car had been calibrated with.
A video of this is here:
The video shows that the car doesn't stop when reaching a green area. As we suspected, is doesn't react to this type of green because it is calibrated to another type of green.

The problem is for sure not in general the type of green being calibrated against, as the program ran fine (and the car stopped nicely upon encountering a green area) if the program was just calibrated with the green color on the track that is was going to run on. A video of this is here:

PID Line Follower


We implemented a PID regulator to make the car run more smooth. The code was greatly inspired by the psuedocode for a PID controller, as described in this weeks lesson litterature. We used trial and error with different numbers for pGain, iGain and dGain in order to get a satisfying result.
Below is the code for the program:

public class LineFollowerPID { public static void main (String[] aArg) throws Exception { float pGain = 5.0f, iGain = 0.4f, dGain = 110.0f, offset, integral = 0, derivative, error; int lastError = 0, light, tp = 100, power; BlackWhiteSensor sensor = new BlackWhiteSensor(SensorPort.S3); sensor.calibrate(); offset = sensor.getThreshold(); LCD.clear(); LCD.drawString("Light: ", 0, 2); while (! Button.ESCAPE.isDown()) { light = sensor.light(); error = light - offset; integral = integral + error; derivative = error - lastError; power = (int) (pGain*error + dGain*derivative + iGain*integral); Car.forward(tp+power, tp-power); lastError = (int) error; LCD.drawInt(sensor.light(),4,10,2); LCD.refresh(); Thread.sleep(10); } Car.stop(); LCD.clear(); LCD.drawString("Program stopped", 0, 0); LCD.refresh(); } }


A video that shows how the car drives can be seen here.

Color Sensor

The three color sensor measures some values and then uses these values to output which color the color sensor believes it is measuring.

Some pictures that show the sensor measuring true values are shown below.
 

The color sensor is pretty sensitive to reflections from the paper. This means that small irregularities with regards to height, in the paper that the car is driving on, means that the sensor registers black when it should be registrering white and vice versa, at some points on the paper. When many measures in a row of the color are wrong, the car starts taking of in the wrong direction, and can’t correct itself back to the line.
A video that shows this is here:
We thought that lowering the power with which the car runs might help, because the error wouldn’t have the opportunity to accumulate as much before getting the correct measurement of color. This proved to be somewhat true, because the car this way could actually follow the line for about 5 cm before taking off in the wrong direction, not following the line anymore.
The video shows that the car seems to start going in the wrong direction at approximately the same point on the paper. This may be due to a height change in the paper at this point.

We did try to switch out our color sensor with one from a different group, but instead of registrering white as black, as described above, it often registered white as green, making the car come to a full stop.We haven't tried further to make the car follow a line with the three color sensor.

Conclusion
We have completed the exercises for the week and played around with the three color sensor.


References



Ingen kommentarer:

Send en kommentar