On the topic of following lines with a robot there is a way to make the robot follow the line a little more precisely. This method is called "Multi-states" program. Or at least we call it like this. In this tutorial you will see how we program 5 state for the robot line following program. This could be particularly important with FIRST LEGO League competitions where we must build consistent and reliable robots.
- #1935
- 29 Jun 2022
- 6:50
- LEGO Education SPIKE Prime
- Align, Scratch, LEGO Education SPIKE App Word Blocks 2, Programming, Light and Color Sensor, Sensors
Why 5 states
Theoretically and practically you can get to a rather smooth line following with configuring the values for the programs and understanding how the values for the reflection of the light sensor and the values for turns change the behavior of the robot. 5 states is enough for this algorithm.
How to use this tutorial?
Download the program and experiment with it. Configure the different values and see what the behavior of the robot is. Try to get the robot to follow the line without missing it and to keep the robot on the edge of the line moving forward without the 'wiggle wiggle' part.
English
In this tutorial we again follow a line, but this time with a multi-state program. And the difference is that this time we are using the reflection of the light sensor rather than the color black or white. We use the reflection, which is sometimes more powerful. Let's see how it works. We start from base and we couldn't catch the line initially. Second time, let's start from the base. And what we see here is how the robot moves slightly to the left and then to the right, the left and to the right. And this robot uses the reflection of the light sensor. We'll get into more details about how to use the reflection and why the program is called Multi-state. The benefit of this program is that you can theoretically and sometimes rather practically follow a line very fast if you manage to get the right values for the reflection. Let's see the program. Now we see the program on the left along with the recording of the robot on the right. And as most programs in our course, we set the movement motors A and B and the speed of the motors is 25%. You can experiment with different speed settings, but when following a line it is a good practice to follow the line rather slow and this allows us to detect the proper values with the light sensor. The next thing is this repeat until block. It's rather large and it has a lot of if statement statements in it. And we repeat this block for about 10 seconds. That's how you limit the duration of the program. And you can modify this, of course. 10 seconds timer. Repeat until the timer is 10 seconds. Done. Next thing in the repeat until we have a number of if statements. And let's take a close look at the first if statement. This one here. If reflection is less than 20%, this means that the sensor E is over black because the reflection is less than 20%. And I'll give you a minute. Think about this. It's the way the sensors work. If you are over black, the reflection is low value, something like below 20% probably. And if this is the case, we move to the right rather fast with a value of 100. Same time, if the reflection is between 20 and 40%, which means it is still black, but it's rather more like a white. Now there is no such thing as a "whitish" black. What this means is that we are probably closer to the edge because the sensor detects a little bit of white. So we are coming to the edge and if we are coming to the edge of the line, we don't stop, but we change the speed with which we rotate to the right and reset 95. Let's see how this works in the program.
We start and now we are over black. Then we go to the white. We are over black, then we go to the right, black, white and the beautiful thing about this program and why I like this program very much is this section here. If the reflection is between 40% and 60% and 40 and 60%, we are almost certain that we are on the edge. We are right there on the edge, which means that we move straight. And theoretically and practically I've seen it many times happen with many robots you can move straight without this wiggle wiggle to the left and to the right that we've seen in a lot of the programs for line following. Just because we are moving straight here and as long as we stay on the edge, we continue move straight. Now, there is a catch here that we should configure the values for our robot. 40, 60 might not be the right values, 45, 55 might be for our sensor and also this value here, like 100, 95. These are also things that we should configure. Additionally in the repeat until we have this section with two if statements that are the same logic, but for white it's basically the same. So one is for the black, one is for the white and in the middle we have the straight line that's just on the edge. And by configuring this value and experimenting with them, you can learn a lot about your robot. And what's the best way for this robot with this sensor, with this attachment to follow online. This is the idea of a multi-state. Now, can you have seven states? But of course can you have nine? Of course. It doesn't generally pay off. Five is where we think most of the benefits come. Five is a good set of good number of states that we can use. How do we turn on this left turn here? Here it is rather slow, but again it's a matter of configuration to get the values right for your robot. What you should do now, download this program to your robot, start the program, see the behavior, then experiment with some of the values and see can you get the robot to behave better. Experiment with the values for the reflection, experiment with the values for the turn and with the movement speed and how fast do you want the robot to turn. That's it. See you in the next tutorial.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons
LEGO Education SPIKE Prime Programming for competition with Word Blocks
Two concepts are important for robotics competitions - consistently navigate and position the robot exactly where we need it to be on the field, and builing attachments that would accomplish a mission once we have reached it. This course is focused on the first part. The second part is the whole FLLCasts platform, but start at FIRST LEGO League with LEGO Education SPIKE Prime. "Challenge" competition for 9-16 years old
The goal of this course is the help you learn to program LEGO Education SPIKE Prime robots to behave consistently and reliably during competitions. As a language we use LEGO Education SPIKE App Word Blocks which is based on Scratch. We look at a lot of concepts that could be used for FIRST LEGO League and World Robot Olympiad competitions - eg how to follow a line fast, slow, in a smooth way, with 5 states. Also how to align to lines, how to do double alignment, how to keep a straight line with motion sensor.
- 40
- 188:21
- 19
Color Sensor - Follow a line with a multiple states algorithm
On the topic of following lines with a robot there is a way to make the robot follow the line a little more precisely. This method is called "Multi-states" program. Or at least we call it like this. In this tutorial you will see how we program 5 state for the robot line following program. This could be particularly important with FIRST LEGO League competitions where we must build consistent and reliable robots.
- 2
- 0
- 1
- 3d_rotation 1