Looking at the field we must first think of a strategy of solving this line following problem. There are rules that the robot must follow and these rules should be programmed in the robot.

**#205**- 13 Jan 2016
- 7:45

The strategy depends largely on the number of the sensors that we have and the features of the line being followed. In our case the line has gaps. Not every line you are going to follow has gaps, but this one has them. Then, it has left and right turns.

The robot must make a number of decisions while following the line. This could be 1, 2, 3...N decisions. Our goal is to group these decisions into as few as possible. From there we would find how many states our State Machine programming pattern should have.

### Full course available at

### English

In order to build an algorithm for following this line we must first decide on our strategy and what are the different conditions and the different decisions that the robot must take, while following the line. We know that this is the start. Right here we have the start and the robot move from the start and must reach the end. Now, first, the robot moves in this direction, we must decide to go left, so that's the first decision that we must take. Then we have a gap and for this gap we must decide.

Then we must turn right and that's the third decision. Then again we have a gap, 4th decsion, then there's a section here that has the lines crossed and we must take another decision - 5. Then again we see a gap - 6. Then we just follow a line and we have a 7th decision that is move left. Then we have a gap - 8. Then we must move left - 9, then we move from this direction and then we must move left, so it's the 10th decision. Then we must move right - 11. Then again right - 12. We see a gap - 13. We see another gap - 14. We move right - 15 and here on this section we must decide to move left - 16. So it's like 16 different decisions that we must take while following this line. Now let's try to group these decisions, so that we know are there really 16 different decisions or we have 4, 5 different decisions in different times we must take.

I'll take another sheet of paper. Using this field, let's try to draw the different decisions that we must take. First, again if the robot is coming from this direction we must turn left. So the robot is moving in this direction and we must turn left. That's one of the decisions that we take while following the line. Another decision is, we move and we find a gap. So this is another decision that we must take. Third decision is to move right. So we move and then we turn right.

We also have an intersection which is like this but the only intersection on the field is we actually move and we turn right. So it's again similar to this previous turning. Another interesting section is we move and have align like this. So the robot moves from this direction and then we must turn left. And we also have an interesting intersection where we move

and then we must turn right. Then we have again some gaps and we also have an interesting problem for moving. We come from this side of the section and then we must decide to move left. And these are 7 different states, 7 different decisions that we must take while following the line. Again we have a default decision where we are just following a line. What I would like to do in the next couple of videos is to start from the most simple case. Just follow a line, then follow a line and turn left, then follow a line and see a gap, then follow a line and turn right and move through all the different states and while doing it we'll build a robot that follows the line and that can take a correct decision in each step. For this we'll use very interesting technique while programming and for this technique we'll seperate the logic of our robot on

states and behaviour and if you have EV3 software and for it we can use different variables but the basic idea that I'll use in this program is the following. First, I'll have part of the program dedicated to finding the state, the state in which our robot should be. State of our robot. And the state one of these 7 conditions. Turning left, finding gap, following line, turning right. After we find the sate we check the state and we command the motors. So we program the motors.

And we'll seperate our program in these 2 large parts. First finding the state and then depending on the state we control the motors. If we are in 1 state we control the motors in one way and if we are in another state we control the motors in another way. The only way that we communicate between these states should be actually one variable that's called state. Let's start with very, very simple program to just follow a line. For following a line we'll use our EV3 competition robot and it has a number of sensors, i'll describe them in a next video. First, for following a line we'll use the proportional line following algorithm, which is described in one of the previous videos, so search them in the bar above or check out the links below the video so you get the idea how do you follow a line with one of the sensors and it's a proportional line following. It works like this.

In the next video we'll change the proportional line folllowing program so that we can find a gap and move trhough it.

## Lessons with this tutorial

This tutorial is used in the following lessons