... | ... | @@ -134,166 +134,33 @@ In the datalogger class we had to replace FileOutputStream with BufferedOutputSt |
|
|
>
|
|
|
>
|
|
|
> #### Task
|
|
|
> Use the ThreeColorSensor to make a line follower that stops in a green goal zone.
|
|
|
>Both the robots in [2] and [3] use the light sensor to measure the tilt of the robot by measuring the distance to the surface. In [5] and [6] other more reliable types of sensors are used to measure the tilt of the robot during balancing. One such sensor is the HiTechnic gyro sensor, investigate the readings from the gyro sensor and how they relate to the motion of the gyro sensor. As a simple tool for such an investigation use the program GyroTest.java. Estimate the offset of the gyro sensor, [9], [10], when the sensor is not moving and experiment with the gyro sensor drifts e.g. when motors are activated.
|
|
|
>
|
|
|
> #### 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.
|
|
|
> We plan to do some experiments with placement of the gyro, as we suspect that precision of the gyro sensor is dependent on where it is placed on the robot. At first, we will try using the gyro as the only sensor mounted on the smaller robot with the higher centre of gravity.
|
|
|
>
|
|
|
>#### Results
|
|
|
>Afterwards we will try mounting the gyro on the tall robot with the lower centre of gravity and combine the gyro sensor input with the readings of a light sensor to see if we can prevent the offset value of the gyro sensor from drifting.
|
|
|
>
|
|
|
> From the NXT time blog, we know that gyro sensors measure how fast that they are rotating [9], ie degrees of angle per second. Therefore it cannot know which way it is currently facing, just that it is either still, or moving in a certain direction.
|
|
|
|
|
|
> We figured that If the distance from the sensor to the center of gravity of the robot is large, the gyro sensor will have a wider path to swing, making the values larger, as can be seen in (fig. 6).
|
|
|
>
|
|
|
>After the implementation the code with our PID controller looked like this:
|
|
|
>![Gyro sensor udsving (1)](http://gitlab.au.dk/uploads/group-22/lego/b48fa6e6d9/Gyro_sensor_udsving__1_.jpg)
|
|
|
> ##### Fig. Swing path of gyro sensor.
|
|
|
>
|
|
|
> ```
|
|
|
> We ran the GyroTest class to examine the readings of the gyro sensor. The default sensor reading (raw value) when stationary was about 611-612 on a scale from 0 to 1024. By shaking the robot hard, we could get the minimum reading down to 184, and the maximum reading up to 1003. It was hard to read the on screen values of the gyro sensor when the robot was going, so we tried implemented the data logger to get some more accurate readings. NOPE?
|
|
|
>
|
|
|
> 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();
|
|
|
> }
|
|
|
>
|
|
|
> ```
|
|
|
> #### Results
|
|
|
>
|
|
|
>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.
|
|
|
> Forventet resultat:
|
|
|
Gyroers offset drifter når den trækker strøm fra samme batteri som de to elmotorer alt efter om motorerne kører på samme tid.
|
|
|
Desuden kan lav spænding på batteriet også påvirke gyroens offset.
|
|
|
>
|
|
|
>---
|
|
|
>
|
|
|
>## 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
|
|
|
>
|
... | ... | |