BLE CPro sensor我试图"构建"智能手机游戏的遥控器。如果传感器位于左侧或右侧而不受其重力影响,我如何识别传感器的方向(优先级)。即在动摇/移动的环境中?
我的问题是,如果我使用加速度计计算方向,每次传感器被晃动时,重力会急剧变化,这使得很难知道当前的方向?
此CPro传感器提供了有关如何计算四元数的示例。作为输出,它使用OpenGL ES显示立方体图形,该图形遵循传感器的方向/旋转。不幸的是,我不太了解如何从四元数中获得毕业生的方向......
//src https://github.com/mbientlab-projects/iOSSensorFusion/tree/master
- (void)performKalmanUpdate
{
[self.estimator readAccel:self.accelData
rates:self.gyroData
field:self.magnetometerData];
if (self.estimator.compassCalibrated && self.estimator.gyroCalibrated)
{
auto q = self.estimator.eskf->getState();
auto g = self.estimator.eskf->getAPred();
auto a = self.accelData;
auto w = self.gyroData;
auto mp = self.estimator.eskf->getMPred();
auto m = self.estimator.eskf->getMMeas();
_s->qvals[0] = q.a();
_s->qvals[1] = q.b();
_s->qvals[2] = q.c();
_s->qvals[3] = q.d();
// calculate un-filtered angles
float ay = -a.y;
if (ay < -1.0f) {
ay = -1.0f;
} else if (ay > 1.0f) {
ay = 1.0f;
}
_s->ang[1] = std::atan2(-a.x, -a.z);
_s->ang[0] = std::asin(-ay);
_s->ang[2] = std::atan2(m(1), m(0)); // hack: using the filtered cos/theta to tilt-compensate here
// send transform to render view
auto R = q.to_matrix();
GLKMatrix4 trans = GLKMatrix4Identity;
auto M = GLKMatrix4MakeAndTranspose(R(0,0), R(0,1), R(0,2), 0.0f,
R(1,0), R(1,1), R(1,2), 0.0f,
R(2,0), R(2,1), R(2,2), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
trans = GLKMatrix4Multiply(trans, M);
self.renderVC.cubeOrientation = trans;
}
}