The reason why you would want to watch this tutorial is because it demonstrates one of the most reliable ways to know where you are on the field and to accomplish missions successfully and this is aligning to a line. In the tutorial you will also see how a parallel program is developed and who parallel programs could be used in a meaningful way.
- 20 Jul 2022
- LEGO Education SPIKE Prime
- Scratch, Light and Color Sensor, LEGO Education SPIKE App Word Blocks, Programming, Align
The process of aligning involves moving with both motors until any of them reaches a line and then only the other motor continues. Simple, right? Check out the tutorial to see the implementation and the program.
How to use this tutorial?
Download and experiment with the program. Start the robot and align to different lines. All kinds of lines. See if you are happy with the precision of the robot.
In this video tutorial we will look at one of the most important programs for FIRST LEGO League competitions and this is how to align to a line with two LEGO Education Spike Prime sensors.
Why is this important? It's important because it's one of the most reliable way to know where we are on the field and how the robot is positioned. And we can use the lines, we can follow the lines, but at a certain point we can even align to these lines. And how do we align? We move from the left and from the right, and when one of the sensors see the line, we move with the other model. Let's go into the programming. Here is the program for our robot. On the right you can see the recording of the robot. And these are the few simple blocks. That would allow us to align to the line with our LEGO Education Spike Prime robot. And again, let's start the program again and let's see how the program behaves. We move with both motors until the left sensor sees a black line, and because it sees a black line, we start moving with the right sensor, until the right sensor sees a black line. That is a simple, straightforward program where we have a very simple algorithm for aligning to the line. And in this way we know precisely how are we located on the field and how to approach the mission model and how to accomplish the mission model. Because once we know where we are, we can then accomplish it. Same thing from the other side. We start, we move forward, we see a black line and we stop. That's it. How does the robot behave and how is the program implemented? We have the following blocks. First, we have a block when the program starts, and when the program starts, we set the speed of motor A to 20%. Let me return back to video. Motor A is the left motor of our robot, motor A is the left motor. And what we do is we say move forward with motor A until sensor E, which is the left sensor, detects a black line and then stop the motor. That's it. Move forward until we see a black line. And you can see how right here it stops. In parallel, which is something interesting for this program. In parallel, we run the following program: Another set of blocks that again start when the program starts. So when we press the button, this other set of blocks will also start. And how would they behave? We start the program, we move with motor B, which is the right motor, and we wait until sensor F, which is the right sensor, detects a black color and then we stop the motor. So we start. And because both programs run in parallel, here is the moment where motor A stops, and only motor B continues until it detects a black line and then it stops. Now there could be an argument that now it is good to return the left side of the robot a little back. And we leave this to you as a decision. And we can also implement this in some of the next programs for aligning. But that's the simplest way to align. We have two sets of blocks in our Scratch program and they are executed in parallel. One is responsible for motor A, the other is responsible for motor B. That's it. That's the importance. And that's how the robot behaves. And it's important to know this, because we found out that during the years, that's probably the most reliable way to know where you are on the field. To align to the different lines that are available on the field. Download the program, experiment with your robot, try to align. And in some of the next tutorials we'll look at, how do we align but moving backward. See you in the next tutorial.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons