/** Returns the rotation matrix describing the devices rotation as per <a href= * "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])" * >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform * does not have an accelerometer and compass, or a rotation vector sensor. * @param matrix */ public void getRotationMatrix (float[] matrix) { if (rotationVectorAvailable) SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValues); else // compass + accelerometer SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues); }
/** Returns the rotation matrix describing the devices rotation as per <a href= * "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])" * >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform * does not have an accelerometer and compass, or a rotation vector sensor. * @param matrix */ public void getRotationMatrix (float[] matrix) { if (rotationVectorAvailable) SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValues); else // compass + accelerometer SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues); }
private void updateOrientation () { if (rotationVectorAvailable){ SensorManager.getRotationMatrixFromVector(R, rotationVectorValues); } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) { return; // compass + accelerometer in free fall } SensorManager.getOrientation(R, orientation); azimuth = (float)Math.toDegrees(orientation[0]); pitch = (float)Math.toDegrees(orientation[1]); roll = (float)Math.toDegrees(orientation[2]); }
private void updateOrientation () { if (rotationVectorAvailable){ SensorManager.getRotationMatrixFromVector(R, rotationVectorValues); } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) { return; // compass + accelerometer in free fall } SensorManager.getOrientation(R, orientation); azimuth = (float)Math.toDegrees(orientation[0]); pitch = (float)Math.toDegrees(orientation[1]); roll = (float)Math.toDegrees(orientation[2]); }
@Override protected void onSensorEvent(SensorEvent sensorEvent) { // Get rotation matrix float[] rotationMatrix = new float[16]; SensorManager.getRotationMatrixFromVector(rotationMatrix, sensorEvent.values); // Remap coordinate system float[] remappedRotationMatrix = new float[16]; SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRotationMatrix); // Convert to orientations float[] orientations = new float[3]; SensorManager.getOrientation(remappedRotationMatrix, orientations); // Convert values in radian to degrees for (int i = 0; i < 3; i++) { orientations[i] = (float) (Math.toDegrees(orientations[i])); } rotationAngleListener.onRotation(orientations[0], orientations[1], orientations[2]); } }
@Override @BinderThread public void onSensorChanged(SensorEvent event) { SensorManager.getRotationMatrixFromVector(remappedPhoneMatrix, event.values);
@Override public void onSensorChanged(SensorEvent event) { SensorManager.getRotationMatrixFromVector(matrix,event.values); mSkySphere.setMatrix(matrix); }
/** * Sets the target direction used for angle deltas to determine tilt. * * @param values a rotation vector (presumably from a ROTATION_VECTOR sensor) */ private void setTargetVector(float[] values) { SensorManager.getRotationMatrixFromVector(mTargetMatrix, values); mTargeted = true; }
/** * Sets the target direction used for angle deltas to determine tilt. * * @param values a rotation vector (presumably from a ROTATION_VECTOR sensor) */ protected void setTargetVector(float[] values) { SensorManager.getRotationMatrixFromVector(mTargetMatrix, values); mTargeted = true; }
public void onSensorChanged(SensorEvent sensorEvent) { float[] rotationMatrix = new float[9]; float[] orientation = new float[3]; // Convert the result Vector to a Rotation Matrix. SensorManager.getRotationMatrixFromVector(rotationMatrix, sensorEvent.values); // Extract the orientation from the Rotation Matrix. SensorManager.getOrientation(rotationMatrix, orientation); Log.d(TAG, "Yaw: " + orientation[0]); // Yaw Log.d(TAG, "Pitch: " + orientation[1]); // Pitch Log.d(TAG, "Roll: " + orientation[2]); // Roll }
public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { // convert the rotation-vector to a 4x4 matrix. the matrix // is interpreted by Open GL as the inverse of the // rotation-vector, which is what we want. SensorManager.getRotationMatrixFromVector( mRotationMatrix , event.values); } }
public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { // convert the rotation-vector to a 4x4 matrix. the matrix // is interpreted by Open GL as the inverse of the // rotation-vector, which is what we want. SensorManager.getRotationMatrixFromVector( mRotationMatrix , event.values); } }
@Override public void onSensorChanged(SensorEvent event) { azimuthFrom = azimuthTo; float[] orientation = new float[3]; float[] rMat = new float[9]; SensorManager.getRotationMatrixFromVector(rMat, event.values); azimuthTo = (int) ( Math.toDegrees( SensorManager.getOrientation( rMat, orientation )[0] ) + 360 ) % 360; mAzimuthListener.onAzimuthChanged(azimuthFrom, azimuthTo); }
@Override public void onSensorChanged(SensorEvent event) { // we received a sensor event. it is a good practice to check // that we received the proper event if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { // convert the rotation-vector to a 4x4 matrix. the matrix // is interpreted by Open GL as the inverse of the // rotation-vector, which is what we want. SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix.matrix, event.values); // 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(temporaryQuaternion, event.values); currentOrientationQuaternion.setXYZW(temporaryQuaternion[1], temporaryQuaternion[2], temporaryQuaternion[3], -temporaryQuaternion[0]); } } }
private void updateCoordinate(float[] rotationVector) { SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector); SensorManager.remapCoordinateSystem(mRotationMatrix, mRemappedXAxis, mRemappedYAxis, mRemappedRotationMatrix); SensorManager.getOrientation(mRemappedRotationMatrix, mOrientationVals); if (mCurrentRotation == Surface.ROTATION_0) { //For some reasons, there is a difference of 100° on the Y coordinate //between landscape and portrait orientation. This is a poor //attempt at fixing this issue. mOrientationVals[2] -= 1.7453292519; } onSmoothCoordinateChanged(mOrientationVals.clone()); }
public void onGyroDataUpdate(float[] gyro) { // initialisation of the gyroscope based rotation matrix if (!isGyroInitialized) { float[] initMatrix = getRotationMatrixFromOrientation(accMagOrientation); gyroMatrix = matrixMultiplication(gyroMatrix, initMatrix); isGyroInitialized = true; } // copy the new gyro values into the gyro array // convert the raw gyro data into a rotation vector float[] deltaVector = new float[4]; final long currentTimestamp = System.nanoTime(); if(timestamp != 0) { final float dT = (currentTimestamp - timestamp) * NS2S; System.arraycopy(gyro, 0, this.gyro, 0, 3); getRotationVectorFromGyro(this.gyro, deltaVector, dT / 2.0f); } // measurement done, save current time for next interval timestamp = currentTimestamp; // convert rotation vector into rotation matrix float[] deltaMatrix = new float[9]; SensorManager.getRotationMatrixFromVector(deltaMatrix, deltaVector); // apply the new rotation interval on the gyroscope based rotation matrix gyroMatrix = matrixMultiplication(gyroMatrix, deltaMatrix); // get the gyroscope based orientation from the rotation matrix SensorManager.getOrientation(gyroMatrix, gyroOrientation); }
private void update(float[] vectors) { int AMP_MAX = 50; int AMPLIFICATION = AMP_MAX / mControls.getGyroAmplification(); float[] rotationMatrix = new float[9]; SensorManager.getRotationMatrixFromVector(rotationMatrix, vectors); int worldAxisX = SensorManager.AXIS_X; int worldAxisY = SensorManager.AXIS_Y; float[] adjustedRotationMatrix = new float[9]; SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisX, worldAxisY, adjustedRotationMatrix); float[] orientation = new float[3]; SensorManager.getOrientation(adjustedRotationMatrix, orientation); float pitch = (orientation[2] * FROM_RADS_TO_DEGS * -1) / AMPLIFICATION; float roll = (orientation[1] * FROM_RADS_TO_DEGS) / AMPLIFICATION; mSensorRoll = roll; mSensorPitch = pitch; updateFlightData(); }
/** * Sets the output quaternion and matrix with the provided quaternion and synchronises the setting * * @param quaternion The Quaternion to set (the result of the sensor fusion) */ private void setOrientationQuaternionAndMatrix(Quaternion quaternion) { Quaternion correctedQuat = quaternion.clone(); // 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()); synchronized (syncToken) { // Use gyro only currentOrientationQuaternion.copyVec4(quaternion); // Set the rotation matrix as well to have both representations SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix.matrix, correctedQuat.ToArray()); } }
/** * Sets the output quaternion and matrix with the provided quaternion and synchronises the setting * * @param quaternion The Quaternion to set (the result of the sensor fusion) */ private void setOrientationQuaternionAndMatrix(Quaternion quaternion) { correctedQuaternion.set(quaternion); // We inverted w in the deltaQuaternion, because currentOrientationQuaternion required it. // Before converting it back to matrix representation, we need to revert this process correctedQuaternion.w(-correctedQuaternion.w()); synchronized (synchronizationToken) { // Use gyro only currentOrientationQuaternion.copyVec4(quaternion); // Set the rotation matrix as well to have both representations SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix.matrix, correctedQuaternion.array()); } } }
/** * Sets the output quaternion and matrix with the provided quaternion and synchronises the setting * * @param quaternion The Quaternion to set (the result of the sensor fusion) */ private void setOrientationQuaternionAndMatrix(Quaternion quaternion) { correctedQuaternion.set(quaternion); // We inverted w in the deltaQuaternion, because currentOrientationQuaternion required it. // Before converting it back to matrix representation, we need to revert this process correctedQuaternion.w(-correctedQuaternion.w()); synchronized (synchronizationToken) { // Use gyro only currentOrientationQuaternion.copyVec4(quaternion); // Set the rotation matrix as well to have both representations SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix.matrix, correctedQuaternion.array()); } } }