@@ -81,8 +81,45 @@ Second: We implement the methods for the motors.
...
@@ -81,8 +81,45 @@ Second: We implement the methods for the motors.
As seen in the video the car detects both the black line, and the white and green zones - in which it stops perfectly. The car has some problems when going from the ramp and down the hill.
As seen in the video the car detects both the black line, and the white and green zones - in which it stops perfectly. The car has some problems when going from the ramp and down the hill.
The below codesnippet is the implemented code, the thresholds for the colors are calibrated each time the program starts, furthermore they are allowed to differ +-2 in relation to the detected value.
```
public class carLineFollower1 {
public static void main(String[] args) throws Exception {
BlackWhiteSensor sensor = new BlackWhiteSensor(SensorPort.S3);
int power = 80;
sensor.calibrate();
LCD.clear();
LCD.drawString("Light: ", 0, 2);
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();
}
Thread.sleep(10);
}
Car.stop();
LCD.clear();
LCD.drawString("Program stopped", 0, 0);
LCD.refresh();
}
}
```
##### CodeSnippet1: Implemented code for the three color sensor + line follower that stop in green zone.[6]
#### Conclusion
#### Conclusion
Because of the increase in the height of the sensor when going from the ramp and downhill, the robot detects another light percentage, and thereby it don’t know what to do with this value. This could maybe solved by increasing the sample interval so it won’t check as quickly or forcing the motors to run for a very small interval of time, instead of, as it is now, only run when detecting the right value. This would require some more testing, and hopefully more solutions will come next time we look at this experiment.
Because of the increase in the height of the sensor when going from the ramp and downhill, the robot detects another light percentage, and thereby it don’t know what to do with this value. This could maybe be solved by increasing the sample interval so it won’t check as quickly or forcing the motors to run for a very small interval of time, instead of, as it is now, only run when detecting the right value. Further, using a mean as the threshold for the black and white could solve the problem. However, this would require some more testing, and hopefully more solutions will come next time we look at this experiment.
### Exercise 5 - PID Line Follower
### Exercise 5 - PID Line Follower
...
@@ -162,7 +199,7 @@ public class PIDCarController {
...
@@ -162,7 +199,7 @@ public class PIDCarController {
}
}
}
}
```
```
##### CodeSnippet1: The implement code in our PID controlled line follower program.
##### CodeSnippet2: The implement code in our PID controlled line follower program.[7]
#### Conclusion
#### Conclusion
...
@@ -187,4 +224,5 @@ Lastly, we will check if it Is possible to use the color sensor for both followi
...
@@ -187,4 +224,5 @@ Lastly, we will check if it Is possible to use the color sensor for both followi