return 0;
}
+/*
+ Euler angles to Quarternion conversion
+ q.w = cos(pitch / 2) * cos(roll / 2) * cos(yaw / 2) + sin(pitch / 2) * sin(roll / 2) * sin(yaw / 2)
+ q.x = sin(pitch / 2) * cos(roll / 2) * cos(yaw / 2) - cos(pitch / 2) * sin(roll / 2) * sin(yaw / 2)
+ q.y = cos(pitch / 2) * sin(roll / 2) * cos(yaw / 2) + sin(pitch / 2) * cos(roll / 2) * sin(yaw / 2)
+ q.z = cos(pitch / 2) * cos(roll / 2) * sin(yaw / 2) - sin(pitch / 2) * sin(roll / 2) * cos(yaw / 2)
+
+ Be careful about the definition of pitch and roll.
+ It can be different of axis direction each reference.
+*/
+
+void orientation_to_quat(float *quat, float azimuth, float pitch, float roll)
+{
+ azimuth /= -RAD2DEGREE;
+ pitch /= -RAD2DEGREE;
+ roll /= -RAD2DEGREE;
+ double cy = cos(azimuth * 0.5);
+ double sy = sin(azimuth * 0.5);
+ double cp = cos(pitch * 0.5);
+ double sp = sin(pitch * 0.5);
+ double cr = cos(roll * 0.5);
+ double sr = sin(roll * 0.5);
+
+ quat[3] = cp * cr * cy + sp * sr * sy;
+ quat[0] = sp * cr * cy - cp * sr * sy;
+ quat[1] = cp * sr * cy + sp * cr * sy;
+ quat[2] = cp * cr * sy - sp * sr * cy;
+}
int matrix_to_quat(const float *R, float *quat);
int calculate_rotation_matrix(float *accel, float *geo, float *R, float *I);
int quat_to_orientation(const float *rotation, float &azimuth, float &pitch, float &roll);
+void orientation_to_quat(float *quat, float azimuth, float pitch, float roll);
#ifdef __cplusplus
}
// released in android-11.0.0_r9
#include "orientation_filter.h"
+#include "fusion_util.h"
using namespace android;
vec3_t north(cross_product(up, east));
R << east << north << up;
- const vec4_t q = matrixToQuat(R);
+ vec4_t q = matrixToQuat(R);
+
+ if (mMode == FUSION_NOMAG) {
+ float temp[4] = {q[0], q[1], q[2], q[3]};
+ float azimuth, pitch, roll;
+
+ quat_to_orientation(temp, azimuth, pitch, roll);
+ azimuth = 0;
+ orientation_to_quat(temp, azimuth, pitch, roll);
+
+ q[0] = temp[0];
+ q[1] = temp[1];
+ q[2] = temp[2];
+ q[3] = temp[3];
+ }
initFusion(q, mGyroRate);
}