Course 6 / Lecture 2:

Move along a path

In this lecture you will learn how to get a vehicle to turn exactly 90 degrees. The lecture uses a robot that can do turns with the help of two motors. You will learn how to calculate the required motor rotation from the robot's dimensions. You will see the command to use to make the turn. You will also solve a task where the goal is to move your robot along a square path, using the calculated rotation values.

Figure 1 - Turning your robot by 90 degree


Task #1:

Draw a wheel and mark the radius!

Radius - a straight line extending from the center of a circle to the contour.

Figure 2 - Radius

Task #2:

Draw a wheel and mark the circumference!

Circumference - the distance around something rounded. For example the wheel.

Figure 3 - Circumference

Task #3:

Write what you know about the π!

π - mathematical constant. It is approximately equal to 3.14159.

Task #4:

Measure your Sniffer's turning width!

To turn your Sniffer by 90 degree, first you need to measure your Sniffer's width. You can measure your Sniffer's width using a A4 paper, a pencil and a ruler. First place your paper on a horizontal surface, such as on the table or floor. After that, place your Sniffer on it, then mark the wheels' location on the left and right side of your Sniffer on the paper. Now you can measure the distance between the two marked point on the paper. This is the robot's width. This value is very important in this lecture, because you can calculate the turning width from this measurement. To calculate the turning width, the width of the robot's wheel should be extracted from the Sniffer's width (Figure 4).

Figure 4 - Measuring the width of your robot and the wheel width too

Task #5:

Calculate how many centimeters should your wheel travel!

After you have measured the robot's turning width, you can calculate how many centimeters should your Sniffer's left wheel travel to turn the robot by 90 degrees to the right and reach the end point (Figure 5). To calculate it, you must know the circumference of the full circle path. Get the path's circumference by multiplying the turning width by 2*Pi. In this lecture you will turn your Sniffer by 90 degrees, so you should divide the circumference by 4, which is a 90° turning path for your Sniffer.

Figure 5 - How many centimeters to move

Task #6:

Calculate how many degrees should the wheel turn to turn your robot by exactly 90 degrees!

After you calculated in the previous task how many centimeters should the Sniffer's wheel roll to turn the robot by 90 degrees, you should figure out the exact angle you need to rotate the motor. In this task you will use the same algorithm as before to calculate how many degrees to rotate the left motor to turn your robot vehicle right. Take in count distance value what your Sniffer's wheel should take during the turning. First divide the path with the wheel's circumference measured in the previous lecture to get the number of required turns. After you have the number of full turns to make, you just have to multiply it by 360 to get the required turning angle in degrees (Figure 6).

Figure 6 - How many degrees should the wheel turn

Task #7:

Write code to turn your robot by 90 degrees!

STEP 1: Create the constants in SNAP

After that you calculated everything to turn your Sniffer by 90 degrees right, open the built-in Snap application in Ozeki 10. First you should create an entry point for your program, so place a 'when green flag clicked' block to the stage. After that please create three variable called 'Pi', 'circumference' and 'turning_width'. Finally set their values using the 'set [variable] to [value]' block found in Variables category. Please set 'Pi' to 3.14159, 'circumference' to 13.5 (measured in Lecture 1) and the 'turning_width' to 13.4 (measured in Task #4) as you can see on Figure 7.

Figure 7 - The required constant variables

STEP 2: Make a calculations in SNAP

After creating the variables, you should calculate how many degrees should your Sniffer's motor rotate. Please create two new variables for the calculations, called as 'distance_traveled' and 'degree'. Start by dragging in two 'set [variable] to [value]' blocks to set their values. Set the 'distance_traveled' by using the 'X x Y' block to multiply'Pi' with 2, then multiply the result with the 'turning_width' and finally dividing the calculation by 4. To get the degree, please divide the 'distance_traveled' with the 'circumference' and multiplying it by 360. See it created on Figure 8.

Figure 8 - Calculating the correct motor rotation angle in SNAP

STEP 3: Use calculations in SNAP - moving

After that your program calculate everything, you should turn your robot by the calculated degree. To do this, please use the 'Rotate [motor] by [degree]' block where 'motor' should be A and use the 'degree' variable for the 'degree' field like Figure 9 demonstrates. After that you should test your calculation by running your program with a click on the green flag icon, which is on the top right corner. Now you should see that your Sniffer has turned 90° right by using only the left motor. After that you can turn your robot by a defined degree using only one motor. The right motor turns it left.

Figure 9 - Rotating the Lego motor with the calculated degree

Task #8:

Write code to move your robot in a square court!

STEP 1: Moving in a square court - Repeat

After that you can turn your Sniffer by 90 degrees, you should create a program, which will move your Sniffer in a square court. To move your Sniffer in a square court, you should move it for equal duration and turn it every time by 90 degrees. So you need to use the 'repeat [times]' block found in the Control category after the 'set' blocks to repeat the movement and rotation. Because the square has four sides, please change the number parameter in the 'repeat [times]' block to 4 (Figure 10).

Figure 10 - Drag in a repeat block and set it to 4

STEP 2: Moving in a square court - Move and turning

To repeat the movement, you should place a 'Drive [motor] forward [sec] sec' block inside the 'repeat' block. Please select the 'A+D' for the value of the 'motor' field because these motors drive the robot. If you want to move your robot longer, you need to increase the value of the 'sec' field. To repeat the rotation, you should place a 'Rotate [motor] by [degree]' block inside the 'repeat' block. Finally replace the default '360' value with the 'degree' variable and run the program by clicking on the green flag. Now you should see that your Sniffer moving in a square court (Figure 11).

Figure 11 - Clockwise movement in a square court. Go counterclockwise with motor B

Program code

Figure 12 - The program code moves the Sniffer in a square court

More information


Copyright © 2000- |Ozeki Ltd | |
Page: 6091 | | Login
Thank you for visiting this page