From 93d0aed45ee352025775c69a957bc766dbda3630 Mon Sep 17 00:00:00 2001 From: KalebKE Date: Sun, 5 Apr 2020 18:00:26 -0600 Subject: [PATCH] v2.0 * Code clean up. --- .../fsensor/filter/averaging/MeanFilter.java | 2 +- .../fsensor/filter/averaging/MedianFilter.java | 2 +- .../gyroscope/fusion/kalman/OrientationFusedKalman.java | 8 ++++---- .../fusion/kalman/filter/RotationMeasurementModel.java | 2 +- .../fsensor/linearacceleration/LinearAcceleration.java | 5 ++--- .../fsensor/observer/SensorSubject.java | 2 +- .../fsensor/sensor/acceleration/AccelerationSensor.java | 6 +++--- .../ComplementaryLinearAccelerationSensor.java | 7 ++++--- .../acceleration/KalmanLinearAccelerationSensor.java | 7 ++++--- .../sensor/acceleration/LinearAccelerationSensor.java | 6 +++--- .../acceleration/LowPassLinearAccelerationSensor.java | 7 ++++--- .../sensor/gyroscope/ComplementaryGyroscopeSensor.java | 6 +++--- .../fsensor/sensor/gyroscope/GyroscopeSensor.java | 6 +++--- .../fsensor/sensor/gyroscope/KalmanGyroscopeSensor.java | 6 +++--- .../fsensor/util/gravity/GravityUtil.java | 3 --- .../kircherelectronics/fsensor/util/offset/FitPoints.java | 8 ++------ 16 files changed, 39 insertions(+), 44 deletions(-) diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MeanFilter.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MeanFilter.java index fd569ff..56d551d 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MeanFilter.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MeanFilter.java @@ -37,7 +37,7 @@ public class MeanFilter extends AveragingFilter { private static final String tag = MeanFilter.class.getSimpleName(); - private ArrayDeque values; + private final ArrayDeque values; private float[] output; /** diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MedianFilter.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MedianFilter.java index c7458b3..5d90a8f 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MedianFilter.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/MedianFilter.java @@ -42,7 +42,7 @@ public class MedianFilter extends AveragingFilter { private static final String tag = MedianFilter.class .getSimpleName(); - private ArrayDeque values; + private final ArrayDeque values; private float[] output; diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/OrientationFusedKalman.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/OrientationFusedKalman.java index 826498f..68412fc 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/OrientationFusedKalman.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/OrientationFusedKalman.java @@ -61,15 +61,15 @@ public class OrientationFusedKalman extends OrientationFused { private static final String TAG = OrientationFusedComplementary.class.getSimpleName(); - private RotationKalmanFilter kalmanFilter; - private AtomicBoolean run; + private final RotationKalmanFilter kalmanFilter; + private final AtomicBoolean run; private volatile float dT; private volatile float[] output = new float[3]; private Thread thread; private volatile Quaternion rotationVectorAccelerationMagnetic; - private double[] vectorGyroscope = new double[4]; - private double[] vectorAccelerationMagnetic = new double[4]; + private final double[] vectorGyroscope = new double[4]; + private final double[] vectorAccelerationMagnetic = new double[4]; public OrientationFusedKalman() { this(DEFAULT_TIME_CONSTANT); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/filter/RotationMeasurementModel.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/filter/RotationMeasurementModel.java index 9b013c7..fc8156d 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/filter/RotationMeasurementModel.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/kalman/filter/RotationMeasurementModel.java @@ -21,7 +21,7 @@ */ public class RotationMeasurementModel implements MeasurementModel { - private double noiseCoefficient = 0.001; + private final double noiseCoefficient = 0.001; /** * The measurement matrix, used to associate the measurement vector to the diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAcceleration.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAcceleration.java index fd32b19..e1e0e6a 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAcceleration.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAcceleration.java @@ -30,10 +30,9 @@ public abstract class LinearAcceleration { private static final String tag = LinearAcceleration.class.getSimpleName(); - private float[] output = new float[] - {0, 0, 0}; + private final float[] output = new float[]{0, 0, 0}; - protected BaseFilter filter; + protected final BaseFilter filter; public LinearAcceleration(BaseFilter filter) { this.filter = filter; diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/observer/SensorSubject.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/observer/SensorSubject.java index ec55a9b..13125b2 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/observer/SensorSubject.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/observer/SensorSubject.java @@ -4,7 +4,7 @@ import java.util.List; public class SensorSubject { - private List observers = new ArrayList<>(); + private final List observers = new ArrayList<>(); public interface SensorObserver { void onSensorChanged(float[] values); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/AccelerationSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/AccelerationSensor.java index 24066bf..7381950 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/AccelerationSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/AccelerationSensor.java @@ -28,8 +28,8 @@ public class AccelerationSensor implements FSensor { private static final String TAG = AccelerationSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -38,7 +38,7 @@ public class AccelerationSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public AccelerationSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/ComplementaryLinearAccelerationSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/ComplementaryLinearAccelerationSensor.java index bf89c35..a70331d 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/ComplementaryLinearAccelerationSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/ComplementaryLinearAccelerationSensor.java @@ -32,8 +32,8 @@ public class ComplementaryLinearAccelerationSensor implements FSensor { private static final String TAG = ComplementaryLinearAccelerationSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -49,7 +49,7 @@ public class ComplementaryLinearAccelerationSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; private int sensorType = Sensor.TYPE_GYROSCOPE; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public ComplementaryLinearAccelerationSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); @@ -127,6 +127,7 @@ public void reset() { stop(); magnetic = new float[3]; acceleration = new float[3]; + rawAcceleration = new float[3]; rotation = new float[3]; output = new float[4]; listener.reset(); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/KalmanLinearAccelerationSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/KalmanLinearAccelerationSensor.java index 18b29a2..8ba1f5a 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/KalmanLinearAccelerationSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/KalmanLinearAccelerationSensor.java @@ -32,8 +32,8 @@ public class KalmanLinearAccelerationSensor implements FSensor { private static final String TAG = KalmanLinearAccelerationSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -49,7 +49,7 @@ public class KalmanLinearAccelerationSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; private int sensorType = Sensor.TYPE_GYROSCOPE; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public KalmanLinearAccelerationSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); @@ -117,6 +117,7 @@ public void reset() { stop(); magnetic = new float[3]; acceleration = new float[3]; + rawAcceleration = new float[3]; rotation = new float[3]; output = new float[4]; listener.reset(); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LinearAccelerationSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LinearAccelerationSensor.java index 1a3794f..f33db0f 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LinearAccelerationSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LinearAccelerationSensor.java @@ -28,8 +28,8 @@ public class LinearAccelerationSensor implements FSensor { private static final String TAG = LinearAccelerationSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -38,7 +38,7 @@ public class LinearAccelerationSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public LinearAccelerationSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LowPassLinearAccelerationSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LowPassLinearAccelerationSensor.java index 554a4a4..472c504 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LowPassLinearAccelerationSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LowPassLinearAccelerationSensor.java @@ -31,8 +31,8 @@ public class LowPassLinearAccelerationSensor implements FSensor { private static final String TAG = LowPassLinearAccelerationSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -46,7 +46,7 @@ public class LowPassLinearAccelerationSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public LowPassLinearAccelerationSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); @@ -103,6 +103,7 @@ public void setFSensorLpfLinearAccelerationTimeConstant(float timeConstant) { public void reset() { stop(); acceleration = new float[3]; + rawAcceleration = new float[3]; output = new float[4]; start(); } diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/ComplementaryGyroscopeSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/ComplementaryGyroscopeSensor.java index bb6bcad..aa000fe 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/ComplementaryGyroscopeSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/ComplementaryGyroscopeSensor.java @@ -30,8 +30,8 @@ public class ComplementaryGyroscopeSensor implements FSensor { private static final String TAG = ComplementaryGyroscopeSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -45,7 +45,7 @@ public class ComplementaryGyroscopeSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; private int sensorType = Sensor.TYPE_GYROSCOPE; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public ComplementaryGyroscopeSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/GyroscopeSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/GyroscopeSensor.java index 4c466fd..7247a6d 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/GyroscopeSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/GyroscopeSensor.java @@ -31,8 +31,8 @@ public class GyroscopeSensor implements FSensor { private static final String TAG = GyroscopeSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -46,7 +46,7 @@ public class GyroscopeSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; private int sensorType = Sensor.TYPE_GYROSCOPE; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public GyroscopeSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/KalmanGyroscopeSensor.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/KalmanGyroscopeSensor.java index cd3952f..88c93d3 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/KalmanGyroscopeSensor.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/gyroscope/KalmanGyroscopeSensor.java @@ -30,8 +30,8 @@ public class KalmanGyroscopeSensor implements FSensor { private static final String TAG = KalmanGyroscopeSensor.class.getSimpleName(); - private SensorManager sensorManager; - private SimpleSensorListener listener; + private final SensorManager sensorManager; + private final SimpleSensorListener listener; private float startTime = 0; private int count = 0; @@ -45,7 +45,7 @@ public class KalmanGyroscopeSensor implements FSensor { private int sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; private int sensorType = Sensor.TYPE_GYROSCOPE; - private SensorSubject sensorSubject; + private final SensorSubject sensorSubject; public KalmanGyroscopeSensor(Context context) { this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/util/gravity/GravityUtil.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/util/gravity/GravityUtil.java index 98d2ead..38665dc 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/util/gravity/GravityUtil.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/util/gravity/GravityUtil.java @@ -1,9 +1,6 @@ package com.kircherelectronics.fsensor.util.gravity; import android.hardware.SensorManager; -import android.util.Log; - -import java.util.Arrays; /* * Copyright 2018, Kircher Electronics, LLC diff --git a/fsensor/src/main/java/com/kircherelectronics/fsensor/util/offset/FitPoints.java b/fsensor/src/main/java/com/kircherelectronics/fsensor/util/offset/FitPoints.java index ad511d1..8d0574c 100644 --- a/fsensor/src/main/java/com/kircherelectronics/fsensor/util/offset/FitPoints.java +++ b/fsensor/src/main/java/com/kircherelectronics/fsensor/util/offset/FitPoints.java @@ -162,9 +162,7 @@ private RealVector solveSystem(ArrayList points) { RealMatrix dtdi = solver.getInverse(); // v = (( d' * d )^-1) * ( d' * ones.mapAddToSelf(1)); - RealVector v = dtdi.operate(dtOnes); - - return v; + return dtdi.operate(dtOnes); } /** @@ -245,9 +243,7 @@ private RealMatrix translateToCenter(RealVector center, RealMatrix a) { t.setSubMatrix(centerMatrix.getData(), 3, 0); // Translate to the offset. - RealMatrix r = t.multiply(a).multiply(t.transpose()); - - return r; + return t.multiply(a).multiply(t.transpose()); } /**