Course 7 / Lecture 10:

Outdoor navigation using GPS and mobile network

This lecture is about navigation using the Global Position System (GPS) satellites. In this lecture you will install Ozeki 10 on an Android mobile phone, and you will use the GPS coordinates of the Android mobile to do the navigation. You will also learn how to move a Lego robot around based on these coordinates with code written in SNAP.


Figure 1 - Ozeki BillyBot telefonnal

Requirements

Task #1:

Set the start and the final coordinates.


First, create a block, where you can add the latitude and longitude coordinate. You have to subscribe to the GPS of the Android mobilephone to get information about the current GPS points. Add the 'Rotate' block where set '2666' degrees because the robot will go forward only 1 meter if you use this parameter. You need to set the start latitude and longitude as you can see it on the Figure 2 below. Save the finish GPS points with using two 'set' blocks.


Figure 2 - Set the Latitude and Longitude coordinates

Task #2:

Calculating the distance between two GPS points!


First of all, make a block where calculate the distance. Create a variable called 'distance' and drag the 'Set' block from the Variable menu. You have to determine the shortest distance between two points with using the geoid to a sphere of radius R = 6372795.477598 meters and the angles used are express in radians, so you need to converting between degrees and radians. Multiplying the angle by PI and dividing by 180, after that you get the distance. You should add the 'round' block to rounding the distance value. You must use the formula as you can see it on the Figure 3.


Figure 3 - Use 2 GPS points to calculate the distance

Task #3:

Calculation of direction between two GPS points!


Step 1: Create three important variables and set it

Now, make another block to calculate the direction between two points. Create three variables called 'lon', 'x' and 'y'. Use the 'set' blocks to store the value. Subtract the final longtitude from the start longitude and set the value to 'lon'. You have to use another two formulas to set 'x' and 'y' variables as you can see it on Figure 4 below.


Figure 4 - Set 3 variables

Step 2: Check the x and y variables

First of all, drag the 'if [condition] else' block to examine the x and y variables. Add the '=' block to the condition part, and drag the x variable to the left side and write 0 to the right side. If the condition is true, the x is equal to 0, the if branch is executed. Put the 'if [condition] else' block into the previous if branch where you should examine the y value. Drag the '>' block from the Operators menu and put 'y' to the left side and write 0 to the right side. The condition is true, the if branch is executed and the condition is false, the else branch is executed so add the 'set' block to the if branch where set the degree to 90 and set the degree to 270 in the else branch. (Figure 5)


Figure 5 - Examine the x and y value

Step 3: Examine x and y variables to set the degree variable

Put the another 'if [condition] else' block into the main else branch where you check the 'x' variable again. Add the '>' block to the condition part and drag the 'x' to the left side and write 0 to the right side. You have to add the following formula into the if branch. In the else branch you should add the another 'if [condition] else' block to examine the 'y' variable. Drag the 'or' operator to the condition part and choose the '>' block to the left side and '=' block to the right side. The condition is true , if the y is greater than 0 or equal to 0. Add the following formulas which set the degree. (Figure 6)


Figure 6 - Set the degree variable

Step 4: Setting the degree variable

You need only one step to get the direction between two GPS points. First, subtract the degree from 360 and change the degree by 360 until that value is less than 0. After that, change by -360 until degree's value is greater than 0. Finally, use the 'abs of' operator to set the degree. (Figure 7)


Figure 7 - Last part to calculate of direction

Task #4:

Display the current GPS coordinate on the Brick's LCD!


You will build block, which display the robot's current GPS coordinate on the LCD display of the Brick. Start by make a block, called 'Print'. You have to add the 'repeat [condition]' block and drag the 'distance' into the condition part. This block is executed as many times as the distance. Create two variables, called 'current_lat' and current_long', which store the robot's current destination. After that, you have to add the four 'To [conncetion] message [command_text] blocks and select the LCD in all of them. In the first one, write the 'clean' command, then set the middle font size with using the 'fontsize middle' command. The third block will write the destination to the LCD, you have to join the 'draw text foreground 10 55' command with current Latitude and Longitude. In the last one block, use the 'update' command to display the input text as you can see it on Figure 8 below.


Figure 8 - Set the Brick's LCD

Task #5:

Move the robot to the final destination.


It's the time to move the robot to the right place what you set in the first task. First, turn the robot to the right direction with using the degree and multiplying by 6.2. It means the robot turns 6.2 degrees if give it one degree. After that, add the 'repeat' block and drag the 'distance' to the condition part. You have to use the 'Rotate' block and set '2666' degrees and the robot goes one meter. The repeat block is executed and the robot goes forward as many times as is the distance value. (Figure 9)


Figure 9 - Robot goes to the finish GPS coordinate

Task #6:

Test the program with using two parameters



Figure 10 - 4 blocks

Program code


Figure 11 - Program code

More information


Next


Copyright © 2000- |Ozeki Ltd | info@ozekirobot.com |
Page: 6114 | 79.99.42.43 | Login