Skip to content

Commit

Permalink
Merge pull request #26 from KalebKE/v1.2.1
Browse files Browse the repository at this point in the history
V1.2.1
  • Loading branch information
KalebKE authored Nov 4, 2018
2 parents 6fab7eb + 37e381c commit efa542c
Show file tree
Hide file tree
Showing 36 changed files with 1,756 additions and 315 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Expand Down
23 changes: 14 additions & 9 deletions fsensor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.KalebKE'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileSdkVersion 28
buildToolsVersion '28.0.3'

lintOptions {
abortOnError false
}

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 5
versionName "1.1.5"
targetSdkVersion 28
versionCode 6
versionName "1.2.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -29,11 +29,16 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:28.0.0'

androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'

api files('libs/commons-math3-3.6.1.jar')

compile files('libs/commons-math3-3.6.1.jar')
api 'io.reactivex.rxjava2:rxandroid:2.1.0'
api 'io.reactivex.rxjava2:rxjava:2.x.x'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package com.kircherelectronics.fsensor;

/*
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Created by kaleb on 4/1/18.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.kircherelectronics.fsensor.filter.averaging;

/*
* Copyright 2017, Kircher Electronics, LLC
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -46,4 +46,6 @@ public void reset() {
timestamp = 0;
count = 0;
}

public abstract float[] filter(float[] data);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kircherelectronics.fsensor.filter.averaging;

/*
* Copyright 2017, Kircher Electronics, LLC
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Arrays;

/*
* Copyright 2017, Kircher Electronics, LLC
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -81,7 +81,12 @@ public float[] filter(float[] data) {
values.removeFirst();
}

output = getMean(values);
if(!values.isEmpty()) {
output = getMean(values);
} else {
output = new float[data.length];
System.arraycopy(data, 0, output, 0, data.length);
}

return output;
}
Expand All @@ -98,7 +103,7 @@ public float[] getOutput() {
* @return the mean of the data set.
*/
private float[] getMean(ArrayDeque<float[]> data) {
float[] mean = new float[3];
float[] mean = new float[data.getFirst().length];

for (float[] axis : data) {
for (int i = 0; i < axis.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Arrays;

/*
* Copyright 2017, Kircher Electronics, LLC
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -89,7 +89,12 @@ public float[] filter(float[] data) {
values.removeFirst();
}

output = getMean(values);
if(!values.isEmpty()) {
output = getMean(values);
} else {
output = new float[data.length];
System.arraycopy(data, 0, output, 0, data.length);
}

return output;
}
Expand All @@ -106,9 +111,9 @@ public float[] getOutput() {
* @return the mean of the data set.
*/
private float[] getMean(ArrayDeque<float[]> data) {
float[] mean = new float[3];
float[] mean = new float[data.getFirst().length];

double[][] values = new double[3][data.size()];
double[][] values = new double[data.getFirst().length][data.size()];
int index = 0;

for (float[] axis : data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.kircherelectronics.fsensor.filter.gyroscope;

import android.hardware.SensorManager;
import android.util.Log;

import com.kircherelectronics.fsensor.BaseFilter;
import com.kircherelectronics.fsensor.util.rotation.RotationUtil;

import org.apache.commons.math3.complex.Quaternion;
import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;

import java.util.Arrays;

/*
* Copyright 2017, Kircher Electronics, LLC
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,7 +84,7 @@
*/
public class OrientationGyroscope extends BaseFilter {

private static final String tag = OrientationGyroscope.class.getSimpleName();
private static final String TAG = OrientationGyroscope.class.getSimpleName();
private static final float NS2S = 1.0f / 1000000000.0f;
private static final float EPSILON = 0.000000001f;
private Quaternion rotationVectorGyroscope;
Expand All @@ -105,34 +110,23 @@ public float[] getOutput() {
* @return An orientation vector -> @link SensorManager#getOrientation(float[], float[])}
*/
public float[] calculateOrientation(float[] gyroscope, long timestamp) {

if (rotationVectorGyroscope != null) {
if (isBaseOrientationSet()) {

if (this.timestamp != 0) {
final float dT = (timestamp - this.timestamp) * NS2S;
rotationVectorGyroscope = RotationUtil.integrateGyroscopeRotation(rotationVectorGyroscope, gyroscope, dT, EPSILON);
}

this.timestamp = timestamp;

// Now we get a structure we can pass to get a rotation matrix, and then
// an orientation vector from Android.

float[] fusedVector = new float[4];

fusedVector[0] = (float) rotationVectorGyroscope.getVectorPart()[0];
fusedVector[1] = (float) rotationVectorGyroscope.getVectorPart()[1];
fusedVector[2] = (float) rotationVectorGyroscope.getVectorPart()[2];
fusedVector[3] = (float) rotationVectorGyroscope.getScalarPart();

// rotation matrix from gyro data
float[] fusedMatrix = new float[9];
Rotation rotation = new Rotation(rotationVectorGyroscope.getQ0(), rotationVectorGyroscope.getQ1(), rotationVectorGyroscope.getQ2(),
rotationVectorGyroscope.getQ3(), true);

// We need a rotation matrix so we can get the orientation vector
SensorManager.getRotationMatrixFromVector(fusedMatrix, fusedVector);
try {
output = doubleToFloat(rotation.getAngles(RotationOrder.XYZ, RotationConvention.VECTOR_OPERATOR));
} catch(Exception e) {
Log.d(TAG, "", e);
}
}

// Get the OrientationFused
SensorManager.getOrientation(fusedMatrix, output);
this.timestamp = timestamp;

return output;
} else {
Expand Down Expand Up @@ -160,6 +154,16 @@ public void reset() {
}

public boolean isBaseOrientationSet() {
return !(rotationVectorGyroscope == null);
return rotationVectorGyroscope != null;
}

private static float[] doubleToFloat(double[] values) {
float[] f = new float[values.length];

for(int i = 0; i < f.length; i++){
f[i] = (float) values[i];
}

return f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.apache.commons.math3.complex.Quaternion;

/*
* Copyright 2017, Kircher Electronics, LLC
* Copyright 2018, Kircher Electronics, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,7 +63,7 @@ public void reset() {
}

public boolean isBaseOrientationSet() {
return !(rotationVectorGyroscope == null);
return rotationVectorGyroscope != null;
}

/**
Expand All @@ -86,15 +86,6 @@ public void setTimeConstant(float timeConstant) {
*/
public abstract float[] calculateFusedOrientation(float[] gyroscope, long timestamp, float[] acceleration, float[] magnetic);

/**
* Calculate the fused orientation of the device.
* @param gyroscope the gyroscope measurements.
* @param timestamp the gyroscope timestamp
* @param orientation an estimation of device orientation.
* @return the fused orientation estimation.
*/
public abstract float[] calculateFusedOrientation(float[] gyroscope, long timestamp, float[] orientation);

public void setBaseOrientation(Quaternion baseOrientation) {
rotationVectorGyroscope = baseOrientation;
}
Expand Down
Loading

0 comments on commit efa542c

Please sign in to comment.