使用Core Motion从加速度计数据中获取位移 [英] Getting displacement from accelerometer data with Core Motion

查看:167
本文介绍了使用Core Motion从加速度计数据中获取位移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种增强现实应用程序(目前)想要在表面上显示一个简单的立方体,并且能够在空间中移动(旋转和移位)以查看所有不同的立方体角。校准相机的问题在这里不适用,因为我要求用户将iPhone放在他想要放置立方体的表面上,然后按下按钮以重置姿势。
使用陀螺仪和核心运动来查找相机旋转非常简单。我这样做:

I am developing an augmented reality application that (at the moment) wants to display a simple cube on top of a surface, and be able to move in space (both rotating and displacing) to look at the cube in all the different angles. The problem of calibrating the camera doesn't apply here since I ask the user to place the iPhone on the surface he wants to place the cube on and then press a button to reset the attitude. To find out the camera rotation is very simple with the Gyroscope and Core Motion. I do it this way:

if (referenceAttitude != nil) {
    [attitude multiplyByInverseOfAttitude:referenceAttitude];
}

CMRotationMatrix mat = attitude.rotationMatrix;

GLfloat rotMat[] = {
    mat.m11, mat.m21, mat.m31, 0,
    mat.m12, mat.m22, mat.m32, 0,
    mat.m13, mat.m23, mat.m33, 0,
    0, 0, 0, 1
};

glMultMatrixf(rotMat);

这非常有效。
当我试图在加速期间找到空间位移时,无论如何都会出现更多问题。
带有Core Motion的Apple Teapot示例只是将加速度矢量的x,y和z值添加到位置矢量。这(除了没有多大意义)具有在加速之后将对象返回到原始位置的结果。 (因为加速度从正到负,反之亦然)。
他们是这样做的:

This works really well. More problems arise anyway when I try to find the displacement in space during an acceleration. The Apple Teapot example with Core Motion just adds the x, y and z values of the acceleration vector to the position vector. This (apart from having not much sense) has the result of returning the object to the original position after an acceleration. (Since the acceleration goes from positive to negative or vice versa). They did it like this:

translation.x += userAcceleration.x;
translation.y += userAcceleration.y;
translation.z += userAcceleration.z;

我应该怎样做才能找出某些人的加速度位移? (已知时差)。看一些其他的答案,似乎我必须整合两次以从加速度获得速度,然后从速度获得位置。但是代码中没有任何例子,我认为这不是必要的。此外,还有一个问题是,当iPhone仍然在飞机上时,加速度计值不为空(我认为有一些噪音)。我应该过滤多少这些值?我应该过滤掉它们吗?

What should I do to find out displacement from the acceleration in some istant? (with known time difference). Looking some other answers, it seems like I have to integrate twice to get velocity from acceleration and then position from velocity. But there is no example in code whatsoever, and I don't think that is really necessary. Also, there is the problem that when the iPhone is still on a plane, accelerometer values are not null (there is some noise I think). How much should I filter those values? Am I supposed to filter them at all?

推荐答案

很酷,有人在那里挣扎着同样的问题因此值得花了一些时间: - )

Cool, there are people out there struggling with the same problem so it is worth to spent some time :-)

我同意westsider的陈述,因为我花了几周的时间尝试不同的方法并最终得到了糟糕的结果。我相信,对于较长距离或持续超过1秒或2秒的慢速运动,将无法获得可接受的解决方案。如果您可以忍受一些限制,例如小距离(<10厘米)和给定动作的最小速度,那么我相信可能有机会找到解决方案 - 完全没有保证。如果是这样的话,你会花费很多时间进行研究并且会感到非常沮丧,但是如果你得到它,它会非常酷:-)也许你会发现这些提示很有用:

I agree with westsider's statement as I spent a few weeks of experimenting with different approaches and ended up with poor results. I am sure that there won't be an acceptable solution for either larger distances or slow motions lasting for more than 1 or 2 seconds. If you can live with some restrictions like small distances (< 10 cm) and a given minimum velocity for your motions, then I believe there might be the chance to find a solution - no guarantee at all. If so, it will take you a pretty hard time of research and a lot of frustration, but if you get it, it will be very very cool :-) Maybe you find these hints useful:

首先,为了简单起见,只需看一个轴,例如x,但考虑左(-x)和右(+ x)​​都有可表示的情况。

First of all to make things easy just look at one axis e.g x but consider both left (-x) and right (+x) to have a representable situation.

是的,你是对的,你必须整合两次以获得时间函数的位置。对于进一步处理,您应该存储第一个积分的结果(==速度),因为您将在稍后阶段进行优化。要非常小心,因为每一个小虫子都会在很短的时间内导致巨大的错误。

Yes you are right, you have to integrate twice to get the position as function of time. And for further processing you should store the first integration's result (== velocity), because you will need it in a later stage for optimisation. Do it very careful because every tiny bug will lead to huge errors after short period of time.

始终记住即使是非常小的错误(例如<0.1%) )两次整合后会迅速增长。如果你配置加速度计,例如50赫兹,即处理50个滴答,并且微小的可忽略错误将超过真实值,情况将在一秒后变得更糟。我强烈建议不要依赖梯形规则,而是至少使用辛普森或更高程度的牛顿 - 科特公式。

Always bear in mind that even a very small error (e.g. <0.1%) will grow rapidly after doing integration twice. Situation will become even worse after one second if you configure accelerometer with let's say 50 Hz, i.e. 50 ticks are processed and the tiny neglectable error will outrun the "true" value. I would strongly recommend to not rely on trapezoidal rule but to use at least Simpson or a higher degree Newton-Cotes formula.

如果你管理了这个,你必须保持着眼于设置正确的低通滤波。我不能给出一般值,但根据经验,尝试0.2到0.8之间的滤波因子将是一个很好的起点。正确的价值取决于您需要的商业案例,例如什么样的游戏,对事件做出反应的速度,......

If you managed this, you will have to keep an eye on setting up the right low pass filtering. I cannot give a general value but as a rule of thumb experimenting with filtering factors between 0.2 and 0.8 will be a good starting point. The right value depends on the business case you need, for instance what kind of game, how fast to react on events, ...

现在你将有一个解决方案在某些情况下并在很短的时间内工作得很好。但是几秒钟后你会遇到麻烦,因为你的物体正在飘走。现在你将进入解决方案的难点部分,我最终在给定的时间范围内未能处理: - (

Now you will have a solution which is working pretty good under certain circumstances and within a short period of time. But than after a few seconds you will run into trouble because your object is drifting away. Now you will enter the difficult part of the solution which I failed to handle eventually within the given time scope :-(

一种有希望的方法是引入我称之为合成的东西虽然设备保持固定(?没有母语,我的意思是没有移动)在你的手中,这是一些策略,可以对触发物体漂移的几种不良情况作出反应。最令人不安的是速度大于0而没有任何加速度。这是一个不可避免的误差传播结果,可以通过人工减速来处理,这意味着即使没有真正的对应物也会引入虚拟减速。一个非常简单的例子:

One promising approach is to introduce something I call "synthectic forces" or "virtual forces". This is some strategy to react on several bad situations triggering the object to drift away although the device remains fixed (? no native speaker, I mean without moving) in your hands. The most troubling one is a velocity greater than 0 without any acceleration. This is an unavoidable result of error propagation and can be handled by slowing down artificially that means introducing a virtual deceleration even if there is no real counterpart. A very simplified example:

if (vX > 0 && lastAccelerationXTimeStamp > 0.3sec) {

     vX *= 0.9;
}

`

你需要驯服野兽的这些条件的组合.Ge需要很多尝试和错误感觉是正确的方法,这将是问题的难点。

You will need a combination of such conditions to tame the beast. A lot of try and error is required to get a feeling for the right way to go and this will be the hard part of the problem.

如果你设法破解密码,请告诉我,我是非常好奇,看一般是否可能: - )

If you ever managed to crack the code, pleeeease let me know, I am very curious to see if it is possible in general or not :-)

Cheers Kay

Cheers Kay

这篇关于使用Core Motion从加速度计数据中获取位移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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