In this video tutorial we demonstrate the use of the motion sensor and how it could be use to turn precisely to 90 degrees. We demonstrate some of the caveats of the sensor and how sometimes it does not work as expected. Like you set the robot to turn until the sensors detects 90 degrees and at the end the robot is not at exactly 90 degrees.
- 15 May 2022
- LEGO Education SPIKE Prime
- Scratch, Motion Sensor, LEGO Education SPIKE App Word Blocks, Sensors, Programming, Gyro Sensor
The motion sensor detects three angles. One of the angles is called "yaw" and it detects the horizontal rotation of the sensor. We use the yaw angle in this tutorial. To turn exactly to 90 degrees you should be prepared to wait for the robot to wait to turn to about 85-86-87 degrees and then the inertia will kick in.
How to use this tutorial?
Download the program to the robot and check if the robot turns to 90 degrees. It probably wont. Then edit the program and configure the value in the if statements to a value that will make your robot turn to 90 degrees. Remember this value. It will be useful in the future. Experiment with different speeds of the robot.
In this video tutorial will use the LEGO Education SPIKE Prime robot and we will try to do a basic turn with the motion sensor that will turn the robot to 90 degrees. This makes it easier for us to know where we are on the competition field and how we can position the robot correctly. Basic turn with the motion sensor. Let's see how it works. Here it is. Motion sensor turn 90 degrees. It's not exactly 90 degrees. And I'll explain why in the program that will enter into the details next. But the robot turns and its behavior is quite consistent. It turns to about 95, 96 degrees. We start again and it turns and it uses the motion sensor to turn and try to turn to about 90 degrees. Let's see it from another angle.
Now we enter into the program.
I have my program on the left and you can see the program we've developed. You can see all the different blocks on the right. We see the video of the robot, how the robot behaves. And I'll do a step by step move through the different blocks. First when the program starts and it's somewhere around here we are at when program starts, set movement Motors A and B. On the left, we have motor A. On the right, we have motor B. Both of them will move with the speed of 30%. Then we set the Yaw angle of the motion sensor to zero. This is the angle because the motion sensor detacts three angles and this is the angle that we detect when the robot turns horizontally. Then we start moving. We start moving and we start moving to one of the directions either to the left or to the right. In our case, we will move to the right. So this is how we've configured the Motors. We will move to the right and when we are moving to the right, we wait. We have a block that waits. We move, we move. And in this wait we start moving from here and we move and we wait until the sensor detects an angle of 87 degrees or slightly above 87 degrees. So we have both checks. Now you can use both of the checks or you can use just one of the checks more than 87 degrees. The reason why we check both is for us to be able to describe in the video that the way the sensor works, the motion sensor works is that it might detect 85, 86 and then 89 degrees. So if you just use this check angle equals to 87, this might never occur because the sensor detects like 80,83,85,89, it is not exactly equal to 87 at any point in time. That's why we use larger than 87. So when it is larger than 87, then stop. And an interesting thing here about the robot is that there is some inertia going on. So you see, we start from an angle of zero and we move and as we move 90 degrees is somewhere here, but the robot does not stop there. The robot continues to move forward and as it moves forward, it moves forward because of the inertia, but it's consistent. It moves forward consistently. Which is nice. If we configure this angle here to be equal to 82, probably it will stop exactly at 90. Now there are other ways to make it stop exactly at 90 and we'll enter into more details in some of the next videos. For this tutorial, it's just basic turn with the motion sensor and how the robot turns. Hope you like it, move on to the next lesson after you try to download the program, put it on the robot, download it on the robot and try to experiment with this program and see how it works.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.