В момента ресурсът е наличен само на английски

Line follow with multiple states algorithm for Color Sensor from LEGO Education SPIKE Prime Pro Preview

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

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.

Курсове и занятия включващи този Урок

Този Урок е използван в следните курсове и занятия.

Image for LEGO Education SPIKE Prime Programming for competition with Word Blocks
  • 40
  • 188:21
  • 19
Image for Color Sensor - Follow a line with a multiple states algorithm
  • 2
  • 0
  • 1
  • 3d_rotation 1