Thursday, September 30, 2010

Lab Exercise 5

Date:
30/9 2010

Duration of activity:
3.5 hours

Group members participating:
Frederik, Lasse & Christian

Goals:
The main goal is to make a robot follow a black line and stop at the end of the line in the goal zone[1].

Plan:
1. Build a robot and mount the light sensor
2. Test a program that distinguishes between black and white and investigate its behavior on different colors.
3. Run a program that uses the black/white sensor program to follow a line
4. From experiences with programs in 2. and 3. make a program that distinguishes between black, white and green
5. Finally the program from 4. shall be used to make a line follower that stops in a green goal zone.


Results:
1. The robot was built according to the description in the Lego NXT Base Set 9797 building instructions page 32 to page 34. The result can be seen in action in section 3.

2. We modified the LineFollowerCal-class so instead of regulating the motors either black or white was written to display. Calibration values were black = 32, white =  59 and the threshold was then observed to be 44 although it should have been 46. This is probably because the values changed a bit during calibration.

3. The class LineFollowerCal was tested just to see how well a calibrated line follower performs. A video can be seen below.




4.We made a class called BlackWhiteGreenSensor[2] which extended the original BlackWhiteSensor with a green color. The test showed (as expected) that the robot detects green every time the color changes from white to black and vice versa.

5. Based on the observations made in 4. we wanted to improve both the SW and HW; replace the NXT sensor with two RCX sensors, improve BlackWhiteGreenSensor and use it with a new linefollower program.

We modified the robot by adding two RCX light sensors to be able to detect when we are inside or outside the black line. Image can be seen below:

Robot with two RCX light sensors


We added an enum to the BlackWhiteGreenSensor in order to get the current color. We also replaced the NXT light sensor by a RCX light sensor in the new BlackWhiteGreenSensor[3]. The idea about this is to use the same calibration values for both RCX sensors and we then only need to calibrate once a start up.

We made a new edition[4] of the previous line follower program by adding two RCX-sensors in the program. Apart from that we added a StopWatch-like functionality with the purpose of measuring how long time the sensor has measured green. When the time has passed the motors are stopped.

We wanted to have a minimum speed for each wheel so e.g. when turning a minimum speed of say 50 is applied to the motors. By experimenting we concluded that a minimum speed of around 50 was necessary to get the motor running.

The MotorPort class in the class Car was replaced by the Motor because we had problems getting the Motor to slow down fast enough, which was solved by using the Motor class. After that the robot performed quite good with a relatively high speed and able to stop in the goal zone.

Conclusion:
This exercise has shown that a calibration before doing the line following has a lot to say because the light condition varies a lot. A further improvement is replacing one light sensor with two. This makes the robot do a more real line following instead of just following the dividing line between black and white. To avoid the robot drives away from the track the motors need to be very responsive and we had the best results using the Motor class instead of the MotorPort class.

References:
[1] Lab Exercise 5 description - http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson5.dir/Lesson.html
[2] BlackWhiteGreenSensor - http://dl.dropbox.com/u/2389829/Lego/Lab5/BlackWhiteGreenSensor.java
[3] Extended BlackWhiteGreenSensor - http://dl.dropbox.com/u/2389829/Lego/Lab5/BlackWhiteGreenSensorExtended.java
[4] LineFollower with 2 sensors -  http://dl.dropbox.com/u/2389829/Lego/Lab5/LineFollower.java