Gapped & Crossed Line Following. Part 5. Detect Gap Pro Preview

It's inevitable. While following this gapped line we would reach a gap. The robot must somehow understand that there is a gap and must make a decision on what to do. For detecting the gap we use the Rotation Sensor. Not the most popular, but very convenient in many cases. Check out the video.

  • #208
  • 10 Feb 2016
  • 5:35

States

In the State Machine we add one more state. That is Gap Detected. After a gap is detected we must find a way to move to the next section of the line, but that would be the subject of the next video.

Prerequisites

Again make sure that you have taken the course on Proportional Line Following with LEGO Mindstorms EV3 to make sure you understand how line following is done. 

Rotation sensors

In this particular state we make use of the rotation sensor and with this sensor we detect if there is a gap. Pretty interesting. Check out the video. 

English

Previously we started using the state and calculating the state for our line following program, then using the state to control the motors. But we made some changes and the proportional line following is not working. Let's explore further how we used the states.

This here is now the most complex part of our program. If we get this right and if you can understand it, you can understand all the other parts of the program, because they will be quite straight forward. We are doing a calculation on our sensors and based on the state of sensor 2 we set a state, state 0 means following a line. Then we check if the state is 0, then we follow a line with the proportional line following. How do we set the state, we set the state to 0 only if we're over a black line, but it is true that we can be over the table and we must also be in state 0.

So if we are over black we set state to 0, if we are over white we set state to 0. The difference is that now we must start a timer. If we are over white for more than x amount of seconds, then we have lost our line. let's first run this program to see that we are following the line.

Yes, we are successfully following a line. The program is working as it was initially. Now we need a timer that detects when have we lost the line. In our program, when we are over the black line with the second sensor we are in state 0. This means that we are following a line. Now if we are over white, we are again in state 0, but this time we must check a timer. In the EV3 software there are a number of timers and I'll use a timer with id = 1 and I'll compare this timer to let's say, it must be greater than or equal to 1 sec. In this way I'll compare if we are searching for black line more than 1 sec. This timer will give me, if we are searching for the line for more than 1 sec. And if we are searching for the line for more than 1 sec then we must enter into a new state. This new state is we have found a gap.

We compare logic and we enter into state 1, let's say that state 1 is the state where we have found a gap. If we are over black we must reset our timer. In this way each time we are over black we reset the timer and when we are over white we start the timer and we detect what's the current value of the timer. We just reset this. Let's look at the whole program. This left part of the program is calculating state, the right part of the program is actually doing something with this state. Currently we are doing something only if we are in state 0, which is follow a line. Now we would like to do something if we are in state 1.

And in state 1 we must stop the motors.

And we wait for let's say 5 sec, just to show that the robot stops.

And this will be our program for detecting the gap. If we are in state 0 we are following a line, if we are in state 1 we detect a gap, we stop both motors and wait for 5 sec.

Download and run the program.

The robot follows the line and it detect a gap and it stops. Now we know that there's a gap. Let's run the program again. Follow and we detect a gap. In the next video we'll program the robot, so that we move over the gap and continue following the line after the gap.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for The power of State Machines. Gapped and Crossed Line Following with LEGO Mindstorms EV3
  • 12
  • 92:11
  • 0
Image for Detect Gap
  • 1
  • 0
  • 0
  • 3d_rotation 0