This year’s field mat is very line heavy and compact. The color sensor is going to be crucial in navigating the field efficiently. So, let’s start with the basics of the Color Sensor.
Aligning to lines in FLL is important for the robot to be in the proper place to accomplish the mission. Look at the last years field and identify missions the specifically have lines place to help with navigation.
Last year’s mat has only three lines and two “T” intersections to use. So the lines were mostly to “approach” different mission, rather to “get to” the mission. The only “colors” used this year are black and white in previous years there has been lines of various colors and angles.
See in the 2012 challenge of Senior Solutions how many lines there was to follow and the different colors to detect. The green line was particularly important that year to accomplish several missions.
Now to the Color Sensor!
The first step is to have an EV3-color sensor mounted on the robot somewhere in the front. Later we will figure out the best placement for the sensor; center, or in front of the wheel. Some robots use two light sensors. Placement depends on the field and what you are trying to accomplish.
The sensor should be no more than a brick and a half off the ground. 8 to 12 mm. It is best to have the color sensor in a “cage” so that light from the room doesn’t mess with the values.
Video extra from Builderdude35, The Optimal Color Sensor Placement for EV3 Line Followers, on color sensor placement:
Let’s get to Programming
Place a color sensor block next to the start block. It in the yellow sensor tab for the color sensor.
Check the port number for your color sensor (upper right box that reads “3” currently). In this example it is on port 3. If it is the right one for your robot, click the upper right-hand box and change it.
Open up the configuration of the color sensor block. Click the measure tool on the bottom left corner of the color sensor block to open up the choices.
Click measure, then color.
In color sensing mode the sensor gives each color a number:
Use your port view on the brick or port view on the computer to test the color sensor reading. Use different lego bricks for the color.
The majority of the time, we are going to use the color sensor in the reflected light intensitymode. This is where the color sensor emits a light, red, and reads the amount of light that bounces back to its detector in the sensor. This is where blocking outside light, or ambient light is important for an accurate reading.
Configure the block to reflected light intensity, compare.
This now adds extra parameters to the block:
Now test the placement of the Light Sensor
Use Port View on the Brick or the Brick View box on the lower right with your robot connected on the computer. Test the values you get back on the light sensor with the sensor 3 or 4 bricks high, and then with it super close to the mat. Then place the color sensor in the best position for your robot for now…..
Light Sensor – Black and White Readings
Now that you’ve looked at the color sensor block some, now let’s look at the outputs using the port view or the view the port view on the computer. Go to the mat or use a large black line on a piece of white paper.
Place the light sensor over a black line, what does the sensor read? Hopefully, something near 0 to 10
Place the light sensor over a white line, what does it read? Hopefully, something high like 80 to 100.
If the sensor was “perfect” the amount of reflected light over a black line would be 0, and a white line would be 100. Black absorbs the light so that there is little to no light reflected back and white reflects all the light.
Video overview from Builderdude 35, How to Program the EV3 Color Sensor, on color sensor:
There is a way to “calibrate” the sensor so that given your room light, the sensor will read “0” for black and “100” for white. We will cover that towards the end of this tutorial.
Finding the Line
Notice on the mat that around each black line is a white line. So, to find the “black line”. You first need to get your robot near the line area. Then find the white around the black and then find the black of the line. See how each backline is outlined by white.
Pick a line on the mat to practice with.
Now, you are going to write a program to find white,
Step 1: Grab a loop block, in the orange program flow section (See below)
2: Place a move steer block inside the loop, configure it to “on” and power 20
3: Name the loop by clicking the 01 area and call it “FindWhite”
4: Configure the loop exit to color, reflected light intensity
5: Select 3, greater or equal to on the first parameter of the color block, then select a threshold for white, like 85.
6: Place a move steer block after the loop, and configure it to “off”
Now test the program. After it works, label the blocks…
If any issues with it finding “white” check your port of the light sensor, check the configuration of the loop exit block to greater or equal, make sure you place a “white” value, usually something around 85.
Step 1: A second loop is needed now to find the black line.
2: Copy the loop FindWhite, paste it right after the first one and name it “FindBlack”.
3: Change the loop exit parameter to “5” less than or equal too, and a low threshold, usually around 5 to 15.
4: Place a move steer block after the loop to “off”
Set the power setting of the move steer blocks to something low, like 20, in both loops.
Test the program
Once you have your program working, make it into a MyBlock call it “FindLine” Do do that:
Step 1: Select everything, except the start block, go to Tools, Myblock maker
2: Now, add parameters four parameters,Click the plus button, so there are 4 parameter set-ups.
Now give your MyBlock a name, “Find Line”. Then click on a picture that looks like a color Sensor.
Now select the first parameter set up, the “a”. Give that parameter a name , click “parameter set-up” tab, next to the My Block Icons. Then select an icon for each parameter
Set up each of these parameters White threshold, Black threshold, Power, and Port number.
Port number will become important if you have two light sensors on the robot
Set the power setting to something low, like 20 for a default
The light and dark thresholds allow the block to adapt to different conditions
To wire the port numbers, you need to click the port box and place it to wired
It should look something like this if you have it with wiggle correction, make sure to place your comments! Don’t worry about wiggle if you haven’t done the Gyro tutorial yet….Just focus on the move blocks and wiring of the parameters.