|
sda |
|
> # Group-22: Lab Notebook 4
|
|
\ No newline at end of file |
|
>
|
|
|
|
> #### Date: 10/3/2015
|
|
|
|
>
|
|
|
|
> #### Group members participating:
|
|
|
|
> * Christian Bonde Andersen
|
|
|
|
> * Nikolaj Cilleborg Haulrik
|
|
|
|
> * Rasmus Meldgaard Petersen
|
|
|
|
> * Claus Hedeager Rasmussen
|
|
|
|
> * Jesper Kurtzmann Svith
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>#### Activity duration:
|
|
|
|
> 3+7+3 hours
|
|
|
|
>
|
|
|
|
>#### Overall goal
|
|
|
|
>To make the LEGO 9797 car follow a black line and stop at the end of the line. When the car drives into a goal zone - a green rectangular piece of paper at the end of the black line. The idea is that we will try to use the light sensor to detect three different colors. Besides that we will attempt to implement a PID controller so that the robot will follow a line more smoothly.
|
|
|
|
>
|
|
|
|
>---
|
|
|
|
>
|
|
|
|
>## Exercise 1: Black White Detection
|
|
|
|
>
|
|
|
|
>#### Task
|
|
|
|
>Mount the sensor on the car and make a program that use and test the class BlackWhiteSensor.java. After calibration, place the car with the light sensor over different dark and bright areas and investigate how well the BlackWhiteSensor works.
|
|
|
|
>
|
|
|
|
>#### Plan
|
|
|
|
>We first mounted the light sensor on the car as showed on the picture below. The light sensor is placed just above the ground surface. After mounting the sensor we tested the readings on different surfaces and under different light settings. These findings are presented in a table under the results section.
|
|
|
|
>
|
|
|
|
> ![1](http://gitlab.au.dk/uploads/group-22/lego/974492fb01/2.jpg)
|
|
|
|
>
|
|
|
|
>#### Results
|
|
|
|
> We decided to test the light sensor under different settings. First we tested how it reads black and white values at different surfaces (plastic and paper) and under different light settings (dark and bright). As further investigation we tested how the sensor is able to detect dark green and light green. The findings from the light sensor tests are presented in the table below:
|
|
|
|
>
|
|
|
|
> | Black reading | White reading | Black White Difference | Black White Threshold| Dark Green reading | Light Green Reading | Green Difference| Green Threshold |
|
|
|
|
> | -------- | -------- | -------- |--------|-------- |--------|--------|--------|--------|
|
|
|
|
> | Bright Room Paper surface | 33 | 55 | 22 | 44 | 39 | 44 | 3 | 41 |
|
|
|
|
> | Bright Room Plastic surface | 25| 52 | 27 | 38 | 34 | 32 | 1 | 33 |
|
|
|
|
> | Dark Room Paper surface | 28 | 52 |24 | 40 | 34 | 34 | 0 | 34 |
|
|
|
|
> | Dark Room Plastic surface | 26 | 47 | 21 | 36 | 24 | 28 |4| 26 |
|
|
|
|
|
|
|
|
>
|
|
|
|
>
|
|
|
|
> ##### Black and White results:
|
|
|
|
>
|
|
|
|
>The results show that the sensor is able to distinguish black from white under both dark and bright light settings. With "Black White Difference" the table shows a significant difference above 20 for all black-white readings. It also shows that the surface did have a small impact on the readings as the "Black White Difference" changed according to the surface. It is also worth to notice that the "Black White Difference" was generally larger under bright light settings.
|
|
|
|
>
|
|
|
|
>
|
|
|
|
> ##### Dark Green and Light Green Results:
|
|
|
|
>
|
|
|
|
> As an extension we also tested the sensor in a setting where the two colors to be distinguished were closer to each other. For this purpose we chose green. The table shows that the sensor generally has a hard time differentiating the green colors regardless of the surface. However it seems to be possible under bright light settings with a paper surface and under dark settings with a plastic surface. It is interesting that the "green difference" changes from nothing (0) to 4 when changing the surface under dark settings. The reason for this behavior might be that plastic has a better capability to reflect the light from the color sensor due to it's reflective surface.
|
|
|
|
>
|
|
|
|
>---
|
|
|
|
>
|
|
|
|
>## Exercise 2: Line Follower with Calibration
|
|
|
|
>
|
|
|
|
>#### Task
|
|
|
|
>Try the LineFollowrCal.java. The program uses the simple class Car.java to move the car.
|
|
|
|
>
|
|
|
|
>#### Plan
|
|
|
|
> Upload the code to the robot and observe what happens.
|
|
|
|
>
|
|
|
|
>#### Results
|
|
|
|
>After running the LineFollowerCal.java we observed that it runs fine along a black line but as soon it encounters a different color eg. green or grey it starts spinning uncontrollably. This is partly due to the program only distinguishing between black and non-black colors. This means that whenever the robot encounters a color different from black it will diverse from its course. From this point it might not detect black colors even though it drives over a black line due to its sample interval of 10ms. This interval makes the robot detect colors once every 10ms and all other time it is blind to it's surrounding meaning that we cannot be sure that i makes a reading as it drives over black.
|
|
|
|
>
|
|
|
|
>---
|
|
|
|
>
|
|
|
|
>## Exercise 3: ThreeColorSensor with Calibration
|
|
|
|
|
|
|
|
>
|
|
|
|
>#### Task
|
|
|
|
>Use the idea and structure of the BlackWhiteSensor to program a class ThreeColorSensor that can detect three colors: black, green and white. Make a test program that investigate the usefulness of the class.
|
|
|
|
>
|
|
|
|
>#### Plan
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>We implemented a third possibility in the BlackWhiteSensor class, which is green. The program is still using the light sensor to determine the values of light from the table. With the corrections to the code, we had the possibility to sample black, white and green.
|
|
|
|
>In Lab session 1 [1] we used the light sensor to figure out the values of different colors - Green had a value between black and white. We used these findings to determine that we needed two new thresholds in the code. To distinguish between the three different colors we changed the thresholds in the code between white & green and black & green. The white’s values are the highest and the black are the lowest, so in order to determine green, we know that it has to be between black and white.
|
|
|
|
>
|
|
|
|
>By calibrating the colors before the cars starts running it is possible to find the median between the colors to create a threshold which leaves room for some error. We also rewrote some of the code to give us the raw values of the lightsensor, as the results between black and green were pretty close when using the readValue() method, this left us with a bit more precise readings and a slightly larger error margin.
|
|
|
|
|
|
|
|
>#### Results
|
|
|
|
|
|
|
|
>During the initial testing, we found that the program would work as intended with the robot driving right when the light sensor read a low (dark) value and left when the light sensor read a high (light) value. The problem occurred when the light sensor settled on the border between the black line and the white space around it within a few seconds. This meant that the reading it got was a median value between the high and low color thresholds. The resulting combined value was too similar to the light value for the color green. This meant that the robot saw this value as green in the code and stopped as was intended when it read a similar light value for the real color green.
|
|
|
|
> ![3](http://gitlab.au.dk/uploads/group-22/lego/a4841d7341/3.png)
|
|
|
|
>
|
|
|
|
>From this exercise we can conclude that the light sensor is not very useful for navigating based on following specific lines of specific colors, as the way that the light sensor works
|
|
|
|
>
|
|
|
|
>---
|
|
|
|
>
|
|
|
|
>## Exercise 4: Line Follower that stops in a Goal Zone
|
|
|
|
>
|
|
|
|
>
|
|
|
|
> #### Task
|
|
|
|
> Use the ThreeColorSensor to make a line follower that stops in a green goal zone.
|
|
|
|
>
|
|
|
|
> #### Plan
|
|
|
|
> We now intended to use the colour thresholds made in exercise to distinguish between black,
|
|
|
|
> white and green.
|
|
|
|
>
|
|
|
|
> Code snippet from ThreeColorSensor class:
|
|
|
|
> ```
|
|
|
|
> public boolean white() {
|
|
|
|
> greenCount = 0;
|
|
|
|
> return (ls.readNormalizedValue()> whiteGreenThreshold);
|
|
|
|
> }
|
|
|
|
>
|
|
|
|
> //Returns true if threshold is under white and over black
|
|
|
|
> public boolean green() {
|
|
|
|
> greenCount += greenCount + 1;
|
|
|
|
> if (greenCount > 300)
|
|
|
|
> return (ls.readNormalizedValue()>whiteGreenThreshold && ls.readNormalizedValue()> > greenBlackThreshold);
|
|
|
|
> else return false;
|
|
|
|
> }
|
|
|
|
> ```
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>[![image alt text](http://img.youtube.com/vi/aU9JqzJGzx0/0.jpg)](http://www.youtube.com/watch?v=aU9JqzJGzx0)
|
|
|
|
> ##### Fig. 1: The robot follows the line and stops just short of the green zone.
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>#### Results
|
|
|
|
>As can be seen in the video (Fig. 1), the ThreeColorSensor program makes the robot follow the black line oscillating in small turns between the black and the white areas until it enters the green area. The movement is not very smooth however, and only the sensor of the robot enters the green area and then the robot stops.
|
|
|
|
Our issue was that our code could not distinguish between the light sensor reading half black and half white, and the colour green. This was the same issue as we encountered in exercise 3. We therefore still ran the risk of halting at the edge of a black line instead of going into the green zone and stopping.
|
|
|
|
We implemented a simple integer that was increased by one when the threshold was between the thresholds determined as “green”. Unfortunately we now got the problem that the light sensor would internet the edge of the black/white line as the light value for green. This means that it will drive off from the line at an angle, instead of following it like it should. We still need to find a better way of distinguishing between white/black and green with the light sensor, but we are not sure that such a thing is possible without a more advanced colour sensor.
|
|
|
|
>
|
|
|
|
>---
|
|
|
|
>
|
|
|
|
>## Exercise 5: PID Line Follower
|
|
|
|
>
|
|
|
|
>#### Task
|
|
|
|
>
|
|
|
|
>Implement the PID controller as described in [2].
|
|
|
|
>
|
|
|
|
>#### Plan
|
|
|
|
>
|
|
|
|
>We intend to follow the guide step by step and implement the code into the LineFollowerCal.java code exampel from the tutorial plan. After the implementation we will try adjusting the PID constants to achieve a smooth ride along the line.
|
|
|
|
>
|
|
|
|
>#### Results
|
|
|
|
>
|
|
|
|
>After the implementation the code with our PID controller looked like this:
|
|
|
|
>
|
|
|
|
> ```
|
|
|
|
>
|
|
|
|
> BlackWhiteSensor sensor = new BlackWhiteSensor(SensorPort.S3);
|
|
|
|
>
|
|
|
|
> sensor.calibrate();
|
|
|
|
>
|
|
|
|
> LCD.clear();
|
|
|
|
> LCD.drawString("Light: ", 0, 2);
|
|
|
|
>
|
|
|
|
> // Variabler til PID
|
|
|
|
>
|
|
|
|
> // P led
|
|
|
|
> int Kp = 300; //Proportional controller
|
|
|
|
> int offset = sensor.getThreshold();
|
|
|
|
> int Tp = 50; // Target power. Den verdi der bruges nor error er 0
|
|
|
|
>
|
|
|
|
> // I led
|
|
|
|
> int Ki = 0; // Integral constant
|
|
|
|
> int integral = 0;
|
|
|
|
>
|
|
|
|
> // D led
|
|
|
|
> int Kd = 0; // Derivative constant
|
|
|
|
> int lastError = 0;
|
|
|
|
> int derivative = 0;
|
|
|
|
>
|
|
|
|
>
|
|
|
|
> while (! Button.ESCAPE.isDown())
|
|
|
|
> {
|
|
|
|
>
|
|
|
|
> LCD.drawInt(sensor.light(),4,10,2);
|
|
|
|
> LCD.refresh();
|
|
|
|
>
|
|
|
|
> int LightValue = sensor.light();
|
|
|
|
> int error = LightValue - offset;
|
|
|
|
>
|
|
|
|
> integral = integral + error;
|
|
|
|
>
|
|
|
|
> derivative = error - lastError;
|
|
|
|
>
|
|
|
|
> int Turn = Kp*error + Ki*integral + Kd*derivative;
|
|
|
|
> Turn = Turn/100;
|
|
|
|
>
|
|
|
|
> int powerLeft = Tp + Turn;
|
|
|
|
> int powerRight = Tp - Turn;
|
|
|
|
>
|
|
|
|
> Car.forward(powerLeft, powerRight);
|
|
|
|
>
|
|
|
|
> lastError = error;
|
|
|
|
>
|
|
|
|
> Thread.sleep(50);
|
|
|
|
> }
|
|
|
|
>
|
|
|
|
> Car.stop();
|
|
|
|
> LCD.clear();
|
|
|
|
> LCD.drawString("Program stopped", 0, 0);
|
|
|
|
> LCD.refresh();
|
|
|
|
> }
|
|
|
|
>
|
|
|
|
> ```
|
|
|
|
>
|
|
|
|
>We started adjusting the numbers for the PID constants but we did not have time to find the desired values before it was time to hand in. Therefore we have not yet fully completed a satisfying PID controlled line follower robot.
|
|
|
|
>
|
|
|
|
>---
|
|
|
|
>
|
|
|
|
>## Exercise 6: Color Sensor
|
|
|
|
>
|
|
|
|
>#### Task
|
|
|
|
>In the LEGO Mindstorms series there is a color sensor. Use the test program ColorSensorSensor.java to investigate the information that the class ColorSensor provide in Full mode.
|
|
|
|
>
|
|
|
|
>#### Plan
|
|
|
|
>To place the color sensor over black, white and green to figure out if the information provided can be used to distinguish the three colors.
|
|
|
|
>
|
|
|
|
>![nxt-color-sensor](http://gitlab.au.dk/uploads/group-22/lego/642da6f7be/nxt-color-sensor.jpg)
|
|
|
|
>
|
|
|
|
>#### Results
|
|
|
|
>We tested the color sensor on paper with colors green, white and black. The color sensor has three inputs (red, green and blue). The results are shown in the table below:
|
|
|
|
>
|
|
|
|
> | | Red reading | Green reading | Blue reading | Light reading |
|
|
|
|
> | -------- | -------- | -------- | -------- | -------- |
|
|
|
|
> | White paper | 590 | 605 | 584 | 535 |
|
|
|
|
> | Green paper | 470 | 524 | 454 | 400 |
|
|
|
|
> | Black paper | 368 | 375 | 355 | 285 |
|
|
|
|
>
|
|
|
|
> The table shows red, green and blue readings on different paper colors. White paper results in high values and black paper results in low values. Green paper has values higher than black but lower than white.
|
|
|
|
>
|
|
|
|
>In order to use these values to distinguish between the three colors we suggest looking at the raw values as they are the most accurate readings the sensor can provide. If we want to detect green color we look at the raw color sensor value "Green". If this value is significantly higher (should invesigated further) than the raw values of red and blue, the color is green. If we want to detect the color black we will look at the color sensors getRawLightValue(). If the light value is low the color is black. Likewise if it is high the color is white. The reason why the color sensor might be better than the light sensor is that it not only serves as a color detector but also a light detector.
|
|
|
|
>
|
|
|
|
>This method is not 100 % accurate and some colors close to green may also result in a green interpretation, but it should still be able to distinguish the three colors apart.
|
|
|
|
>
|
|
|
|
> ## Conclusion
|
|
|
|
> Through this lab session we gained experience using a light sensor for black white
|
|
|
|
> detection. Readings were collected in different rooms with different light settings and
|
|
|
|
> results showed that we were able to distinguish black from white under various light
|
|
|
|
> settings.
|
|
|
|
>
|
|
|
|
> To extend our work with the light sensor we mounted the color sensor with a goal to
|
|
|
|
> distinguish between three colors (black, white and green). When implementing a line follower
|
|
|
|
> we encountered some problems with the three color distinction as the car robot’s navigation
|
|
|
|
> relies on input from the color sensor. When it detects white it moves in one direction and
|
|
|
|
> another when it detects green. The problem occurs when the sensor is between the black and
|
|
|
|
> white line. This causes the sensor to read medium values eg. green even though no green
|
|
|
|
> space is present.
|
|
|
|
>
|
|
|
|
> The three color sensing robot was later modified according to the problem. To deal with the
|
|
|
|
> problem of medium values we made the robot count how many green readings were made before it
|
|
|
|
> detects it as a goal zone. This means that the robot will only stop when it reads a certain
|
|
|
|
> amount of consecutive green values.
|
|
|
|
>
|
|
|
|
> Later we implemented a PID control structure on the car resulting in the car driving in a
|
|
|
|
> smooth path. Due to lack of time we did not have adequate time to explore and tweak the
|
|
|
|
> values of the PID. This means that the PID controlled line follower was not completed to
|
|
|
|
> full extend.
|
|
|
|
>
|
|
|
|
> ## References
|
|
|
|
>
|
|
|
|
> Video:
|
|
|
|
> * Exercise 3: http://youtu.be/wlh4UXzuPlk
|
|
|
|
> * Exercise 5: http://youtu.be/UMSrPEmQrwE
|
|
|
|
> * Exercise 6: http://youtu.be/MxLNTdugOnA
|
|
|
|
>
|
|
|
|
> Code:
|
|
|
|
> * Full code from our programs can be found here: https://drive.google.com/?tab=wo&authuser=0#folders/0B2Ko0NOiIJolaDg2SllGZ2p0TGM
|
|
|
|
>
|
|
|
|
> Links:
|
|
|
|
>
|
|
|
|
> [1] https://gitlab.au.dk/group-22/lego/wikis/home - exercise 1 & 2, table 1
|
|
|
|
>
|
|
|
|
> [2] http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html |
|
|
|
\ No newline at end of file |