banner I have been a Lego League coach since 2007. This year, I wanted to document the season to give rookie coaches a resource to help them through to competition. The process can be intense, but it can also be a lot of fun for you and your team.

I hope to cover enough through my posts, but if I leave anything out, please feel free to leave a comment, or contact me.

Following a Line

Author: fllCoach | Files under Programming

On most FLL competition mats, there will be thick black lines placed strategically around the board. Most of these lines are put there to help you complete a mission. A few are there to fool your robot. Either way, you’ll probably want to do some line following in order to complete a mission or two. It’s a good challenge for your kids and it will only help you in the technical judging.

There are almost as many algorithms to following a line as there are ways to draw a line. You can use one sensor, two sensors next to each other, or one sensor in front and one in back. Even with only those three sensor configurations, each has a multitude of methods in which to use them.

What I’m about to describe is the simplest and most basic of line following routines and good for rookie teams. It uses one light sensor.

The first thing you need to know is that when you follow a line, you’re not following the middle of the line, but the edge of it. If you try to follow the middle of the line, if the robot’s light sensor encounters white, you won’t know which way it should turn. By following either the left or right edge, you’ll always know what the robot should do.

If you want the robot to follow the right edge of the line, if the robot sees white, it should turn left. If it sees black, it should turn right. The reverse is true if the robot is following the left edge. I’ve found that both come in handy and create myBlocks for each that can be used for appropriate missions.

I was going to jump right into what the program would look like, but as I write this, I thought it might be a good exercise for you to try to figure it out. Besides, this post could get too long and you might fall asleep before you get to the end of it. I’ll give you some hints, though.

Remember that you are doing something based on what the light sensor sees. What construct do you use to accomplish that? And the light sensor decision is going to be done multiple times. There is a construct for that as well. Don’t put an end condition yet. That can be complicated and be dealt with later. For now, just let it go forever and stop the program when you reach the end of a line.

The tricky part is what to do in each branch of what the light sensor sees. You obviously want to use motors. But read my Go Until… post for hints on how to make the robot go smoothly instead of in spurts. Remember that the robot will make the motors move the same way unless you change it. So if you make a motor go, it won’t stop until you tell it to.

That should be enough information to help you write your program. I’ll post the solution in a day or two.

11 responses. Wanna say something?

  1. Dean Hystad
    Nov 2, 2010 at 17:22:23

    The Robot Educator (RE) in education versions of the NXT software has a line follower example. The algorithm used performs poorly and is a bad introduction to feedback control. I know a lot of teams that try this rudimentary line follower, see how poorly it performs, and decide from that the light sensor is no good.

    The problem with the RE algorithm is that it has no finesse. The action the robot makes for a small following error is exactly the same as for a large following error. This would be like slamming the handle bars all the way left and right as you ride your bike down the middle of the bike path. Theoretically it can work, but you aren’t going to enjoy the ride.

    What works better, is if the robot’s action is proportional to the error. If the robot is just a little off the edge (line following is usually edge following as mentioned in the “Following a Line” article above), the robot should make a small correction. If the robt is way off the edge, the correction should be bigger. Just like the way you make little steering corrections when your bike is close to the middle of the path, and bigger steering corrections when your are just about to drive off into the grass.

    For some bizarre reason many people find this thinking too advanced for young and rookie teams to understand. Even though it is easier to write (fewer blocks), works much better (very smooth and fast following), and demonstrates that sensors work very well and are a powerful tool.

    So when you are thinking about how your robot can follow a line, do a quick search on the web. Here’s a nice article to start with:

  2. fllCoach
    Nov 3, 2010 at 08:59:54

    Just because a program has fewer blocks doesn’t mean it is easier to understand. The concept behind proportional line following is easy for us adults to grasp, but not 4th and 5th graders. Many kids that age barely remember that 1/5 is bigger than 1/6, let alone what “proportional” means.

    Yes, the line following algorithm outlined is rudimentary, but it works well enough. And it is all you can expect a rookie team, or rookie coach, to understand. Before the kids can understand the algorithm and program it, the coach has to understand it enough to teach it to them. Most rookie coaches didn’t have the slightest idea how to program a robot before they took on the challenge of trying to understand programming enough to teach 9 and 10 year olds.

    These kids are overwhelmed as it is having to do a research project, build a robot, and then program it. In my view, the simpler the program in the first year the better because they can at least explain it to the judges. The kids are supposed to be programming the robot themselves and I doubt any judge would believe a rookie team came up with a proportional line following program on their own. At least with the basic algorithm described above, kids can understand “see white, turn left, see black, turn right” and conceivably come up with the program to execute it.

    A proportional line follower is definitely much smoother and more accurate, but rookie teams need a foundation they can build on for future years. Algebra is also much easier and more accurate than brute force mathematics, but you can’t do algebra until you know addition, subtraction, multiplication, and division.

  3. Dean Hystad
    Nov 3, 2010 at 11:32:20

    How is “If you have twice as much error you turn twice as much” an advanced concept? Kids understand what proporional means even if they don’t know the word. Proportionality is built into our genes.

    One of your earlier topics was “Programming a Parent”. Have your kids program a parent to do line following. When the parent is making violent left and right turns the kids will be screaming “No, turn just a little” or “Turn more, turn more!” between bouts of hysterical laughter. After that tell me again that proportional control is too advanced for kids to understand.

    The only advanced part of proportional control is also it’s most important lesson. And it is a lesson that is central to FLL. That is that you can use fairly simple mathematics to model real world behavior. Math is useful. Math is power.

    Studies show that kids (especially girls) start losing interest in math and science around 4th and 5th grade. Math curriculum in school is doing a poor job showing the power of math. Kids don’t see it as useful, so they don’t think it is important. Math in school is often boring. You need to show kids that math is neither unimportant or boring. Math is fun.

    You don’t believe me about fun? Last fall I helped teach robotics to 4th graders. We built robots that used the ultrasonic sensor to always stay 2′ away from you. You approach and the robot retreats. You back away and the robot advances. Very easy, and very neat.

    We started with an IF-THEN-ELSE algorithm. It worked Ok, but was either jittery or too slow depending on the power setting used to move the robot. The kids not only understood the concept of proportionality, but came up with the suggestion of it on their own. “If the robot is falling behind it should go faster” is a pretty good description of proportional control.

    So we made a simple proportional controler and started tuning it. Tuning is fun. Setting the correction gain really high and making the robot go crazy is really fun. Interesting thing is. the class very quickly got a feel for how changes in the controller gain would affect the robot. Time for the entire lesson was two hours.

    If you are nervous about “the kids do the work”, introduce proportional control using a method similar to what I used with the class. Here is a way to control your robot. No, you don’t need to make a people follower for FLL, but can you think of another use for this? If they don’t make the connection and try it for line following, fine. They still learned something and they might use it later.

  4. fllCoach
    Nov 3, 2010 at 18:27:27

    If rookie teams and rookie coaches want to take on such an algorithm, I’m certainly not going to discourage it. More power to them. It definitely is smoother and more accurate and a great challenge. All I’m trying to do is give rookie teams at least a rudimentary line following program that they can easily understand and program.

    When I started with FLL a few years ago, I had no idea how to program the robot to follow a line. I would have loved to have a basic line following program explained to me. I just want to give rookie teams something they can work with. It definitely is not a be all to end all and should be a foundation for discussion and improvement.

  5. Pebblekeper - Angie
    Nov 5, 2010 at 20:51:23

    We tried this tonight – at first a basic left or right line – and it went in a circle. I took the team the greater part of a half hour to figure out that they had to great thans in their sequence. The younger kids (we have few 8 year olds) glossed over at Percent, Greater Than, and Reflective Light. The 12 and 13 year olds saw the challenge. We moved on to putting in the switch, we have seen on this site and others, and they got excited. However, for the most part, the robot just jiggles back and forth, it does not go forward.
    One thing that Mr. Hystad might take into consideration, is that no only are we dealing with 8-13 year old boys and girls, but that we live in a town where this is the first year Lego League has ever occurred. We do not have other teams around, we do not even have the medical personnel in town to take field trips for our programs, and we do not have the books we need in our library. We don’t have time or day camps. We have a hard time convincing parents to let their kids attend for more than 45 minutes one time a week. 🙂 Keeping it fun – is key. Simple. They do not have luxury of time to keep thinking it through.

    If you do have a tip on why the robot did not consistently move forward, I’d love to know. 🙂

  6. Pebblekeper - Angie
    Nov 6, 2010 at 09:46:46

    Sorry for the typos above! Coffee on the Keyboard makes for sticky keys. 🙂 Here is our meeting for yesterday!

  7. Clarence Perdue
    Dec 21, 2011 at 10:32:20

    We are having some issue with Light Sensor. I understand about how high it need to be off of the mat and being in the shadow. But, we are still having a hard time with making this work. I saw a team create some kind of shield that they place the sensor into. I have had the team look at this but we can not how they build it and kept it on the sensor and attach to the robot. Can you give me some insight on how they build this robot light sensor shielding. Here is the team that I saw do this last year. The NXTeam has a video on youtube and we can not fiqure it out.

  8. fllCoach
    Dec 23, 2011 at 07:38:20

    This probably has less to do with the shadows and more to do with the calibration of the light sensor. Download the calibration 3 program from the line follower at NXT Programs (bottom of the page) and see if that helps.

3 Trackback(s)

  1. Nov 4, 2010: Following a Line – The Program | Lego League Coaching
  2. Nov 6, 2010: Am I Cheating my Boys? « Petra School
  3. Nov 19, 2010: Letting Them Learn – | Taco Force 2010

Post a Comment