cobbzilla / vastra

privacy-respecting gps/map tools
Apache License 2.0
1 stars 0 forks source link

Accurate route mapping #1

Closed cobbzilla closed 4 years ago

cobbzilla commented 5 years ago

Despite our best efforts, the route map the app produces is not very accurate.

One source of this problem is that the raw GPS data points tend to "jump around" a lot. If you only use raw data, you get a terrible route map that jumps all over.

We first tried sampling a bunch of raw GPS points and then averaging them, which works well but requires a lot of time due to GPS sampling intervals (not fast). We wait several seconds to get enough GPS data points, then we have a decent idea of the true location. But in a fitness tracker this is horrible, because the user is constantly moving (running, bicycling, etc).

Alas, all is not lost: we have an accelerometer and a clever filtering algorithm. We can use the accelerometer to check if we are standing still or moving (and what is our velocity). We can use a clever filter to combine the raw GPS and accelerometer data and produce a stream of synthetic (filtered) location points.

In theory, we accomplish our goal by feeding both GPS and accelerometer data into a Kalman filter, and reading accurate locations out.

The app should do the following:

  1. Upon starting a workout, begin a loop reading from GPS and accelerometer. Feed the values we read into the Kalman filter.
  2. Periodically read the current location from the filter and store that as a "filtered" data point.
  3. During the workout, analyze the filtered data (and also raw data if needed or if it helps) and draw a route map (sequence of location points) of where the user traveled.
  4. At completion of the workout, reanalyze and adjust the route points if needed.

Theory:

The Kalman filter we created seems to be an improvement over the raw data, but it's still not great. We take the app for a walk to test it. It's less jumpy than the raw data, but still shows big swings; the path should be a certain shape, but it still has places where it goes far away from the route we know we actually took, and other unacceptably gross inaccuracies.

This goal of this project is to achieve 90% accuracy of a proprietary app, with no gross inaccuracies. MapMyFitness (MMF) will be our benchmark app. We'll perform acceptance testing by running our app with the code you write alongside MMF on a circuit course. The app passes acceptance testing when the absolute value of the difference in areas between our route map and MMF's route map is less than 10% of the area of the MMF map, with no gross inaccuracies.

Potential Complicators:

It could be the case that a different filter type is required, or multiple filters are required, or some other processing needs to constantly compare filtered data with raw data and make adjustments to the route map as needed. Really the Kalman filter is a starting point, it is entirely possible that much more needs to be done.

It could be the case that this project is impossible to complete using only a mobile browser and HTML+JS; for example perhaps the only way to get the best resolution data from GPS and accelerometer is to be running natively in an iOS/Android app. In that case, we would want to ensure the core code is reusable across both iOS and Android. Here are some ways to do that: https://stackoverflow.com/questions/37047483/best-way-to-share-code-between-ios-and-android We would prefer the React Native approach if that is feasible. If not then a shared C or C++ library would be our next preference.

mul1sh commented 5 years ago

@cobbzilla I'm interested to work on this issue but before I do these are my thoughts on this because of my experience dealing with something similar before.

To be honest the issue is not the filter, its how the html5 geolocation api for mobile browsers, generates the location updates. This api largely depends on the mobile browser implementation of location access and it may or may not have access to the device GPS and if it doesn't have access to the device GPS it has to use other methods to try and get the location i.e. cell tower triangulation, getting the location based on the device ip address e.t.c which now results in the jumpy locations. So in short getting accurate route mapping with a mobile browser is almost impossible.

The solution like you accurately put it, is to get the location data natively. Using react native we can do this via the react-native-geolocation-service plugin and also just to ensure high accuracy we can use the kalman filter for location updates to ensure a much smoother route. If implemented like this the route drawn will definitely match the MapMyFitness app's accuracy.

mul1sh commented 5 years ago

@cobbzilla i sent you some mails, kindly check 🙂

cobbzilla commented 4 years ago

This issue is closed and the bountysource bounty has been cancelled. I've decided to focus on other priorities.