Course 6 / Lecture 5:

Measure distance

If you know your robot's speed you can calculate the travelled distance. You will learn how to build a SNAP program, which calculates the travelled distance using the speed and time measurement. By completing this lecture you will understand how GPS systems can predict and calculate travelled distance.

Figure 1 - Calculate the distance traveled by your Sniffer


Task #1:

Import the project you created in the previous lecture and run it for 10 seconds!

In this lecture you need to use the program that you created in the previous lecture. So please open the Snap application and import the Snap code you wrote in Lecture 4. After that, you should start the stopwatch and your Sniffer at the same time using the 's' key on your keyboard. Please wait about 10 seconds then press the 't' key to stop the stopwatch and the robot. On the canvas you can see the exact time passed like Figure 2 demonstrates.

Figure 2 - Import and run the project from Lecture 4

Task #2:

Calculate the distance traveled from the speed you already know and the measured time!

To calculate the distance of the moving robot, you will use the equation on Figure 3. The speed is equal to the distance traveled divided by the passed time. To get the distance on the right side of the equation, you should multiply both sides by the passed time. So the speed is equal to the passed time multiplied by the speed. So in this task you should multiply the speed calculated in the previous lecture by the passed time read on the canvas to know how far your Sniffer moved.

Figure 3 - How to calculate distance from speed and passed time

Task #3:

Check your calculation by measuring the traveled distance!

After you have calculated the distance that your Sniffer should took, you can test how accurate your calculation was. To do this, please measure the distance between the start and end points using your ruler as it demonstared on Figure 4. If it was correctly calculated, you should apporximately get the same result from the distance measurement as well as from the calculation.

Figure 4 - Confirm your calculation with a ruler

Task #4:

Upgrade the stopwatch to measure the traveled distance by knowing the speed!

STEP 1: Upgrade the stopwatch

First create two new variables and name them as 'speed' and 'distance'. The 'speed' variable will be used as a constant value to help calculating the distance. The 'distance' variable will always store the value of the momentary distance traveled. To set their values, please place two 'set [variable] to [value]' found in Variables category to the stage. Using the first one, you need to set the speed value you calculated in the previous lecture as a value of the 'speed' variable then place the block under the 'when s key pressed' one. Then using the second placed 'set' block, you need to set its value using the '[value] x [value]' block to multiply the speed by the passed time. To refresh the value of 'distance' variable while the program is running, please place the associated 'set' block into bottom of the 'repeat until' block as you can see on Figure 5. Thanks to these steps, you can see the passed time and distance traveled of the Sniffer continuously while the program is running.

Figure 5 - Modify your program to calculate distance

STEP 2: Test your modified stopwatch

After you have modified the stopwatch, please start it using the 's' key and wait about 10 seconds, then press the 't' key to stop your stopwatch and also your Sniffer. If you checked the checkbox next to the 'distance' variable inside the 'Variables' category, you should also see the distance (in meters) that your Sniffer is traveled on the top right corner of the GUI like Figure 6 shows.

Figure 6 - Test your modified program and check the distance after stopping it

Program code

Figure 7 - Program code that moves the robot and calculates the traveled distance

More information


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