Attendees: Jesper Jakobsen, Mads Hansen Lund og Michael Nygaard Pedersen
Goal
In this lesson we will modify the LEGO 9797 car and make it 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.
Sub goals
To build a simple robot inspired by the LEGO 9797 building instructions.
To evaluate a black and white distinguisher java class and expand the functionality to also detect the color green.
Plan
· Build a robot with a light sensor
· Code the robot and evaluate the result based on default code
· Experiments involving different environments to evaluate color distinguishing performance
· Test the expanded class and implement line follower functionality
Results
Description of experiment
Beneath the main sequence of the line follower combined with a stop sequence is presented. A “time1” variable is declared once with starts. The total operation time (totalTime) is calculated in the stop sequence.
// Line follower
if (sensor1.light() <>
// On white, turn right
Car.forward(0, power);
}
else{
Car.forward(power, 0);
}
// Stop at green
if( sensor1.light() <> sensor1.getGreenValue()-Hysteresis){
time2 = System.currentTimeMillis();
totalTime = time2 – time1;
Car.forward(0, 0);
}
Programming attempts
The original code was expanded and will now calibrate for three different colors. The main functionality is shown beneath.
public boolean black() {
return (ls.readValue()< blackWhiteThreshold && ls.readValue()< blackGreenThreshold);
}
public boolean white() {
return (ls.readValue()> blackWhiteThreshold && ls.readValue()> greenWhiteThreshold);
}
public boolean green() {
return (ls.readValue()< greenWhiteThreshold && ls.readValue()> blackWhiteThreshold);
}
Measurements
The light sensors have been evaluated in Lab session 1
Light reflection measurements
| Sensor 1 | Sensor 2 | Sensor 3 |
Lightgreen | 29 | 25 | 30 |
Green | 23 | 16 | 23 |
White | 33 | 28 | 33 |
Black | 22 | 15 | 22 |
Table 1 – Measurement made to distinguish between white, green and black
Pictures of Lego model
Figure 1 - Picture of robot
Problems encountered
The battery is a common issue when building a NXT robot. The robot performs very bad, if the battery is not fully charged.
Conclusion
The color disguising class can easily be expanded and a stop sequence has been added to the line follower code with success.
References
Ref 1 http://legocarsten.blogspot.com/2009/09/lab-session-1.html
Ingen kommentarer:
Send en kommentar