kalebke / fsensor Goto Github PK
View Code? Open in Web Editor NEWAndroid Sensor Filter and Fusion
License: Apache License 2.0
Android Sensor Filter and Fusion
License: Apache License 2.0
Using both the Kalman and Complimentary filters, when the device is rotated through +/-180 degrees, instead of smoothly wrapping, the reported sensor readings "take the long way around", increasing from -180 to 180 (or vice-versa) causing the compass needle (or other visualization) to rapidly flip through all 360 degrees. Alternately, leaving the device oriented south causes the readings to waver very erratically, with occasional brief stabilization at 0 degrees.
Overall this has the effect of rendering a good 20 degree wedge of the compass unusable
Notably, this problem does not manifest at all with the pure gyroscope mode.
(Normally I would assume I've implemented something wrong but the problem manifests in the demo app as well)
I'm not very familiar with quaternions, but I would have expected this would be a problem using them would solve. Unless something weird is happening when the different sensor readings are combined?
i get compass / gyroscope data from sensor on my android app for google glass i have the rotation degree
but front and backdirection are inverted when marker is rotated
private void updateValues(float[] values) {
float value_0 = fusedOrientation[0];
float gyro_left_right_degree = (float) (Math.toDegrees(value_0) + 360) % 360;
}
https://i.stack.imgur.com/3u7TT.png
this is my code for creating a line from my lat/lng pos
public static GeoPoint movePoint(double latitude, double longitude, double distanceInMetres, double bearing) {
double brngRad = toRadians(bearing);
double latRad = toRadians(latitude);
double lonRad = toRadians(longitude);
int earthRadiusInMetres = 6371000;
double distFrac = distanceInMetres / earthRadiusInMetres;
double latitudeResult = asin(sin(latRad) * cos(distFrac) + cos(latRad) * sin(distFrac) * cos(brngRad));
double a = atan2(sin(brngRad) * sin(distFrac) * cos(latRad), cos(distFrac) - sin(latRad) * sin(latitudeResult));
double longitudeResult = (lonRad + a + 3 * PI) % (2 * PI) - PI;
//Log.i(TAG,"movePoint latitude: " + toDegrees(latitudeResult) + ", longitude: " + toDegrees(longitudeResult));
GeoPoint GeoPoint = new GeoPoint(toDegrees(latitudeResult), toDegrees(longitudeResult));
return GeoPoint;
}
Thanks
Dear KalebKE,
I have a question regarding the argument of getGravity().
LinearAcceleration.filter() receives "acceleration".
But getGravity(0 calls filter.filter() with this "acceleration".
public float[] getGravity(float[] values) {
return Util.getGravityFromOrientation(filter.filter(values));
}
I think the "filter" is orientationFusion and it gets "gyroscope" values, isn't it?
Please correct me if my understanding is wrong.
Thank you.
Finding your sensor fusion algorithm was a great relieve. Since I don't want to have my product dependent on gravity and/or linear sensor algorithms that are manufacturer or android version dependent.
It works very well and intuitive, I'm only experiencing one bug. After a day of debugging and also trying to understand what quaternions are (pfft ;)) I finally debugged where things are going wrong.
When the device is in a static face up position the accelero values are for example:
My phone is not totally flat but almost flat on a surface.
Now when I turn my phone upside down I get this:
So linx and liny are both reporting acceleration which clearly not exists but is caused by an error in the sum op.
The error is in the GetGravity() values since that should have been: -0.38, 2.02, -9.58, that is also what the standard TYPE_GRAVITY (built in) is reporting.
I guess it has something to do with this note of you:
"Assumes a positive, counter-clockwise, right-handed rotation" on top of the getGravityFromOrientation function.
I've been debugging and testing all day now, but I don't want to implement a hacky fix to support upside down positions of the sensors. I really would prefer to fix this the right way. Can you point me in the right direction on how to fix this? Than I can open a PR and fix it on the repo as well.
Hello,
Is it possible to build the FSensor? I've tried on the latest Android studio and looks like it's not:( I can't even add an app module with activity.
Are there like a guidelines or something?
I am using the latest version 2.1. At rest (phone is on table), the ComplementaryLinearAccelerationSensor always returns too large values.
For example :
x: 0.2, y: 13 z: 9
Code is very simple : https://github.com/pvvvgithub/test_ComplementaryLinearAccelerationSensor/tree/master/app/src/main/java/com/example/android/demo
Hi,
I try to use LinearAccelerationFusion to find linearAcceleration and after that try to remap acceleration in world coordinate.
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
System.arraycopy(event.values, 0, acceleration, 0, event.values.length);
hasAcceleration = true;
linearAcceleration = linearAccelerationFusion.filter(acceleration);
}
float[] deviceRelativeAcceleration = new float[4];
deviceRelativeAcceleration[0] = linearAcceleration[0];
deviceRelativeAcceleration[1] = linearAcceleration[1];
deviceRelativeAcceleration[2] = linearAcceleration[2];
deviceRelativeAcceleration[3] = 0;
float[] R = new float[16], I = new float[16], earthAcc = new float[16];
SensorManager.getRotationMatrix(R, I, linearAccelerationFusion.getGravity(), magnetic);
float[] inv = new float[16];
android.opengl.Matrix.invertM(inv, 0, R, 0);
android.opengl.Matrix.multiplyMV(earthAcc, 0, inv, 0, deviceRelativeAcceleration, 0);
float [] earthAccNorm = new float[3];
earthAccNorm[0] = earthAcc[0]/G_CONSTANT;
earthAccNorm[1] = earthAcc[1]/G_CONSTANT;
earthAccNorm[2] = earthAcc[2]/G_CONSTANT;
But the earthNorm takes strange values.
Hi.
I'm trying to use your OrientationKalmanFusion example,
but can't find the class "OrientationFusion" in the project.
private OrientationFusion orientationFusion;
then initialised as orientationFusion = new OrientationKalmanFusion();
i tried declaring it as "OrientationFused" and initialize it with KalmanFusion but the methods:
-setAcceleration
-setMagneticField
-filter
are missing still missing.
Plese help me with some clarification how are this implemented.
Can TiltCompensationUtil be used to get a stabilized compass heading no matter what is the current device orientation? How?
Something like this app does: https://play.google.com/store/apps/details?id=fi.finwe.gyrocompas
Hi, first of all, thanks for this amazing work.
I'm trying to install this library but without success so far. I'm getting a 403 Forbidden
error
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
> Could not resolve com.github.KalebKE:FSensor:v2.x.
Required by:
project :app
> Could not resolve com.github.KalebKE:FSensor:v2.x.
> Could not get resource 'http://dl.bintray.com/lukaville/maven/com/github/KalebKE/FSensor/v2.x/FSensor-v2.x.pom'.
> Could not GET 'http://dl.bintray.com/lukaville/maven/com/github/KalebKE/FSensor/v2.x/FSensor-v2.x.pom'. Received status code 403 from server: Forbidden
Hi,
I noticed that you created a code snippet to help on how to add the maven repository that hosts the library. It contains
maven {
maven { url "https://jitpack.io" }
}
and it should be pasted inside the project level build.gradle
file as you explained.
I guess that the maven block is duplicated and that the correct code snippet should be
maven {
url "https://jitpack.io"
}
If this proceeds, let me know if I can help more by sending a PR.
Thanks for the nice effort of putting up this code library and all the explanation regarding the filtering. Really nice work!
I've used your awesome sensor fusion to get device orientation around 3 axes. The problem is that the z-axis orientation has two values when the device is pointed towards the ground and the same situation when the device is pointed upward. The image can demonstrate the problem to be better understand.
As the figure shows, the absolute combination of two angles results in 180 degrees. I've used accelerometer and magnetometer to calculate orientation which gives me the correct z-axis independent of device hight angle.
rotationVectorAccelerationMagnetic
can occasionally be null, presumably due to SensorManager.getRotationMatrix()
returning false in getOrientationVectorFromAccelerationMagnetic()
This then causes a NPE in the subsequent line, rotationVectorAccelerationMagnetic.multiply((double)oneMinusAlpha);
relevant stack trace:
java.lang.NullPointerException: Attempt to invoke virtual method 'org.apache.commons.math3.complex.Quaternion org.apache.commons.math3.complex.Quaternion.multiply(double)' on a null object reference at com.kircherelectronics.fsensor.filter.gyroscope.fusion.complimentary.OrientationFusedComplimentary.calculateFusedOrientation(OrientationFusedComplimentary.java:122) at com.redacted.location.FSensorCompassKt$getFSCompassObservable$1$listener$1.onSensorChanged(FSensorCompass.kt:62)
I want to use orientation fusion but without use of the magnetic sensor, is that possible?
Hi, i really love your software! But i don't understand, how OrientationFused should be used now, since it was changed 2 months ago and the documentation still contains OrientationFusion.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.