In FLL robot games, measuring the distance traveled by the robot is very important. For instance, we may need the robot to follow a line for a specific distance. This post provides a step-by-step guide on creating a reusable EV3 Check Distance My Block
EV3 motors can not only power our robot. They’re also sensors. By using the Motor Rotation block, we can measure the degree of rotation and use it for distance calculation
The Motor Rotation block gets data from the built-in motor rotation sensor in the EV3 Medium Motor and Large Motor. It allows us to measure the motor’s degree of rotation or number of rotations. Additionally, we can obtain the motor’s current power level.
We use the Reset and Measure Degrees modes of the Motor Rotation Block to check distance.
The Reset mode resets the rotation amount to zero (0 degrees or rotations). Future measurements of the motor’s rotation amount using the Motor Rotation sensor will be measured relative to the reset position.
The Measure – Degrees mode outputs the current motor rotation amount in the Degrees output. The motor rotation is measured in degrees, relative to the last time it was reset with the Reset mode.
The Motor Rotation Block’s Reset mode and Measure mode are shown below.
Using Motor Rotation Block to Check Distance
Our move straight for certain distance post described one way to make our robot travel for certain distance. By using the Motor Rotation Block, we can program our robot to move for certain distance in a different way.
The following program will move our robot by by 12 inches. First we reset motor B. Then turn on Motor B & C using the Move Steering Block. Within a Loop block, measure the rotation degrees of Motor C and check if it has moved greater than or equal to 12 inches. If yes, stop the Motor B & C.
The following program will move our robot by by 300 millimeters.
The move distance vs motor degree ratio shown in the above programs should be adjusted based on your motor size. How to calculate the ratio is available in our post.
Creating Reusable EV3 Check Distance My Block
To make the blocks in the Loop block reusable, we can create a EV3 Check Distance My Block. First select those blocks, then select Tools → My Block Builder menu item as shown below.
Now enter the My Block’s name, description, and select an icon.
Add a parameter to select motor B or C.
Select an icon for the parameter.
Add another parameter for distance traveled.
The output parameter is logic (True or False). If the robot travels more or equal to the distance, it will output True, otherwise, the output is False. So, we select a logic icon exceptionally for this parameter.
Convert the input the port parameter from text to number.
Last step, connect the distance wire.
Using EV3 Check Distance My Block
Using the EV3 Check Distance My Block, the following program will move our robot by by 12 inches.
We can AND logic to make sure that both motor B and C move 12 inches before stopping.
In our Line Following post, we will show how to follow a line for a specific distance.