Previously:
Sci Fi Your Pi - Prince Dakkar's patent log taking chart compass
Sci Fi Your Pi - Prince Dakkar's patent log taking chart compass - Functional Design
Sci Fi Your Pi - Prince Dakkar's patent log taking chart compass - Route selection and indication
Sci Fi Your Pi - Prince Dakkar's patent log taking chart compass - Direction of Travel Indicator 1
Sci Fi your Pi - Prince Dakkar's patent log taking chart compass - Current Position
Sci Fi your Pi - Prince Dakkar's patent log taking chart compass - GPS Test
Direction of Travel Indicator 2
Having got the GPS working I could now get the GPS position for the current location and then compare that with the intended destination. The next challenge was to decide on some suitable destinations and to get the latitude and longitude for those places.
After a quick think I selected a short list of possible destinations to test the functionality (which would also act as start points for the route indication):
1. Sheffield
2. London
3. Perth
4. New York
5 St Petersburg
These destinations were chosen as they were visible on the map I had selected (and being based near Sheffield it would be easier to test using that as one of the destinations. They are also major cities that may feature in a steampunk adventure.
using Latitude Longitude Finder on Map Get Coordinates I came up with the following list.
1. latitude: 53.381129 longitude: -1.470085
2 51.507351 -0.127758
3. -31.953513 115.857047
4. 40.712784 -74.005941
5. 59.920613 30.322952
To test the device have set up these as variables and compare the position and print N or S and E or W to indicate the direction. Once the device is put together these would set a GPIO pin high to light an LED under the appropriate arrow.
To decide which way that the adventurer needs to travel the device needs to calculate the difference between the current location and the destination.
To calculate the direction to travel the latitude and longitude numbers of each location are compared. There is two ways to compare the numbers and indicate the direction to travel thatIi have considered.
The first is to simply take the destination figures away from the current location figure. If the result is a negative number then the destination is south (for latitude, west for longitude) of the current location so the adventure is shown the South arrow (West arrow for longitude) to move towards the destination. This gives a quick comparison and points the traveler towards the destination. The problem with this method is that if the destinations are at the edges of our flat map (with 0 0 at the centre) then the direction indicated could be moving all of the way around the world in the oposite direction to the one which would be the shortest way to get to the destination.
To correct this difficulty and travel in the shortest direction a correction need to be applied. To do this the difference can be used to check if the two positions are closer in the initial direction or by traveling in the opposite direction. This is actually simpler than it sounds as we just need to check if the difference is larger than 90 for latitude and larger for 180 for longitude then the traveler would be best served traveling in the opposite direction to that indicated above.
so that would be something like this (having got the position and in real python rather than a late night mix of python and pseudo python)
clat = current latitude clong = current longitude dlat = destination latitude dlong = destination longitude difflat = clat-dlat difflong = clong-dlong #for latitude if difflat > 90 OR difflat < -90: if difflat > 0: print "N" else print "S" else if difflat > 0: print "S" else print "N" #for longitude if difflong > 180 OR difflong < -180: if difflat > 0 : print "W" else print "E" else if difflat > 0: print "E" else print "W"
This would then go in a loop tested every few seconds and the print statements replaced with GPIO pins being set to high.
All sorted then, well not quite this would throw up issues if the destination was due south (or east, west or north) of the current position as the difference would be zero (although with the number of decimal places given by the GPS module you would have to be pretty accurately directly in line with the destination the problem still remains so a check to see if either difflong or difflat would be added before each section and no light in that section lit.
I also mentioned previously the possibility or adding the ordinals if there were sufficient pins left to do so. This would be a relatively easy task of adding a couple of variables and then seating those with the move directions. if both latitude and longitude required movement the appropriate ordinal could be lit up and only when there was no difference in Latitude or longitude would one of the cardinal points be lit.
The next job is to tidy up the above and get it running on the RPi as a test (which might happen this evening, but more likely over the weekend). Once the basic comparison is working i will then look at adding in the code to pick up the current and destination locations, With this part of the device working it could then function as a very basic navigation system. Having looked at blogs about the subject on here the idea occurred to me that I could use this part of the device as a way of locating geocaches if those locations were used instead of the major cities for the theatrical steampunk navigation device. Once in it's big case it may be a little impractical but adds an everyday use to what is going to be a bit of a novelty.