We extract the Proportional Line Following algorithm into a new block with parameters. This allows us to experiment with the Threshold, Constant Speed and Relaxation Coefficient. You can now easily use the block in you other programs without having to implement it.
- 27 Jan 2016
- LEGO MINDSTORMS, LEGO MINDSTORMS EV3
- FIRST LEGO League, EV3-G, EV3, Light and Color Sensor, FLL, Programming
A MyBlock in EV3-G software can have input parameters and can return a value. The PLF depends on three params. We create a block which allows us to change the value of these three params without changing the code for PLF and to use this block in different circumstances. The params do effect the speed of following the line and how smooth is the robot following it.
Find the complete course at:
Courses with this episode
The episode is used in the following courses where you can find additional tasks for it to use in class
Import the block in your programs. Experiment with values for Relaxation Coefficient in the range of 0.1 to 10. What are there results? Record a video or take a picture and share it with us in the comments section below.
Tasks description, submission and evaluation are available to subscribed users.
Subscribe now to access the full capacity and get feedback.
While working on this crossed, gapped line following algorithm, we understood that some of the parts of the proportional line following were not described entirely. So today we are going to describe the different states of the proportional line following and extract them in a new block. There are different ways to follow the line. First, you can have the following state,
where we are searching for the line very aggressively. And if there is no line, we rotate very fast and search for this line. Or we can follow the line in a very smooth way like this.
Both methods have advantages and disadvantages and in this video we'll discuss how we create such a block to explore and experiment with this behaviors.
This here is the initial program that we start with. First, we change the value of the sensor in the current construction it is sensor 2, then the left motor for our construction is C and the right motor is B. Then we look at the equations for proportional line following, we have these value 40 here. I would like to extract this into new variable 40 is the value of the threshold and it's the middle between white and black. We attach it to port B to input B for the math blocks and then we use it in the formula.
Let's run the program and make sure that we haven't done anything that changes the behavior of the proportional line following.
The robot still follows a line so we haven't changed anything. Let's continue with the block. The next step is to extract common behavior into a block and first I would like to move "motor right", here, after the calculation.
And then move "motor left" at the end after the calculation. Now we extract these blocks here. So the input will be the value of the sensor, the threshold value, the coefficient and the constant speed. And we extract the other blocks into a new proportional line following block.
Tools -> My Block Builder, we give it an icon, call it proportional line following and we have the parameters. First is the sensor value, the second one is the threshold, the third one is the coefficient and the fourth one is the constant speed.
And that's how our proportional line following block, looks like. Let's again download and see if we have changed the program in any way.
The robot follows the line, find it again, try to follow. We can start it from here. So we haven't changed the behavior. We refactored the program, but we haven't changed the behavior of the robot. Now let's experiment with different values for our parameters. We can now delete these constants and I'll just write the numbers directly in the block. This one will be 15 as a constant speed, this one will be 0.4, this one is 40 and we're reading constantly from the sensor, so we can't predict this value. Now I'll just minimize this whole loop that looks quite large.
And now let's change for example the coefficient, for how fast are we searching for the line, how aggressive are we? If we change this to 1, we'll see the following behavior.
As you see the robot is much more aggressive in searching the line and trying to follow it,
because the coefficient is larger and we move much more aggressively. So we can experiment now with this block, with the different values, see how they affect the behavior of the robot, when we are following the line. You can download the block below in the materials section and you can use it in your programs, and you can configure it especially for your robot and the construction you're using.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons