EV3 basics course. Color Sensor. Stop on third line without Wait block (part 3)
Use the color sensor to count the lines and stop on the third line. We do not use the wait block for this.
- #149
- 24 Oct 2015
Use the color sensor to count the lines and stop on the third line. We do not use the wait block for this.
The program from part 3 should be refactored and improved to make it easier to understand and support. We extract most of the repeatable behaviours in a loop and this reduces the size of the program three times in terms of the number of blocks used.
As an extension to the previous video we talk about the Hi Technic Color Sensor again.
This is one of the last tutorials in the LEGO Education SPIKE Prime programming for Competitions course and it demonstrates what we've all been waiting for - how to reach a mission model from base in a reliable and consistent way when the mission model is on the other end of the field. Naturally what we use are all the different concepts that we've learned in the course and the tutorial is more advanced than the other so if anything is not clear take a look also at the different tutorials an concepts in the course.
Using everything that we've learned about LEGO Education SPIKE Prime competition programming we arrive at the final boss mission - how do we consistently reach a mission model at the other end of the field. Consistently. Every time. We use line following, motion sensor, counting of lines and border alignment. All the different concepts that we've looked at separately are now implemented together.
We've detected the gap. It's time to move over it. This is difficult because we have to detect where the line is after the 0.1 meters gap on the line following field.
"Sometimes it works, sometimes it does not work" - this is the most common case in FIRST LEGO League competitions. In this tutorial, we demonstrate and discuss such a case where the first part of accomplishing the mission always works but the second part has about 60-70% success rate. The robot is not very consistent. Let's take a moment to see it and explain why so that we can resolve the problem in the next lesson.
Last part of the series. The final touch of the program makes sure that it works and is following the line with the LEGO Mindstorms EV3 Color Sensor in a smooth and fast way.
We follow a line. We start from the Smooth Proportional Line Following program and modify it a little for this program. We follow the line with the middle sensor attached on port 2.
Next important state is Turn Right with our robot. This happens when we detect a line on the right.
This robot has a color sensor and this sensor is used for following lines. Additional Mindstorms EV3 sensors could be place on the robot, like a Gyro sensor or a second Color sensor.
Next state in our state machine programming pattern is the "Turn Left" state and the corresponding behaviour.
In this video tutorial, we use the Unload Cargo Ship mission from FIRST LEGO League 2021 Cargo Connect robotics competition to demonstrate how we program the robot to keep a straight line while moving. Do we need that for this mission? Probably not, but we do it either way to demonstrate the solution in a fairly simple mission. The program uses the motion sensor to auto-correct the errors the robot is making while moving.
Let's implement a more advanced program for this robot to learn how to use with motors in opposite directions - and this is to implement the Proportional Line Following algorithm.
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.