Gapped & Crossed Line Following. Part 12. Escape the "Lost" state Pro Preview

The final video from the course. The robot escapes the state where it is lost. This happens if it can not continue in any direction.

  • #215
  • 08 Feb 2016
  • 12:42

English

In the last video of this course we'll escape this this lost state that we entered previously and we'll continue following the line.

What we'll do in the program is to remove these block for waiting. I'll just delete this and if we have lost the line, I'll first return with motor B for -90 degrees

and we then do a rotation with motor B for 2 rotations and it will turn left and again left. That way we are facing 180 degrees and after 180 degrees we move forward with both motors for about 1 rotation and then we turn with motor B until we detect a line with the second sensor. We wait for a line with the color sensor.

Now we catch the line and as we do so we start a new line following.

This line following will work like this. We detect with the color sensor on port 2 the reflected light and we set this light to the variable, you might remember it from the first episode, that's called S2 and that's the value of sensor 2, we set this to the value of sensor 2 and we are following the line and we are doing a proportional line following with this value.

We don't need the S2 here. So we are following the line and we are following it for let's say 2 sec and then at the end we set the state of the robot to be -1. Basically we say, we are done with finding the line again, return to the loop for checking the state and determining what's the state that we should enter next. This program should find the line again. We turn 180 degrees and return back to the line, follow it for 2 seconds and then we continue on the left.

Robot follows the line, detects a gap,

And now we are lost.

There is a problem in our program and this problem is our next challenge. Let's see what it is. The problem is in how we use the different states. As an overview of the program, we have first part of the program, that's calculating the new state, let's extract this whole functionality into a new block and we'll call it CalcState, because we use the different sensors and we calculate the new state of the robot. This will be with the following icon and it won't have any params.

So we calculate the new state of our robot and after we do so, we use a Switch and we enter in one of the states. We have a state 0 and it is just following a line, -1 which is our default state, does nothing, 1 - we are passing a gap, in state 2 we are turning right, in state 3 we are turning left and in state 4 we are in the lost state. I'll extract this whole functionality here into a new block called Find the line again or just EscapeLost.

You can find the whole program below the video and it's really not that difficult once you extract all the blocks into their own new blocks.

Our program now looks much more simpler.

The whole program that we have is just calculate the new state and depending on the new state execute a command and these commands might be escape or pass a gap but what we haven't done is when we are passing through a gap, right here in state 1,

and we set the new state to be state 4 but right after that in the loop we again calculate the new state. We set here state 4, but we calculate the new state. We lose the ability to be in state 4 because each time we calculate the new state. The calculation of the new state should be done only if we are in state -1. We need a new Switch and we'll check if the state is -1

And if the state is -1 only then,

we calculate the new state. How do we calculate the new state. We calculate it with the block CalcState and set the new state to the state variable.

Then we use the state variable

to enter in one of the states. This will be one of the final versions of our program. If we don't have a state, we calculate one. We check what is the state and we enter into one of those states after we enter into one state we can reset it to -1 and we can also have the situation where we don't reset the state and we enter into state 4, this is the pass gap.

If we pass the gap we can say that the state is 4 and then we stay in state 4 until we calculate something different and this will be for escaping in a way and finding the line again. Let's check the program. We do a final run with our robot.

That's it for the course on following this crossed, gapped line. Let's see the complete run on the field.

As an end of this course we have a robot that can follow lines and these line could be gapped or crossed. They could have different obstacles and it's a quite an interesting program and it works for most of the cases. In the next few videos, although we have a working program, I'll stop on some of the challenges of improving this program so it can work in many different conditions. I've tested and this program doesn't work for a few of the conditions and for a few of the fields and if you have a different surface that has different traction with the tires then this program might not work as expected. Let's go into the next course of improving this program.

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 Escape the "Lost" state
  • 1
  • 0
  • 0
  • 3d_rotation 0