• Stars
    star
    528
  • Rank 83,941 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mad Location Manager is a library for GPS and Accelerometer data "fusion" with Kalman filter

This is library for GPS and Accelerometer data "fusion" with Kalman filter. All code is written in Java. It helps to increase position accuracy and GPS distance calculation on Android devices for the driver's and couriers' apps. And also, it may be used for precise tracking in on-demand services.

Project consists of 2 parts:

Blog (english version)

Blog (russian version)

Our site

License: MIT Developed by Mad Devs

What can "Mad Location Manager" do?

This module helps to increase GPS coordinates accuracy and also:

  • reduces the errors in route tracking;
  • decreases the noise from Low-class smartphones;
  • excludes sharp «jumps» to the points remote from a real route;
  • eliminates additional distance when the object is motionless;
  • filters errors duу to the short-term loss of GPS-signal.

How to install

Use last version from link below (jitpack):

How to use

There is example application in current repository called "Sensor Data Collector".

WARNING!!

Right now these sensors should be available:
TYPE_ROTATION_VECTOR, TYPE_LINEAR_ACCELERATION.

It's possible to use just TYPE_ACCELEROMETER with high-pass filter.
Also it's possible to use Madgwick filter instead of rotation vector, but gyroscope and magnetometer sensors should be available in that case.

KalmanLocationService

This is main class. It implements data collecting and processing. You need to make several preparation steps for using it:

  1. Add to application manifest this:
<service
            android:name="mad.location.manager.lib.Services.KalmanLocationService"
            android:enabled="true"
            android:exported="false"
            android:stopWithTask="false" />
  1. Create some class and implement LocationServiceInterface and optionally LocationServiceStatusInterface .
  2. Register this class with ServicesHelper.addLocationServiceInterface(this) (do it in constructor for example)
  3. Handle locationChanged callback. There is Kalman filtered location WITHOUT geohash filtering. Example of geohash filtering is in MapPresenter class.
  4. Init location service settings object (or use standard one) and pass it to reset() function.

Important things!

It's recommended to use start(), stop() and reset() methods, because this service has internal state. Use start() method at the beginning of new route. Stop service when your application doesn't use locations data. That need to be done for decrease battery consumption.

Kalman filter settings

There are several settings for KalmanFilter. All of them stored in KalmanLocationService.Settings class.

  • Acceleration deviation - this value controls process noise covariance matrix. In other words it's "trust level" of accelerometer data. Low value means that accelerometer data is more preferable.
  • Gps min time - minimum time interval between location updates, in milliseconds
  • Gps min distance - minimum distance between location updates, in meters
  • Sensor frequency in Herz - the rate sensor events are delivered at
  • GeoHash precision - length of geohash string (and precision)
  • GeoHash min point - count of points with same geohash. GPS point becomes valid only when count greater then this value.
  • Logger - if you need to log something to file just implement ILogger interface and initialize settings with that object. If you don't need that - just pass null .

There is an example in MainActivity class how to use logger and settings.

GeoHashRTFilter

There are 2 ways of using GeoHash real-time filter :

  • It could be used as part of KalmanLocationService. It will work inside that thread and will be used by service. But then you need to use start(), stop() and reset() methods.
  • It could be used as external component and filter Location objects from any source (not only from KalmanLocationService). You need to reset it before using and then use method filter() .

It will calculate distance in 2 ways : Vincenty and haversine formula . Both of them show good results so maybe we will add some flag for choose.

The roadmap

Visualizer

  • Implement some route visualizer for desktop application
  • Implement Kalman filter and test all settings
  • Implement noise generator for logged data
  • Improve UI. Need to use some controls for coefficient/noise changes

Filter

  • Implement GeoHash function
  • Get device orientation
    • Get device orientation using magnetometer and accelerometer + android sensor manager
    • Get device orientation using magnetometer, accelerometer and gyroscope + Madgwick AHRS
    • Get device orientation using rotation vector virtual sensor
  • Compare result device orientation and choose most stable one
  • Get linear acceleration of device (acceleration without gravity force)
  • Convert relative linear acceleration axis to absolute coordinate system (east/north/up)
  • Implement Kalman filter core
  • Implement Kalman filter for accelerometer and gps data "fusion"
  • Logger for pure GPS data, acceleration data and filtered GPS data.
  • Restore route if gps connection is lost

Library

  • Separate test android application and library
  • Add library to some public repository

Theory

Kalman filtering, also known as linear quadratic estimation (LQE), is an algorithm that uses a series of measurements observed over time, containing statistical noise and other inaccuracies, and produces estimates of unknown variables that tend to be more accurate than those based on a single measurement alone, by estimating a joint probability distribution over the variables for each timeframe.

You can get more details about the filter here.

The filter is a de-facto standard solution in navigation systems. The project simply defines the given data and implements some math.

The project uses 2 data sources: GPS and accelerometer. GPS coordinates are not very accurate, but each of them doesn't depend on previous values. So, there is no accumulation error in this case. On the other hand, the accelerometer has very accurate readings, but it accumulates error related to noise and integration error. Therefore, it is necessary to "fuse" these two sources. Kalman is the best solution here.

So first - we need to define matrices and do some math with them. And second - we need to get real acceleration (not in device orientation).

First one is described in current project's wiki. But second one is little bit more complex thing called "sensor fusion". There is a lot information about this in internet.

Algorithms

Sensor fusion is a term that covers a number of methods and algorithms, including:

For real acceleration we need to know 2 things: "linear acceleration" and device orientation. Linear acceleration is acceleration along each device axis excluding force of gravity. It could be calculated by high pass filter or with more complex algorithms. Device orientation could be calculated in many ways:

  • Using accelerometer + magnetometer
  • Using accelerometer + magnetometer + gyroscope
  • Using Madgwick filter
  • Using virtual "rotation vector" sensor.

Best results show Madgwick filter and ROTATION_VECTOR sensor, but Madgwick filter should be used when we know sensor frequency. Android doesn't provide such information. We can set minimum frequency, but it could be much higher then specified. Also we need to provide gain coefficient for each device. So best solution here is to use virtual ROTATION_VECTOR sensor. You can get more details from current project's wiki.

Issues

Feel free to send pull requests. Also feel free to create issues.

License

MIT License

Copyright (c) 2020 Mad Devs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

aws-eks-base

This boilerplate contains terraform configurations for the rapid deployment of a Kubernetes cluster, supporting services, and the underlying infrastructure in AWS.
HCL
600
star
2

ariadna

Geocoder Ariadna on ElasticSearch with OpenStreetMap
Go
333
star
3

openfreecabs

Web/mobile app that shows nearest taxi's by your location
179
star
4

openfreecab-storage

In-memory storage for openfreecabs.org
Go
135
star
5

seo-analyzer

The library for analyze a HTML file to show all of the SEO defects
TypeScript
75
star
6

android-ci-cd

This boilerplate demonstrates how to easily prepare a CI/CD for an android application based on Fastlane, github actions or gitlab CI/CD.
Ruby
71
star
7

django_minio

Django app to use Minio Server as file storage.
Python
65
star
8

gocodelabru

Coding simple database for geospatial data using Go programming language workshop in Russian language
Go
64
star
9

idmatch

Match faces on id cards with OCR capabilities.
Python
60
star
10

comedian

Comedian bot-a team management system that helps track performance and assists team members in daily remote stand-ups meetings.
Go
54
star
11

fcm

Firebase Cloud Messaging for application servers implemented using the Go programming language.
Go
50
star
12

go-idmatch

ID cards recognition based on gocv
Go
42
star
13

mad-fake-slack

Fake Slack implementation on node.js + express.js + express-ws
JavaScript
38
star
14

telegram_bbbot

Telegram Bug Bounty Bot
Go
28
star
15

maddevs

Mad Devs website source code
JavaScript
28
star
16

sensor-fusion-demo

Java
26
star
17

gocodelaben

Building simple database for geospatial data using Go programming language workshop
Go
23
star
18

react-madboiler

The boilerplate to create React application projects. The boilerplate includes everything you need and describes some additional useful things such as typescript and cypress.
JavaScript
23
star
19

grpc-rest-api-example

Репозиторий для статьи https://medium.com/p/f5d52d7ffff6
Go
22
star
20

yourcast.tv

21
star
21

yourcast-streamer

Streamer component for yourcast.tv
Go
20
star
22

ios-pipeline

Ruby
19
star
23

heimdall

Ethereum Smart Contracts Security Monitoring
HTML
19
star
24

nambataxi-telegram-bot

Order a Namba Taxi cab via Telegram
Go
18
star
25

vue-madboiler

A ready-made boilerplate to set up a Vue.JS project which includes the basic structure of styles, package of icons, configure the linter properly, etc.
HTML
18
star
26

openfreecabs-android

Java
14
star
27

openfreecabs-web

Openfreecabs.org web interface
CSS
14
star
28

slack_history_bot

Receive and search history
Go
13
star
29

mad-navigator

C
13
star
30

mad-telegram-standup-bot

Telegram Bot for asynchronous standups meetings
Go
11
star
31

openfreecab-crawler

Crawl data for openfreecabs.org
Go
9
star
32

yourcast-web

web interface of yourcast.tv
JavaScript
7
star
33

openfreecabs-ios

Swift
7
star
34

virtual-okno

Video bridge for full-time communication between buildings, public spaces, teams
6
star
35

mad-radiator

Script for collect data from analytics and send to slack(webhook) and telegram
TypeScript
6
star
36

bbcrawler

[OBSOLETE REPO] Bug Bounty Crawler and bot new repo --->
Go
6
star
37

django-osmp

Django battery for integration with Qiwi payment system
Python
5
star
38

osrm

Make requests from your Go application to OSRM backend
Go
4
star
39

django_pytest_example

The repo for blog article https://blog.maddevs.io/testing-django-on-steroids-with-pytest-38fe11a3538c
Python
4
star
40

graphql-demo

Python
4
star
41

terraform

small examples and modules
HCL
4
star
42

new-para-bot

Detect new trading pairs and report lucky users
Go
3
star
43

django-webmoney

Python
3
star
44

email2name

Resolve or discover names from emails using external APIs or local dummy algo
PHP
3
star
45

screen-monitoring

Go
3
star
46

awesome-smart-contracts

Real world smart contracts examples
3
star
47

madpwa

Mad Progressive Web Apps
CSS
2
star
48

iOS-ETH-web3-boiler

iOS boilerplate with Ethereum blockchain interaction
Swift
2
star
49

silkroadexplore-mobile-app

React Native mobile application for the silkroadexplore.com website
JavaScript
2
star
50

raiden-client-python

Raiden API python client 🐍
Python
2
star
51

mad-location-manager-landing

CSS
2
star
52

vue-mad-parallax

Simple parallax effects for elements
JavaScript
2
star
53

hardhat-mad-boiler

Ready-to-use preconfigured HardHat Ethereum development environment with additional tools for smart-contract development
TypeScript
2
star
54

madops

JavaScript
2
star
55

comedian-ui

UI for Comedian project
Vue
1
star
56

punisher

Telegram bot for interns program
Go
1
star
57

musicbot

telegram music bot
Go
1
star
58

paybox_api

Paybox API wrapper (version 4.0+)
Ruby
1
star
59

AVR_Testing

Src code for "MCU firmware testing" article
C
1
star
60

steven-signal-landing

TypeScript
1
star
61

Mad-Stand-Up

JavaScript
1
star
62

madflow

Mad Flow is an internal project for company's process automation
1
star
63

docker-cron-skeleton

Run cron jobs based on your scripts inside Docker
Dockerfile
1
star
64

publications

Mad Devs team members writeups
HTML
1
star
65

code-coverage-to-slack

1
star
66

react-code-samples

Examples of React code from our projects
JavaScript
1
star