We keep the robot orientation straight while moving, but when we stop the robot could be in a different orientation. This applies for both using the Mindstorms Gyro Sensor when moving straight or the Mindstorms Color sensor when following a line. In this video tutorial, we will do a few examples of when an how this could happen.
- 10 Jan 2018
- LEGO MINDSTORMS, LEGO MINDSTORMS EV3
- Move straight, FIRST LEGO League, EV3-G, EV3, Gyro Sensor, Sensors, Physics, FLL, Programming
In this program, we return the robot to a straight orientation at the end of the program. If there is not enough time for the Mindstorms Gyro sensor the correct the orientation of the robot before the end of the program, then we should do it at the end.
There is one very interesting problem when moving forward and keeping in straight position. And this is that at the end while you are moving the robot will keep the straight position so if it makes a mistake, it will correct, if it makes a mistake, it will correct. So you're keeping a straight position. But at the end - right at the end of the program like a second before the end of the program or half a second before the end of the program if the robot makes a mistake, there is not enough time for the robot to correct for this mistake. And the robot will stop and it will be facing the wrong direction. So, let's discuss how we can fix this. Every time you are using a gyro sensor or a color sensor this might happen. And you are moving with the gyro sensor and you want to keep a straight position but right at the end the robot is like 1 or 2 degrees to the right and the program stops. And at this point there was just not enough time to correct this while the program was working. There is nothing wrong with the algorithm we just stop the program at this time. And now what we should do is at the end of the program we should have some special logic that will correct for this mistake. And basically we do the following thing. We detect the value of the gyro sensor and we see that the robot is on the right and we just move slightly with the right wheel forward or we move slightly with the left wheel backward. And how much should we move? Until the sensor detects a value of 0. Now, should we move with the right forward or with the left backward? This depends on our program, on our robot, on the competition, on the mission, on what we want to achieve but basically what we are almost always doing is moving forward with one of the wheels until the sensor detects a value of 0. So, let's implement this program in the EV3-G software. In the software what I'll first do is to remove this - or let's keep the sample previous program so we have the robot moving for 8 seconds. And this is our end condition - we want the robot to move for 8 seconds and while moving it corrects the orientation of the robot but after these 8 seconds are over the robot might be in a different position, in a different location. It might not be with 0. And what we should do is we should compare. And we compare. Now, there are a number of ways to implement this. So, I'll do it in a very simple way with just a switch. And we compare the value of the gyro sensor. Gyro sensor > Compare > Its angle and if the angle is less than 0 degrees what we are doing is we are moving with one of the motors let's say - I'll just take a large motor we are moving with motor B and we are just moving forward and if the gyro sensor detects something that's more than 0 degrees, we are moving with motor C and we are moving forward. But for how long? And this is the interesting thing. We should do this until the sensor detects a value of 0. So, we should put this in a loop
and we are doing this until some condition is met. And again we say a condition of gyro sensor equal to 0.
And when we reach this condition the robot will stop and we should tell the robot to stop its motors. And just take a tank block and we just stop both motors. Again, the robot is moving and the robot is trying to keep a straight orientation forward and it's moving for about 8 seconds and at the end it might be in a different position, it might be slightly to the left or to the right because it has made an error on the 7th second and there was not enough time to correct for this mistake, for this error. So, at the end of the program we check - if the gyro sensor detects an angle of 0. And if it is less than 0 we move with one of the motors, if it is more than 0, we move with the other motor. And the values here for the motors depend on your construction. And the other interesting thing is that here we should move very slowly like with the power of 15 and again this depends on your robot.
There was one more thing. We must stop the other motor right here. So, we must stop motor C and move with B and in this we must stop motor B and move with C. To make sure that we are moving with only one of the motors we must stop the other. It might be the case that the other is not moving but it might also be moving. So, we must stop these motors and move only with the other motor. And we do this for a condition - until we reach a value of the gyro sensor that's equal to 0 and then we exit the loop and we stop. Try it, run it on your robots and it's applicable both for the gyro sensor and for the color sensor.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.