问题描述
我在CMDeviceMotion中看到来自userAcceleration字段的一些意外读数。当我从CMAccelerometerData查看原始加速度计数据时,我看到如果iPhone在桌面上是平的,读数是1G直下(1G在-Z轴),如果我放下iphone(当然在柔软的表面上),那么加速度读数按预期变为零。那一切都很好。当我改为使用CMDeviceMotion类时,当桌面上的iPhone平放时,userAcceleration读数为零。再次这很好。但是当我放下iPhone并读取CMDeviceManager userAcceleration时,userAcceleration值是1G直线上升(+ Z)而不是按预期下降(-Z)。看起来userCcceleration读数实际上与设备实际遇到的加速度完全相反。还有其他人观察过这个吗?在尝试整合速度和位置之前,我可以反转(乘以-1)所有userAcceleration值,还是我误解了userAcceleration正在读取的内容?
I'm seeing some unexpected readings from the userAcceleration field in CMDeviceMotion. When I look at the raw accelerometer data from CMAccelerometerData, I see that if the iPhone is flat on a table the reading is 1G straight down (1G in -Z axis) and if I drop the iphone (on a soft surface of course) then the acceleromtere reading goes to zero as expected. That's all fine. When I instead use the CMDeviceMotion class, the userAcceleration reading is zero as expected when the iPhone is flat on table. Again this is fine. But when I drop the iPhone and read the CMDeviceManager userAcceleration, the userAcceleration values are 1G straight up (+Z) not down (-Z) as expected. It appears that the userAcceleration readings are actually the exact opposite of what acceleration the device is really experiencing. Has anyone else observed this? Can I just invert (multiply by -1) all the userAcceleration values before I try to integrate for velocity and position, or am I misunerstanding what userAcceleration is reading?
推荐答案
和
- 原始加速度计数据只是所有测量加速度的总和,即设备的重力和当前加速度的组合。
- 设备运动数据是所有3个传感器(即加速度计,陀螺仪和磁力计)的传感器融合的结果。因此消除了偏差和误差(理论上),并将剩余的加速度数据分为重力和加速度,以方便使用。
所以如果你想比较两者你必须检查 CMAccelerometerData.acceleration
对 CMDeviceMotion.userAcceleration + CMDeviceMotion.gravity
进行比较喜欢。
So if you want to compare both you have to check CMAccelerometerData.acceleration
against CMDeviceMotion.userAcceleration + CMDeviceMotion.gravity
to compare like with like.
一般情况下,当你需要精确的值和硬件独立性时,CMDeviceMotion是你的首选。
In general CMDeviceMotion is your first choice in most cases when you want precise values and hardware independency.
要考虑的另一件事是 CMAttitude_Class /参考/#的reference.html // apple_ref / OCC / instm / CMMotionMana ger / startDeviceMotionUpdatesUsingReferenceFrame:rel =nofollow noreferrer> startDeviceMotionUpdatesUsingReferenceFrame 。我不确定使用基本版本时的默认值是什么
Another thing to consider is the CMAttitudeReferenceFrame you provide when starting Device Motion updates via startDeviceMotionUpdatesUsingReferenceFrame. I am not sure what is the default when using the basic version startDeviceMotionUpdates
你说你了想要整合这些值来获得速度和位置。关于这一点有几个讨论,在底线我可以说不可能得到合理的结果。请参阅:
You stated that you want to integrate the values to get velocity and position. There are several discussions about this and at the bottom line I can say it's impossible to get reasonable results. See:
- Finding distance using accelerometer in iPhone
- Getting displacement from accelerometer data with Core Motion
- How can I find distance traveled with a gyroscope and accelerometer?
如果您的应用程序概念迫使您依赖精确结果超过半秒,请尝试更改它。
If your app concept forces you to rely on precise results for more than half a second, try to change it.
这篇关于CMDeviceMotion userAcceleration颠倒了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!