用核心运动计算精益角度 [英] Calculating Lean Angle with Core Motion

查看:159
本文介绍了用核心运动计算精益角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请记录会话。当用户启动记录会话时,我开始从设备的CMMotionManager对象收集数据并将它们存储在CoreData上以便稍后处理和显示。我收集的数据包括gps数据,加速度计数据和陀螺仪数据。数据的频率是10Hz。

I have a record session for my application. When user started a record session I start collecting data from device's CMMotionManager object and store them on CoreData to process and present later. The data I'm collecting includes gps data, accelerometer data and gyro data. The frequency of data is 10Hz.

目前我很难用运动数据计算设备的倾斜角度。可以通过使用重力数据来计算设备的哪一侧着陆,但我想计算用户与地面之间的左右角度而不管行进方向。

Currently I'm struggling to calculate the lean angle of device with motion data. It is possible to calculate which side of device is land by using gravity data but I want to calculate right or left angle between user and ground regardless of travel direction.

这个问题需要一些线性代数知识来解决。例如,对于某些点的计算,我必须计算计算平面上的3D线的方程。我正在研究这一天并且它变得越来越复杂。我根本不擅长数学。一些与该问题相关的数学例子也很受欢迎。

This problem requires some linear algebra knowledge to solve. For example for calculation on some point I must calculate the equation of a 3D line on a calculated plane. I am working on this one for a day and it's getting more complex. I'm not good at math at all. Some math examples related to the problem is appreciated too.

推荐答案

这取决于你想对收集的数据做什么以及什么用户将在iPhone /口袋中录制iPhone的方式。原因是欧拉角不安全,尤其没有表达旋转的独特方式。考虑一种情况,用户将手机直立放入牛仔裤的后袋,然后向左转90°。因为CMAttitude与平放在桌面上的设备有关,所以根据此图片

It depends on what you want to do with the collected data and what ways the user will go with that recording iPhone in her/his pocket. The reason is that Euler angles are no safe and especially no unique way to express a rotation. Consider a situation where the user puts the phone upright into his jeans' back pocket and then turns left around 90°. Because CMAttitude is related to a device lying flat on the table, you have two subsequent rotations for (pitch=x, roll=y, yaw=z) according to this picture:


  • 音高+ 90°让手机竖直=>(90,0,0)

  • roll + 90°for向左转=>(90,90,0)

但你可以获得相同的位置:

But you can get the same position by:


  • yaw + 90°左手拨打电话(0,0,90)

  • 音高-90°用于制作手机直立(-90,0,90)

你会看到两种不同的表示形式(90,90,0)和(-90,0) ,90)为了获得相同的旋转,他们有更多。所以你按下开始按钮,做一些奇特的旋转把手机放进口袋里你就麻烦了,因为在做更复杂的动作时你不能依赖欧拉角(s。万向节锁定对此更令人头疼; - )

You see two different representations (90, 90, 0) and (-90, 0, 90) for getting to the same rotation and there are more of them. So you press Start button, do some fancy rotations to put the phone into the pocket and you are in trouble because you can't rely on Euler Angles when doing more complex motions (s. gimbal lock for more headaches on this ;-)

现在好消息:你是正确的线性代数将完成这项工作。您可以做的是强迫您的用户将手机放在相同的位置,例如直立固定在右后袋中,并通过构建点积来计算相对于地面的角度来自 / gravityrel =noreferrer> CMDeviceMotion g =(x,y,z)和位置向量p,它是-Y轴(0,-1,0)in直立位置:

Now the good news: you are right linear algebra will do the job. What you can do is force your users to put the phone in always the same position e.g. fixed upright in the right back pocket and calculate the angle(s) relative to the ground by building the dot product of gravity vector from CMDeviceMotion g = (x, y, z) and the postion vector p which is the -Y axis (0, -1, 0) in upright position:

g•x = x * 0 + y *( - 1)+ z * 0 = -y = || g || * 1 * cos( alpha)

g • x = x*0 + y*(-1) + z*0 = -y = ||g||*1*cos (alpha)

=> alpha = arccos(-y / 9.81)作为总角度。请注意,重力加速度g常常约为9.81

=> alpha = arccos (-y/9.81) as total angle. Note that gravitational acceleration g is constantly about 9.81

为了获得左右倾斜角和前后角,我们使用tangens:

To get the left-right lean angle and forward-back angle we use the tangens:

alphaLR = arctan(x / y)

alphaFB = arctan(z / y)

[更新:]

如果您不能依赖于上述等式中的(0,-1,0)等预定义位置的手机,则只能计算总角度,而不能计算特定的αLR和alphaFB。原因是您只有一个新坐标系的轴,您需要其中两个轴。然后,新的Y轴 y'将被定义为平均重力矢量,但您不知道新的X轴,因为每个向量到y'的矢量都是有效的。

If you can't rely on having the phone at a predefined postion like (0, -1, 0) in the equations above, you can only calculate the total angle but not the specific ones alphaLR and alphaFB. The reason is that you only have one axis of the new coordinate system where you need two of them. The new Y axis y' will then be defined as average gravity vector but you don't know your new X axis because every vector perpedicular to y' will be valid.

因此,您必须提供更多信息,例如让用户在不偏离的情况下向一个方向行走更长的距离,并使用GPS和磁力计数据来获得第二轴z'。在实践中听起来很容易出错。

So you have to provide further information like let the users walk a longer distance into one direction without deviating and use GPS and magnetometer data to get the 2nd axis z'. Sounds pretty error prone in practise.

总角度没有问题,因为我们可以用平均重力矢量(pX,pY代替)来替换(0,-1,0) pZ):

The total angle is no problem as we can replace (0, -1, 0) with the average gravity vector (pX, pY, pZ):

g•p = x pX + y pY + z pZ = || g || || p || * cos(alpha)= || g || ^ 2 * cos(alpha)

g•p = xpX + ypY + zpZ = ||g||||p||*cos(alpha) = ||g||^2*cos(alpha)

alpha = arccos((x pX + y pY + z * pZ)/ 9.81 ^ 2)

alpha = arccos ((xpX + ypY + z*pZ) / 9.81^2)

还有两件事要记住:


  • 不同的人穿着不同的口袋镘刀。因此,即使对于穿着其他衣服的同一个人,重力矢量也会有所不同,您可能需要某种规范化

  • CMMotionManager在后台不起作用,即用户不能按下待机按钮

这篇关于用核心运动计算精益角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆