Skip to content

Commit efa542c

Browse files
authored
Merge pull request #26 from KalebKE/v1.2.1
V1.2.1
2 parents 6fab7eb + 37e381c commit efa542c

36 files changed

+1756
-315
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
9+
classpath 'com.android.tools.build:gradle:3.2.1'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1111
}
1212
}

fsensor/build.gradle

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ apply plugin: 'com.github.dcendents.android-maven'
44
group='com.github.KalebKE'
55

66
android {
7-
compileSdkVersion 26
8-
buildToolsVersion '26.0.2'
7+
compileSdkVersion 28
8+
buildToolsVersion '28.0.3'
99

1010
lintOptions {
1111
abortOnError false
1212
}
1313

1414
defaultConfig {
1515
minSdkVersion 14
16-
targetSdkVersion 26
17-
versionCode 5
18-
versionName "1.1.5"
16+
targetSdkVersion 28
17+
versionCode 6
18+
versionName "1.2.1"
1919

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

@@ -29,11 +29,16 @@ android {
2929
}
3030

3131
dependencies {
32-
compile fileTree(dir: 'libs', include: ['*.jar'])
33-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
32+
implementation fileTree(dir: 'libs', include: ['*.jar'])
33+
implementation 'com.android.support:support-annotations:28.0.0'
34+
35+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
3436
exclude group: 'com.android.support', module: 'support-annotations'
3537
})
36-
testCompile 'junit:junit:4.12'
38+
testImplementation 'junit:junit:4.12'
39+
40+
api files('libs/commons-math3-3.6.1.jar')
3741

38-
compile files('libs/commons-math3-3.6.1.jar')
42+
api 'io.reactivex.rxjava2:rxandroid:2.1.0'
43+
api 'io.reactivex.rxjava2:rxjava:2.x.x'
3944
}

fsensor/src/main/java/com/kircherelectronics/fsensor/BaseFilter.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
package com.kircherelectronics.fsensor;
22

3+
/*
4+
* Copyright 2018, Kircher Electronics, LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
319
/**
420
* Created by kaleb on 4/1/18.
521
*/

fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/AveragingFilter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.kircherelectronics.fsensor.filter.averaging;
22

33
/*
4-
* Copyright 2017, Kircher Electronics, LLC
4+
* Copyright 2018, Kircher Electronics, LLC
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
99
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
10+
* http://www.apache.org/licenses/LICENSE-2.0
1111
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -46,4 +46,6 @@ public void reset() {
4646
timestamp = 0;
4747
count = 0;
4848
}
49+
50+
public abstract float[] filter(float[] data);
4951
}

fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/LowPassFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.kircherelectronics.fsensor.filter.averaging;
22

33
/*
4-
* Copyright 2017, Kircher Electronics, LLC
4+
* Copyright 2018, Kircher Electronics, LLC
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MeanFilter.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.Arrays;
55

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

84-
output = getMean(values);
84+
if(!values.isEmpty()) {
85+
output = getMean(values);
86+
} else {
87+
output = new float[data.length];
88+
System.arraycopy(data, 0, output, 0, data.length);
89+
}
8590

8691
return output;
8792
}
@@ -98,7 +103,7 @@ public float[] getOutput() {
98103
* @return the mean of the data set.
99104
*/
100105
private float[] getMean(ArrayDeque<float[]> data) {
101-
float[] mean = new float[3];
106+
float[] mean = new float[data.getFirst().length];
102107

103108
for (float[] axis : data) {
104109
for (int i = 0; i < axis.length; i++) {

fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MedianFilter.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Arrays;
77

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

92-
output = getMean(values);
92+
if(!values.isEmpty()) {
93+
output = getMean(values);
94+
} else {
95+
output = new float[data.length];
96+
System.arraycopy(data, 0, output, 0, data.length);
97+
}
9398

9499
return output;
95100
}
@@ -106,9 +111,9 @@ public float[] getOutput() {
106111
* @return the mean of the data set.
107112
*/
108113
private float[] getMean(ArrayDeque<float[]> data) {
109-
float[] mean = new float[3];
114+
float[] mean = new float[data.getFirst().length];
110115

111-
double[][] values = new double[3][data.size()];
116+
double[][] values = new double[data.getFirst().length][data.size()];
112117
int index = 0;
113118

114119
for (float[] axis : data) {

fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/OrientationGyroscope.java

+29-25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.kircherelectronics.fsensor.filter.gyroscope;
22

3-
import android.hardware.SensorManager;
3+
import android.util.Log;
44

55
import com.kircherelectronics.fsensor.BaseFilter;
66
import com.kircherelectronics.fsensor.util.rotation.RotationUtil;
77

88
import org.apache.commons.math3.complex.Quaternion;
9+
import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
10+
import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
11+
import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;
12+
13+
import java.util.Arrays;
914

1015
/*
11-
* Copyright 2017, Kircher Electronics, LLC
16+
* Copyright 2018, Kircher Electronics, LLC
1217
*
1318
* Licensed under the Apache License, Version 2.0 (the "License");
1419
* you may not use this file except in compliance with the License.
@@ -79,7 +84,7 @@
7984
*/
8085
public class OrientationGyroscope extends BaseFilter {
8186

82-
private static final String tag = OrientationGyroscope.class.getSimpleName();
87+
private static final String TAG = OrientationGyroscope.class.getSimpleName();
8388
private static final float NS2S = 1.0f / 1000000000.0f;
8489
private static final float EPSILON = 0.000000001f;
8590
private Quaternion rotationVectorGyroscope;
@@ -105,34 +110,23 @@ public float[] getOutput() {
105110
* @return An orientation vector -> @link SensorManager#getOrientation(float[], float[])}
106111
*/
107112
public float[] calculateOrientation(float[] gyroscope, long timestamp) {
108-
109-
if (rotationVectorGyroscope != null) {
113+
if (isBaseOrientationSet()) {
110114

111115
if (this.timestamp != 0) {
112116
final float dT = (timestamp - this.timestamp) * NS2S;
113117
rotationVectorGyroscope = RotationUtil.integrateGyroscopeRotation(rotationVectorGyroscope, gyroscope, dT, EPSILON);
114-
}
115-
116-
this.timestamp = timestamp;
117-
118-
// Now we get a structure we can pass to get a rotation matrix, and then
119-
// an orientation vector from Android.
120-
121-
float[] fusedVector = new float[4];
122-
123-
fusedVector[0] = (float) rotationVectorGyroscope.getVectorPart()[0];
124-
fusedVector[1] = (float) rotationVectorGyroscope.getVectorPart()[1];
125-
fusedVector[2] = (float) rotationVectorGyroscope.getVectorPart()[2];
126-
fusedVector[3] = (float) rotationVectorGyroscope.getScalarPart();
127118

128-
// rotation matrix from gyro data
129-
float[] fusedMatrix = new float[9];
119+
Rotation rotation = new Rotation(rotationVectorGyroscope.getQ0(), rotationVectorGyroscope.getQ1(), rotationVectorGyroscope.getQ2(),
120+
rotationVectorGyroscope.getQ3(), true);
130121

131-
// We need a rotation matrix so we can get the orientation vector
132-
SensorManager.getRotationMatrixFromVector(fusedMatrix, fusedVector);
122+
try {
123+
output = doubleToFloat(rotation.getAngles(RotationOrder.XYZ, RotationConvention.VECTOR_OPERATOR));
124+
} catch(Exception e) {
125+
Log.d(TAG, "", e);
126+
}
127+
}
133128

134-
// Get the OrientationFused
135-
SensorManager.getOrientation(fusedMatrix, output);
129+
this.timestamp = timestamp;
136130

137131
return output;
138132
} else {
@@ -160,6 +154,16 @@ public void reset() {
160154
}
161155

162156
public boolean isBaseOrientationSet() {
163-
return !(rotationVectorGyroscope == null);
157+
return rotationVectorGyroscope != null;
158+
}
159+
160+
private static float[] doubleToFloat(double[] values) {
161+
float[] f = new float[values.length];
162+
163+
for(int i = 0; i < f.length; i++){
164+
f[i] = (float) values[i];
165+
}
166+
167+
return f;
164168
}
165169
}

fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/OrientationFused.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.apache.commons.math3.complex.Quaternion;
66

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

6565
public boolean isBaseOrientationSet() {
66-
return !(rotationVectorGyroscope == null);
66+
return rotationVectorGyroscope != null;
6767
}
6868

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

89-
/**
90-
* Calculate the fused orientation of the device.
91-
* @param gyroscope the gyroscope measurements.
92-
* @param timestamp the gyroscope timestamp
93-
* @param orientation an estimation of device orientation.
94-
* @return the fused orientation estimation.
95-
*/
96-
public abstract float[] calculateFusedOrientation(float[] gyroscope, long timestamp, float[] orientation);
97-
9889
public void setBaseOrientation(Quaternion baseOrientation) {
9990
rotationVectorGyroscope = baseOrientation;
10091
}

0 commit comments

Comments
 (0)