Robotics Task 3: Line Following
Subject Area:
    Engineering and Technology

Age or Grade:
    9th through 12th grade

Estimated Length:
    4-5 class periods

Prerequisite knowledge/skills: 	
Simple Machines
Freshman physics and understanding of position, velocity and acceleration
Use of Microsoft Windows operating environment
Concepts learned in previous robotics tasks

Description of New Content:
    Students will build and program a robot to follow a thick black line using light sensors

Students will learn about:
a text-based programming structure
programming loop structures
conditional logic
flowcharts
linear  and rotational motion control
Motor Outputs
use of feedback with sensors
logical and syntax errors
the need for sensor inputs
light color and intensity
detection algorithms

Materials Needed: 	
LEGO Mindstorm kit for every 2-3 students
Computer for every Mindstorm kit
Brix Command center software
At least 6 AA batteries per kit (rechargeable recommended)
4x4' white-board sheet
1” black duct tape or similar
2 light sensors for each group

Procedure

On a 4'x4' whiteboard, use the 1" duct tape to make an arbitrary path with turns with a radius or curvature no smaller than 12".

Introduce the light sensor to the class and discuss how it works and the factors that affect how much light it receives. Some of these factors are:
Surface color (white reflects, black absorbs)
surface finish (glossy, rough)
Distance from surface to sensor
Background lighting conditions

Hold a class discussion on how the robot can detect if it is over a white or black surface. Make it clear to students that the light values depend on the design of the robot and the factor discussed above. Also, make it clear that the light sensor is doing nothing but reading the intensity of light in front of it and the surface color is simply light being reflected where black reflects little light and white reflects a lot of light.

Before students attempt the line following program, let them spend a class period programming a robot that will keep itself from driving off a table using a light sensor (the table will have to be a light color). This will introduce them to the threshold values that must be understood when using the light sensors. For example, when the light sensor is over the table, it may read a value about 40. But when the light sensor is hovering over the edge of the table (free space) it may only read a value of 20. So setting a threshold value at 35 might be a good choice, meaning "if the light sensor reads above or equal to 35, drive forward, otherwise stop, backup and turn and then drive forward again..." Make it clear to students that they need to track the robot and be ready to catch it in case their program fails and the robot falls off.

After the students have had some experience with this mini-task, introduce them to the line following challenge.

*Note: Although an efficient line following program can be written with a single light sensor, the programming can be rather tricky. It is suggested that each group uses 2 light sensors that can be used to indicate which side of the robot is or is not on the line.

Depending on the skill level of the students, you can either give them a generalized flowchart for the line following algorithm or have the students come up with one or several as a class. Keep in mind that there are many flowchart algorithms that can successfully complete this task.

Again, you can come up with a simple scoring system that will give points based on a time limit, fastest time and penalties for the robot leaving the track area/line. This score can be used to give extra credit to the top-placing team or teams.

Evaluation:
Have students turn in a complete description of how their program works, any problems encountered, and the solutions to the problems. In addition, have the students turn in a copy of their programming code and a flowchart showing their programming algorithm.

This is a difficult task, so it is suggested that students are evaluated on their understanding of how the light sensor can be used to detect contrast in surface color or light intensity instead of how successful they are at the task. If students are even able to program a robot to move based on the surface it is over, this is a very good indication of understanding.  

Extensions:
For extra credit, encourage students to develop a program for a robot to follow a line using only a single light sensor.

Resources: 	
www.legoeducation.com
http://mindstorms.lego.com/eng/community/resources/default.asp
http://en.wikipedia.org/wiki/Flowcharthttp://bricxcc.sourceforge.net/task_3_files/line_follow.gifhttp://www.legoeducation.comhttp://mindstorms.lego.com/eng/community/resources/default.asphttp://en.wikipedia.org/wiki/Flowchartshapeimage_2_link_0shapeimage_2_link_1shapeimage_2_link_2shapeimage_2_link_3shapeimage_2_link_4