Uncategorized

multi-processing

Calculate Accurate Distance Traveled with GPS in Python [closed]

Ask QuestionAsked 2 days agoActive yesterdayViewed 22 times0Closed. This question is off-topic. It is not currently accepting answers.


This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center.

Closed 12 hours ago by joanMilliwaysDougieDarth Vader.

(Viewable by the post author and users with the close/reopen votes privilege)Edit question

I am trying to update distance traveled between GPS coordinates. My error is that the GPS can move short distances while sitting still. I am currently simply adding the new coordinates to a list every second, calculating the distance between this second and last second, then appending the distances to a new list then add them all together.

The issue is that the small movements in distance keep accumulating. Does anyone know the proper way to do this?

self.breadcrumbs = []

#Calc Linear Distance GPS
while 1:
    report = gpsp.get_current_value() #Retrieves GPS Values
    try:
        self.lat = report.lat
        self.lon = report.lon
        self.latlon = (self.lat, self.lon) #Put lat lon into tuple 
        self.breadcrumbs.append(self.latlon) #Append lat lon to breadcrumb list
        breadcrumb_distances = [] #Holds distances between latlon data points
        for i, b in enumerate(self.breadcrumbs):
            current_location = b
            last_location = self.breadcrumbs[i - 1]
            miles = geodesic(current_location, last_location).miles 
            feet = miles * 5280 #convert to feet
            breadcrumb_distances.append(feet)
        cumulative_distance = round(sum(breadcrumb_distances),2)
        print(cumulative_distance)
    except Exception as e:
        print(e)
    sleep(1)

python-3gpsshareedit  follow  reopenflag asked 2 days agoMike C.14144 bronze badges

  • 1this is not a RPi question – jsotola 2 days ago
  • 2@jsotola You’re right. I should go over to Stack and ask this one. – Mike C. 2 days ago
  • 1You’re shooting yourself in the foot. Why do you add distance when the velocity is zero/near zero? You could start here – Seamus 2 days ago
  • 1@Seamus Thanks for the tip. I’ll check it out. – Mike C. 2 days ago
  • 1Hope it helps… you will almost always get a better outcome in these Q&A forums if you do a bit of homework beforehand. – Seamus 2 days ago
  • Well, no worries about small distances accumulating, because you can (1) do moving averages using Rpi Thonny python eg, (2) use Excel worksheet or Rpi LibOffice worksheet and graph to handle that, (3) Use a Rpi small database utility (of course much more powerful) to store, analyze, and reports. – tlfong01 53 secs ago   Edit   

add a comment

1 Answer

ActiveOldestVotes1

I would advise that you lookup the use of Kalman filters or similar to handle such, but the maths can be heavy so you have been warned. You may also need a second sensor, an accelerometer, which will give you two measures of velocity tat you can then fuse into a single more accurate measure.shareedit  follow  flag answered yesterdayNick49133 silver badges1010 bronze badgesadd a comment

Not the answer you’re looking for? Browse other questions tagged python-3 gps or ask your own question.

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.