Shop OBEX P1 Docs P2 Docs Learn Events
GPS Distance Tracking — Parallax Forums

GPS Distance Tracking

codysprakercodyspraker Posts: 46
edited 2012-04-22 18:15 in Robotics
I am looking to make a simple program that can track the distance that is traveled with the gps from Parallax. The project I am looking to complete is a program that can track your distance when the program is started. The functionality would mimic a car odometer. It would continue to track the distance traveled until a reset button is pressed and then the distance would be set back to zero. Does anyone know where to find where a code like this could be found or know if this is a realistic project? I am very new to the GPS sensor and hoping to get some insight into how to work with it. Thanks for the any help!

Comments

  • prof_brainoprof_braino Posts: 4,313
    edited 2012-04-21 07:00
    Sounds doable.

    To clarify the requirement, you want to recieve GPS sentences, extract the position, and log all the positions?
    OR do a delta from the previous position?
    There could be a LOT of positions, so you can include a requirement for large memory storage, SD card is a simple solution for that.

    Summary: Collect your requirements, and subdivide each requirement unti you have something you can code.
    Do experiments with the chunks of code until you know what it is you want the code to accomplish.
    THEN write the final code. (I'm a process guy, I say this stuff a lot).

    I'm also a forth guy. If you want to do this interactively (fast and fun, with lots of immediate gratification) download propforth and install it on you prop board. The serial comms and SD support are included, all you have to do is follow the GPS datasheet, and the solution pretty much jumps out at you. (At lest it does for me and a couple other folks, your experience may chance during actual gameplay).

    In any case, continue to post your evolution of requirements and code and we will try to help.

    Please try it in forth, so I can use your code.
  • SRLMSRLM Posts: 5,045
    edited 2012-04-21 07:37
    Fairly straight forward. You can get the position in terms of (lat,long) pairs. For example, you may have a sequence such as

    (59.0117,-117.5814)
    (59.0117,-117.5815)
    (59.0116,-117.5819)
    (59.0119,-117.5822)

    Then, you'll need to find the difference between each consecutive sets of numbers, and sum that distance into a result variable.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-21 08:20
    SRLM wrote: »
    Fairly straight forward. You can get the position in terms of (lat,long) pairs. For example, you may have a sequence such as

    (59.0117,-117.5814)
    (59.0117,-117.5815)
    (59.0116,-117.5819)
    (59.0119,-117.5822)

    Then, you'll need to find the difference between each consecutive sets of numbers, and sum that distance into a result variable.

    You'll need some sort of minimum distance before adding consecutive readings. Since the GPS readings are inaccurate if you add the distances between each reading you could end up logging a lot of movement while sitting still.

    You also need to compute the great circle distance between the two readings you wish to log.
  • SRLMSRLM Posts: 5,045
    edited 2012-04-21 08:35
    Duane Degn wrote: »
    You'll need some sort of minimum distance before adding consecutive readings. Since the GPS readings are inaccurate if you add the distances between each reading you could end up logging a lot of movement while sitting still.

    I was going to let him figure that out on his own :)
    You also need to compute the great circle distance between the two readings you wish to log.

    I doubt it really matters unless he is trying to compute distances from a small series of widely spaced points. If he takes the readings often enough it's a bit of a Riemann integral:

    240px-Riemann_sum_convergence.png
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-04-21 08:38
    As you see, the simple "log the distance" requirement gets expanded into various most specific requirements
    * filter for lat, log
    * figure delta
    * reject below minimum distance threshold due to GPS inaccuracy
    * calculate great circle
    * log way points
    * calculate total distance

    These are just the first pass. As you continue to examine the application, each of these gets further refined. Eventually, each requirement gets expressed as something thats obvious to enough to code and verify.

    Of course, while you doing this, you are messing with actual code experiments, to see if you can code anything now, and see how it works out. So you end up working top down from the requirements and bottom up from the code experiments till you meet in the middle.

    The other issues are testing and documentation.

    Each thing you code, you want to determine yes or no, does it do what it needs to? You want to be able to test stuff when something changes, so you don't break stuff that was already working.

    Documentation is usually neglected. If you do a bunch of work, then set it down for a week or a year, or give it to the new kid, will their be enough information to get back up to speed when a change is needed, or will this wheel need to be re-invented again? (Effectively doubling at minimum, the cost in your time). Most folks learn the hard way, if at all, that every minute spent on documentation is an hour saved in rework next year. Surely some folks will pipe in to contradict this, thus an example of the hard way in action.

    Now that we started the analysis, this doesn't look so hard. Maybe I'll get off my butt and work on this too!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-21 09:12
    "Distance" can be a slippery thing to define. I have a friend whom I bike with occasionally. He has a bike odometer; I, a GPS. His distance logged is always about 10% more than mine, even though he's carefully calibrated the odo. But, when I look at the plot of our route from the GPS, it's obvious where the discrepancy lies. The GPS records points at intervals along the route, connects them with straight lines, and adds up the lengths of the lines. My friend's odometer records every little meander he and I take, back and forth across my presumptive line segments.

    I guess my point is that you have to decide what "distance" is before you measure it. That said, however, there might be a very easy way to do what you want: just integrate the GPS ground speed data over time. If it works without accumulating too many errors, it will be easier than converting lat/long to distance.

    -Phil
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2012-04-21 09:21
    I have been doing a lot of work with great circle math lately for my scavenger hunt project. I haven't released code for it yet, but here is some food for thought that may be helpful:

    Propeller-Based-Handheld-GPS-with-Full-Code
    http://forums.parallax.com/showthread.php?133806

    GPS-Datalogger-Using-Google-Earth
    http://forums.parallax.com/showthread.php?115552

    GPS-Logging-Reporting
    http://forums.parallax.com/showthread.php?133514

    Google-Earth-GPS-SD-Card-Logger-COMPLETE!
    http://forums.parallax.com/showthread.php?104049

    Propeller-Based-Reverse-Geo-Cache-Birthday-Present-Project
    http://forums.parallax.com/showthread.php?118830

    @phil: very good point, it would be much easier to calculate distance from speed. You will have a slight margin of error still (since the GPS needs to be getting valid data to determine speed, causing a lag), but the code to get distance from the speed will be much easier to dial in. Great circle math and the propeller can be a bear.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-04-21 09:38
    "Distance" can be a slippery thing to define.
    .. integrate the GPS ground speed data over time.
    ...converting lat/long to distance.

    That sounds funny at first! But brings to light another possible requirement, and function to code.

    So now you have two choices to track, Lat/Long Delta, or speed over time. Both are valid, and suitable for different purposes, I would suggest including both. How cool would that be! Then you can have the general "waypoints path" distance, and compare it to the speed over time distance,and it might tell you something interesting.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-21 09:47
    I would have thought calculating distance from speed wouldn't be as accurate as using great circle calculations (though I accept it is based on the sources telling me it is).

    I'd think there would be times the speed approach wouldn't work well. I started work on a GPS pedometer but I stopped work on it (for now) since the OLED display I was using with it died.

    My plan was to compute distances between turns in the route. Since I wanted to log evening walks with my wife through our neighborhood, I thought the way to keep most of the errors out would be to measure the distance between each turn (most would be 90 degrees) of our walk.

    I doubt we walk fast enough to use the speed approach to distance measurement.
  • codysprakercodyspraker Posts: 46
    edited 2012-04-22 17:58
    Regarding the idea of using the speed to calculate distance, wouldn't that require taking the two points and measuring the distance between the two in the first place? Since you would use the amount of time compared to the distance between the two points. It would seem to make sense to just take the distance between the two temporary points and add that to the total distance traveled in order to get your rolling total.
  • codysprakercodyspraker Posts: 46
    edited 2012-04-22 18:00
    Sounds doable.

    To clarify the requirement, you want to recieve GPS sentences, extract the position, and log all the positions?
    OR do a delta from the previous position?


    The functionality of the odometer in a car is the best example I can come up with. Press restart to begin measuring from a start point, and then measure the distance traveled from the point while displaying it and then go back to zero when the reset button has been pressed.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-04-22 18:15
    Regarding the idea of using the speed to calculate distance, wouldn't that require taking the two points and measuring the distance between the two in the first place?
    No. The GPS unit computes the ground speed every second and includes it as one of the data fields in its output.

    -Phil
Sign In or Register to comment.