Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
* Code clean up.
  • Loading branch information
KalebKE committed Apr 6, 2020
1 parent b052943 commit 93d0aed
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MeanFilter extends AveragingFilter {

private static final String tag = MeanFilter.class.getSimpleName();

private ArrayDeque<float[]> values;
private final ArrayDeque<float[]> values;
private float[] output;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MedianFilter extends AveragingFilter {
private static final String tag = MedianFilter.class
.getSimpleName();

private ArrayDeque<float[]> values;
private final ArrayDeque<float[]> values;
private float[] output;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

public class SensorSubject {
private List<SensorObserver> observers = new ArrayList<>();
private final List<SensorObserver> observers = new ArrayList<>();

public interface SensorObserver {
void onSensorChanged(float[] values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ private RealVector solveSystem(ArrayList<ThreeSpacePoint> points) {
RealMatrix dtdi = solver.getInverse();

// v = (( d' * d )^-1) * ( d' * ones.mapAddToSelf(1));
RealVector v = dtdi.operate(dtOnes);

return v;
return dtdi.operate(dtOnes);
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 93d0aed

Please sign in to comment.