Improved a few names
This commit is contained in:
@@ -24,9 +24,9 @@ public class AccelerometerCompassProvider extends OrientationProvider {
|
||||
final private float[] accelerometerValues = new float[3];
|
||||
|
||||
/**
|
||||
* Temporary variable to save allocations
|
||||
* Inclination values
|
||||
*/
|
||||
final float[] tmpFloat = new float[16];
|
||||
final float[] inclinationValues = new float[16];
|
||||
|
||||
/**
|
||||
* Initialises a new AccelerometerCompassProvider
|
||||
@@ -54,7 +54,7 @@ public class AccelerometerCompassProvider extends OrientationProvider {
|
||||
|
||||
if (magnitudeValues != null && accelerometerValues != null) {
|
||||
// Fuse accelerometer with compass
|
||||
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, tmpFloat, accelerometerValues,
|
||||
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
|
||||
magnitudeValues);
|
||||
// Transform rotation matrix to quaternion
|
||||
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class CalibratedGyroscopeProvider extends OrientationProvider {
|
||||
/**
|
||||
* Temporary variable to save allocations.
|
||||
*/
|
||||
private Quaternion correctedQuat = new Quaternion();
|
||||
private Quaternion correctedQuaternion = new Quaternion();
|
||||
|
||||
/**
|
||||
* Initialises a new CalibratedGyroscopeProvider
|
||||
@@ -78,7 +78,7 @@ public class CalibratedGyroscopeProvider extends OrientationProvider {
|
||||
// that we received the proper event
|
||||
if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
|
||||
|
||||
// This timestep's delta rotation to be multiplied by the current rotation
|
||||
// This timestamps delta rotation to be multiplied by the current rotation
|
||||
// after computing it from the gyro sample data.
|
||||
if (timestamp != 0) {
|
||||
final float dT = (event.timestamp - timestamp) * NS2S;
|
||||
@@ -110,20 +110,20 @@ public class CalibratedGyroscopeProvider extends OrientationProvider {
|
||||
deltaQuaternion.setW(-(float) cosThetaOverTwo);
|
||||
|
||||
// Matrix rendering in CubeRenderer does not seem to have this problem.
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
// Move current gyro orientation if gyroscope should be used
|
||||
deltaQuaternion.multiplyByQuat(currentOrientationQuaternion, currentOrientationQuaternion);
|
||||
}
|
||||
|
||||
correctedQuat.set(currentOrientationQuaternion);
|
||||
correctedQuaternion.set(currentOrientationQuaternion);
|
||||
// We inverted w in the deltaQuaternion, because currentOrientationQuaternion required it.
|
||||
// Before converting it back to matrix representation, we need to revert this process
|
||||
correctedQuat.w(-correctedQuat.w());
|
||||
correctedQuaternion.w(-correctedQuaternion.w());
|
||||
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
// Set the rotation matrix as well to have both representations
|
||||
SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix.matrix,
|
||||
correctedQuat.array());
|
||||
correctedQuaternion.array());
|
||||
}
|
||||
}
|
||||
timestamp = event.timestamp;
|
||||
|
||||
@@ -24,9 +24,9 @@ public class GravityCompassProvider extends OrientationProvider {
|
||||
final private float[] gravityValues = new float[3];
|
||||
|
||||
/**
|
||||
* Temporary variable to save some allocations
|
||||
* Inclination values
|
||||
*/
|
||||
float[] tmpFloat = new float[16];
|
||||
float[] inclinationValues = new float[16];
|
||||
|
||||
/**
|
||||
* Initialises a new GravityCompassProvider
|
||||
@@ -54,7 +54,7 @@ public class GravityCompassProvider extends OrientationProvider {
|
||||
|
||||
if (magnitudeValues != null && gravityValues != null) {
|
||||
// Fuse gravity-sensor (virtual sensor) with compass
|
||||
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, tmpFloat, gravityValues, magnitudeValues);
|
||||
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, gravityValues, magnitudeValues);
|
||||
// Transform rotation matrix to quaternion
|
||||
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ public class ImprovedOrientationSensor1Provider extends OrientationProvider {
|
||||
/**
|
||||
* Some temporary variables to save allocations
|
||||
*/
|
||||
final private float[] tmpFloat = new float[4];
|
||||
final private float[] temporaryQuaternion = new float[4];
|
||||
final private Quaternion correctedQuaternion = new Quaternion();
|
||||
final private Quaternion interpolateQuaternion = new Quaternion();
|
||||
final private Quaternion interpolatedQuaternion = new Quaternion();
|
||||
|
||||
/**
|
||||
* Initialises a new ImprovedOrientationSensor1Provider
|
||||
@@ -152,10 +152,10 @@ public class ImprovedOrientationSensor1Provider extends OrientationProvider {
|
||||
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
|
||||
// Process rotation vector (just safe it)
|
||||
// Calculate angle. Starting with API_18, Android will provide this value as event.values[3], but if not, we have to calculate it manually.
|
||||
SensorManager.getQuaternionFromVector(tmpFloat, event.values);
|
||||
SensorManager.getQuaternionFromVector(temporaryQuaternion, event.values);
|
||||
|
||||
// Store in quaternion
|
||||
quaternionRotationVector.setXYZW(tmpFloat[1], tmpFloat[2], tmpFloat[3], -tmpFloat[0]);
|
||||
quaternionRotationVector.setXYZW(temporaryQuaternion[1], temporaryQuaternion[2], temporaryQuaternion[3], -temporaryQuaternion[0]);
|
||||
if (!positionInitialised) {
|
||||
// Override
|
||||
quaternionGyroscope.set(quaternionRotationVector);
|
||||
@@ -218,12 +218,12 @@ public class ImprovedOrientationSensor1Provider extends OrientationProvider {
|
||||
|
||||
// Interpolate with a fixed weight between the two absolute quaternions obtained from gyro and rotation vector sensors
|
||||
// The weight should be quite low, so the rotation vector corrects the gyro only slowly, and the output keeps responsive.
|
||||
quaternionGyroscope.slerp(quaternionRotationVector, interpolateQuaternion, DIRECT_INTERPOLATION_WEIGHT);
|
||||
quaternionGyroscope.slerp(quaternionRotationVector, interpolatedQuaternion, DIRECT_INTERPOLATION_WEIGHT);
|
||||
|
||||
// Use the interpolated value between gyro and rotationVector
|
||||
setOrientationQuaternionAndMatrix(interpolateQuaternion);
|
||||
setOrientationQuaternionAndMatrix(interpolatedQuaternion);
|
||||
// Override current gyroscope-orientation
|
||||
quaternionGyroscope.copyVec4(interpolateQuaternion);
|
||||
quaternionGyroscope.copyVec4(interpolatedQuaternion);
|
||||
|
||||
// Reset the panic counter because both sensors are saying the same again
|
||||
panicCounter = 0;
|
||||
@@ -266,7 +266,7 @@ public class ImprovedOrientationSensor1Provider extends OrientationProvider {
|
||||
// Before converting it back to matrix representation, we need to revert this process
|
||||
correctedQuaternion.w(-correctedQuaternion.w());
|
||||
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
// Use gyro only
|
||||
currentOrientationQuaternion.copyVec4(quaternion);
|
||||
|
||||
|
||||
@@ -129,9 +129,9 @@ public class ImprovedOrientationSensor2Provider extends OrientationProvider {
|
||||
/**
|
||||
* Some temporary variable to save allocations.
|
||||
*/
|
||||
final private float[] temporaryQuaternion = new float[4];
|
||||
final private Quaternion correctedQuaternion = new Quaternion();
|
||||
final private Quaternion interpolateQuaternion = new Quaternion();
|
||||
final private float[] tmpFloat = new float[4];
|
||||
final private Quaternion interpolatedQuaternion = new Quaternion();
|
||||
|
||||
/**
|
||||
* Initialises a new ImprovedOrientationSensor2Provider
|
||||
@@ -152,10 +152,10 @@ public class ImprovedOrientationSensor2Provider extends OrientationProvider {
|
||||
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
|
||||
// Process rotation vector (just safe it)
|
||||
// Calculate angle. Starting with API_18, Android will provide this value as event.values[3], but if not, we have to calculate it manually.
|
||||
SensorManager.getQuaternionFromVector(tmpFloat, event.values);
|
||||
SensorManager.getQuaternionFromVector(temporaryQuaternion, event.values);
|
||||
|
||||
// Store in quaternion
|
||||
quaternionRotationVector.setXYZW(tmpFloat[1], tmpFloat[2], tmpFloat[3], -tmpFloat[0]);
|
||||
quaternionRotationVector.setXYZW(temporaryQuaternion[1], temporaryQuaternion[2], temporaryQuaternion[3], -temporaryQuaternion[0]);
|
||||
if (!positionInitialised) {
|
||||
// Override
|
||||
quaternionGyroscope.set(quaternionRotationVector);
|
||||
@@ -218,13 +218,13 @@ public class ImprovedOrientationSensor2Provider extends OrientationProvider {
|
||||
|
||||
// Interpolate with a fixed weight between the two absolute quaternions obtained from gyro and rotation vector sensors
|
||||
// The weight should be quite low, so the rotation vector corrects the gyro only slowly, and the output keeps responsive.
|
||||
quaternionGyroscope.slerp(quaternionRotationVector, interpolateQuaternion,
|
||||
quaternionGyroscope.slerp(quaternionRotationVector, interpolatedQuaternion,
|
||||
(float) (INDIRECT_INTERPOLATION_WEIGHT * gyroscopeRotationVelocity));
|
||||
|
||||
// Use the interpolated value between gyro and rotationVector
|
||||
setOrientationQuaternionAndMatrix(interpolateQuaternion);
|
||||
setOrientationQuaternionAndMatrix(interpolatedQuaternion);
|
||||
// Override current gyroscope-orientation
|
||||
quaternionGyroscope.copyVec4(interpolateQuaternion);
|
||||
quaternionGyroscope.copyVec4(interpolatedQuaternion);
|
||||
|
||||
// Reset the panic counter because both sensors are saying the same again
|
||||
panicCounter = 0;
|
||||
@@ -267,7 +267,7 @@ public class ImprovedOrientationSensor2Provider extends OrientationProvider {
|
||||
// Before converting it back to matrix representation, we need to revert this process
|
||||
correctedQuaternion.w(-correctedQuaternion.w());
|
||||
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
// Use gyro only
|
||||
currentOrientationQuaternion.copyVec4(quaternion);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class OrientationProvider implements SensorEventListener {
|
||||
* Sync-token for syncing read/write to sensor-data from sensor manager and
|
||||
* fusion algorithm
|
||||
*/
|
||||
protected final Object syncToken = new Object();
|
||||
protected final Object synchronizationToken = new Object();
|
||||
|
||||
/**
|
||||
* The list of sensors used by this provider
|
||||
@@ -99,7 +99,7 @@ public abstract class OrientationProvider implements SensorEventListener {
|
||||
* Get the current rotation of the device in the rotation matrix format (4x4 matrix)
|
||||
*/
|
||||
public void getRotationMatrix(MatrixF4x4 matrix) {
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
matrix.set(currentOrientationRotationMatrix);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public abstract class OrientationProvider implements SensorEventListener {
|
||||
* Get the current rotation of the device in the quaternion format (vector4f)
|
||||
*/
|
||||
public void getQuaternion(Quaternion quaternion) {
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
quaternion.set(currentOrientationQuaternion);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public abstract class OrientationProvider implements SensorEventListener {
|
||||
* Get the current rotation of the device in the Euler angles
|
||||
*/
|
||||
public void getEulerAngles(float angles[]) {
|
||||
synchronized (syncToken) {
|
||||
synchronized (synchronizationToken) {
|
||||
SensorManager.getOrientation(currentOrientationRotationMatrix.matrix, angles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,10 @@ import android.hardware.SensorManager;
|
||||
*/
|
||||
public class RotationVectorProvider extends OrientationProvider {
|
||||
|
||||
|
||||
/**
|
||||
* Temporary variable to save allocation
|
||||
* Temporary quaternion to store the values obtained from the SensorManager
|
||||
*/
|
||||
final private float[] tmpFloat = new float[4];
|
||||
final private float[] temporaryQuaternion = new float[4];
|
||||
|
||||
/**
|
||||
* Initialises a new RotationVectorProvider
|
||||
@@ -43,8 +42,8 @@ public class RotationVectorProvider extends OrientationProvider {
|
||||
|
||||
// Get Quaternion
|
||||
// Calculate angle. Starting with API_18, Android will provide this value as event.values[3], but if not, we have to calculate it manually.
|
||||
SensorManager.getQuaternionFromVector(tmpFloat, event.values);
|
||||
currentOrientationQuaternion.setXYZW(tmpFloat[1], tmpFloat[2], tmpFloat[3], -tmpFloat[0]);
|
||||
SensorManager.getQuaternionFromVector(temporaryQuaternion, event.values);
|
||||
currentOrientationQuaternion.setXYZW(temporaryQuaternion[1], temporaryQuaternion[2], temporaryQuaternion[3], -temporaryQuaternion[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user