DeviceMotion 相对于世界 -multiplyByInverseOfAttitude
使用 CMAttitude:multiplyByInverseOfAttitude 的正确方法是什么?
假设 iOS5 设备平放在桌子上,启动 CMMotionManager 后:
CMMotionManager *motionManager = [[CMMotionManager alloc]init];
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:
CMAttitudeReferenceFrameXTrueNorthZVertical];
稍后,获得 CMDeviceMotion 对象:
CMDeviceMotion *deviceMotion = [motionManager deviceMotion];
我期望 [deviceMotion Attitude] 反映设备从正北的旋转。
通过观察,[deviceMotion userAcceleration] 报告设备参考系中的加速度。也就是说,左右移动设备(使其平放在桌子上)会记录 x 轴上的加速度。将设备旋转 90°(仍然平坦)并将设备左右移动仍然会报告 x 加速度。
转换 [deviceMotion userAcceleration] 以获得南北/东西加速度而不是左右/前后加速度的正确方法是什么?
CMAttitudemultiplyByInverseOfAttitude 似乎没有必要,因为已经指定了参考系,并且文档中不清楚如何将姿态应用于 CMAcceleration。
What is the correct way to use CMAttitude:multiplyByInverseOfAttitude?
Assuming an iOS5 device laying flat on a table, after starting CMMotionManager with:
CMMotionManager *motionManager = [[CMMotionManager alloc]init];
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:
CMAttitudeReferenceFrameXTrueNorthZVertical];
Later, CMDeviceMotion objects are obtained:
CMDeviceMotion *deviceMotion = [motionManager deviceMotion];
I expect that [deviceMotion attitude] reflects the rotation of the device from True North.
By observation, [deviceMotion userAcceleration] reports acceleration in the device reference frame. That is, moving the device side to side (keeping it flat on the table) registers acceleration in the x-axis. Turning the device 90° (still flat) and moving the device side to side still reports x acceleration.
What is the correct way to transform [deviceMotion userAcceleration] to obtain North-South/East-West acceleration rather than left-right/forward-backward?
CMAttitude multiplyByInverseOfAttitude seems unnecessary since a reference frame has already been specified and it is unclear from the documentation how to apply the attitude to CMAcceleration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果 CMDeviceMotion 在参考系坐标中有一个用于 userAcceleration 的访问器,那么这个问题就不会出现。因此,我使用了一个类别来添加所需的方法:
在 CMDeviceMotion+TransformToReferenceFrame.h:
和 CMDeviceMotion+TransformToReferenceFrame.m: 中
以及在 Swift 3 中
,以前使用 [deviceMotion userAcceleration] 的代码可以改用 [deviceMotion userAccelerationInReferenceFrame]。
The question would not have arisen if CMDeviceMotion had an accessor for the userAcceleration in coordinates of the reference frame. So, I used a category to add the required method:
In CMDeviceMotion+TransformToReferenceFrame.h:
and in CMDeviceMotion+TransformToReferenceFrame.m:
and in Swift 3
Now, code that previously used [deviceMotion userAcceleration] can use [deviceMotion userAccelerationInReferenceFrame] instead.
根据 Apple 的文档,
CMAttitude
是指身体相对于给定参考系的方向。userAcceleration
或gravity
是设备框架的值。这样才能得到参考系的值。我们应该像@Batti 所说的那样,这是 Swift 版本
希望它能有所帮助
According to Apple's Documentation,
CMAttitude
refers to the orientation of a body relative to a given frame of reference. And eitheruserAcceleration
orgravity
is the value of the device's frame. So in order to get the value of reference frame. We should do as @Batti saidHere's the Swift version
Hope it helps a little bit
在阅读上面链接的论文后,我尝试实施一个解决方案。
步骤如下:
所得向量将是向量的投影。
-x 北,+x 南
-y 东,+y 西
我的代码还不完美,我正在努力。
i tried to implement a solution after reading the paper linked above.
Steps are the follows:
the resultant vector will be the projection of the vector.
-x north, +x south
-y east, +y weast
my code it's not perfect yet, i'm working on it.
参考系与姿态值有关,看偏航角的姿态值;如果您不使用参考系,则在启动应用程序时,该值始终为零,而如果您使用参考系 CMAttitudeReferenceFrameXTrueNorthZVertical,则偏航值指示 x 轴与真北之间的角度。
通过这些信息,您可以确定手机在地球坐标中的姿态,从而确定加速度计的轴相对于基点的位置。
The reference frame is related to the attitude value, look the value of attitude of yaw angle; If you don't use a reference frame, when you start your app, this value is always zero, instead if you use the reference frame CMAttitudeReferenceFrameXTrueNorthZVertical the yaw value indicates the angle between the x-axis and true north.
with this information you can identify the attitude of phone in the coordinates of the earth and therefore the position of axes of the accelerometer with respect to the cardinal points.