Skip to content

Create Android device like orientation sensor by fusing together noisy magnetometer and accelerometer data.

Notifications You must be signed in to change notification settings

k3ru-sailco/sensor-fusion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sensor-fusion

Create a virtual orientation event by fusing gravity and magnetometer sensor data together. This is a port of the respective methods from the Android Device SensorManager to Go for use with spoofed or synthetic events.

This replicates how an android device typically gets its 3 orientation angles.

The downside to the use of this method is that the orientation events are not as exact as combined sensor would be due to the fact that the magnetometer and gravity sensor are inherently noisey/inaccurate.

More information regarding this topic can be found on a blog post made by Paul Lawitzki on Android sensor fusion, and applying a complimentrary filter to reduce or eradicate gyroscope drift and the aforementioned magnetometer and gravity drift. This post also served as a great reference while porting similar methods to Go.

Usage

    package main

    import "log"

    var (
	/*
		MAG and GRAV are each an individual
		slice of values representing a magnetometer and
		accelerometer event respectively.
	*/
	MAGNETOMETER_EVENT = []float64{}
	GRAVITY_EVENT      = []float64{}
    )

    func Example() {
	rotationMatrix := make([]float64, 9)
	inclinationMatrix := make([]float64, 9)
	if getRotationMatrix(rotationMatrix, inclinationMatrix, GRAVITY_EVENT, MAGNETOMETER_EVENT) {
		orientation := getOrientation(rotationMatrix)
		log.Println(orientation)
	}
    }

About

Create Android device like orientation sensor by fusing together noisy magnetometer and accelerometer data.

Topics

Resources

Stars

Watchers

Forks

Languages