// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/OrientationFused.java
// public abstract class OrientationFused extends BaseFilter {
// 
//     protected static final float EPSILON = 0.000000001f;
//     // Nano-second to second conversion
//     protected static final float NS2S = 1.0f / 1000000000.0f;
//     private static final String tag = OrientationFused.class.getSimpleName();
//     public static float DEFAULT_TIME_CONSTANT = 0.18f;
//     // The coefficient for the fusedOrientation... 0.5 = means it is averaging the two
//     // transfer functions (rotations from the gyroscope and
//     // acceleration/magnetic, respectively).
//     public float timeConstant;
//     protected Quaternion rotationVector;
//     protected long timestamp = 0;
//     protected float[] output = new float[3];
// 
//     /**
//      * Initialize a singleton instance.
//      */
//     public OrientationFused() {
//         this(DEFAULT_TIME_CONSTANT);
//     }
// 
//     public OrientationFused(float timeConstant) {
//         this.timeConstant = timeConstant;
// 
//     }
// 
//     @Override
//     public float[] getOutput() {
//         return output;
//     }
// 
//     public void reset() {
//         timestamp = 0;
//         rotationVector = null;
//     }
// 
//     public boolean isBaseOrientationSet() {
//         return rotationVector != null;
//     }
// 
//     /**
//      * The complementary fusedOrientation coefficient, a floating point value between 0-1,
//      * exclusive of 0, inclusive of 1.
//      *
//      * @param timeConstant
//      */
//     public void setTimeConstant(float timeConstant) {
//         this.timeConstant = timeConstant;
//     }
// 
//     /**
//      * Calculate the fused orientation of the device.
//      * @param gyroscope the gyroscope measurements.
//      * @param timestamp the gyroscope timestamp
//      * @param acceleration the acceleration measurements
//      * @param magnetic the magnetic measurements
//      * @return the fused orientation estimation.
//      */
//     public abstract float[] calculateFusedOrientation(float[] gyroscope, long timestamp, float[] acceleration, float[] magnetic);
// 
//     public void setBaseOrientation(Quaternion baseOrientation) {
//         rotationVector = baseOrientation;
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/util/gravity/GravityUtil.java
// public class GravityUtil {
// 
//     private static final String tag = GravityUtil.class.getSimpleName();
// 
//     private static float[] gravity = new float[]{SensorManager.GRAVITY_EARTH, SensorManager.GRAVITY_EARTH, SensorManager.GRAVITY_EARTH};
// 
//     /**
//      * Assumes a positive, counter-clockwise, right-handed rotation
//      * orientation[0] = pitch, rotation around the X axis.
//      * orientation[1] = roll, rotation around the Y axis
//      * orientation[2] = azimuth, rotation around the Z axis
//      * @param orientation The orientation.
//      * @return The gravity components of the orientation.
//      */
//     public static float[] getGravityFromOrientation(float[] orientation) {
// 
//         float[] components = new float[3];
// 
//         float pitch = orientation[1];
//         float roll = orientation[2];
// 
//         // Find the gravity component of the X-axis
//         // = g*-cos(pitch)*sin(roll);
//         components[0] = (float) -(gravity[0]
//                 * -Math.cos(pitch) * Math
//                 .sin(roll));
// 
//         // Find the gravity component of the Y-axis
//         // = g*-sin(pitch);
//         components[1] = (float) (gravity[1] * -Math
//                 .sin(pitch));
// 
//         // Find the gravity component of the Z-axis
//         // = g*cos(pitch)*cos(roll);
//         components[2] = (float) (gravity[2]
//                 * Math.cos(pitch) * Math.cos(roll));
// 
//         return components;
//     }
// 
//     /**
//      * Set the gravity as measured by the sensor. Defaults to SensorManager.GRAVITY_EARTH
//      * @param g the gravity of earth in units of m/s^2
//      */
//     public static void setGravity(float[] g) {
//         gravity = g;
//     }
// }


import com.kircherelectronics.fsensor.filter.gyroscope.fusion.OrientationFused;
import com.kircherelectronics.fsensor.util.gravity.GravityUtil;
package com.kircherelectronics.fsensor.linearacceleration;


/*
 * 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.
 */

/**
 * A wrapper for Linear Acceleration filters that are backed by sensor fusions.
 *
 * Created by kaleb on 7/6/17.
 */
public class LinearAccelerationFusion extends LinearAcceleration {

    public LinearAccelerationFusion(OrientationFused orientationFused) {
        super(orientationFused);
    }

    @Override
    public float[] getGravity() {
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/filter/gyroscope/fusion/OrientationFused.java
// public abstract class OrientationFused extends BaseFilter {
// 
//     protected static final float EPSILON = 0.000000001f;
//     // Nano-second to second conversion
//     protected static final float NS2S = 1.0f / 1000000000.0f;
//     private static final String tag = OrientationFused.class.getSimpleName();
//     public static float DEFAULT_TIME_CONSTANT = 0.18f;
//     // The coefficient for the fusedOrientation... 0.5 = means it is averaging the two
//     // transfer functions (rotations from the gyroscope and
//     // acceleration/magnetic, respectively).
//     public float timeConstant;
//     protected Quaternion rotationVector;
//     protected long timestamp = 0;
//     protected float[] output = new float[3];
// 
//     /**
//      * Initialize a singleton instance.
//      */
//     public OrientationFused() {
//         this(DEFAULT_TIME_CONSTANT);
//     }
// 
//     public OrientationFused(float timeConstant) {
//         this.timeConstant = timeConstant;
// 
//     }
// 
//     @Override
//     public float[] getOutput() {
//         return output;
//     }
// 
//     public void reset() {
//         timestamp = 0;
//         rotationVector = null;
//     }
// 
//     public boolean isBaseOrientationSet() {
//         return rotationVector != null;
//     }
// 
//     /**
//      * The complementary fusedOrientation coefficient, a floating point value between 0-1,
//      * exclusive of 0, inclusive of 1.
//      *
//      * @param timeConstant
//      */
//     public void setTimeConstant(float timeConstant) {
//         this.timeConstant = timeConstant;
//     }
// 
//     /**
//      * Calculate the fused orientation of the device.
//      * @param gyroscope the gyroscope measurements.
//      * @param timestamp the gyroscope timestamp
//      * @param acceleration the acceleration measurements
//      * @param magnetic the magnetic measurements
//      * @return the fused orientation estimation.
//      */
//     public abstract float[] calculateFusedOrientation(float[] gyroscope, long timestamp, float[] acceleration, float[] magnetic);
// 
//     public void setBaseOrientation(Quaternion baseOrientation) {
//         rotationVector = baseOrientation;
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/util/gravity/GravityUtil.java
// public class GravityUtil {
// 
//     private static final String tag = GravityUtil.class.getSimpleName();
// 
//     private static float[] gravity = new float[]{SensorManager.GRAVITY_EARTH, SensorManager.GRAVITY_EARTH, SensorManager.GRAVITY_EARTH};
// 
//     /**
//      * Assumes a positive, counter-clockwise, right-handed rotation
//      * orientation[0] = pitch, rotation around the X axis.
//      * orientation[1] = roll, rotation around the Y axis
//      * orientation[2] = azimuth, rotation around the Z axis
//      * @param orientation The orientation.
//      * @return The gravity components of the orientation.
//      */
//     public static float[] getGravityFromOrientation(float[] orientation) {
// 
//         float[] components = new float[3];
// 
//         float pitch = orientation[1];
//         float roll = orientation[2];
// 
//         // Find the gravity component of the X-axis
//         // = g*-cos(pitch)*sin(roll);
//         components[0] = (float) -(gravity[0]
//                 * -Math.cos(pitch) * Math
//                 .sin(roll));
// 
//         // Find the gravity component of the Y-axis
//         // = g*-sin(pitch);
//         components[1] = (float) (gravity[1] * -Math
//                 .sin(pitch));
// 
//         // Find the gravity component of the Z-axis
//         // = g*cos(pitch)*cos(roll);
//         components[2] = (float) (gravity[2]
//                 * Math.cos(pitch) * Math.cos(roll));
// 
//         return components;
//     }
// 
//     /**
//      * Set the gravity as measured by the sensor. Defaults to SensorManager.GRAVITY_EARTH
//      * @param g the gravity of earth in units of m/s^2
//      */
//     public static void setGravity(float[] g) {
//         gravity = g;
//     }
// }


// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAccelerationFusion.java
import com.kircherelectronics.fsensor.filter.gyroscope.fusion.OrientationFused;
import com.kircherelectronics.fsensor.util.gravity.GravityUtil;

package com.kircherelectronics.fsensor.linearacceleration;


/*
 * 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.
 */

/**
 * A wrapper for Linear Acceleration filters that are backed by sensor fusions.
 *
 * Created by kaleb on 7/6/17.
 */
public class LinearAccelerationFusion extends LinearAcceleration {

    public LinearAccelerationFusion(OrientationFused orientationFused) {
        super(orientationFused);
    }

    @Override
    public float[] getGravity() {
        return GravityUtil.getGravityFromOrientation(filter.getOutput());