检测汽车的加速度(iPhone 加速度计) [英] Detecting Acceleration in a car (iPhone Accelerometer)

查看:71
本文介绍了检测汽车的加速度(iPhone 加速度计)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 iPhone 应用程序,我们试图在其中计算行驶中的汽车的加速度.类似的应用程序已经实现了这一点(Dynolicious),但不同的是该应用程序旨在用于一般城市驾驶,而不是在拖带上使用.

I am working on an iPhone app where we are trying to calculate the acceleration of a moving car. Similar apps have accomplished this (Dynolicious), but the difference is that this app is designed to be used during general city driving, not on a drag strip.

这让我们想到了 Dynolicious 幸运地能够避免的一个大问题:山丘.是的,山丘.

This leads us to one big concern that Dynolicious was luckily able to avoid: hills. Yes, hills.

这有两个重要阶段:校准和实际驾驶.

There are two important stages to this: calibration, and actual driving.

我们最初的运行很简单,但后果很严重.在校准阶段,我在手机上取了平均力,而在运行时,我只是从当前的力中减去平均力,就得到了这一帧的当前加速度.问题在于,典型的汽车受到的力远不止前进的力——从转弯到坑洼的一切都导致数值与实际发生的情况不同步.

Our initial run was simple and suffered the consequences. During the calibration stage, I took the average force on the phone, and during running, I just subtracted the average force from the current force to get the current acceleration this frame. The problem with this is that the typical car receives much more force than just the forward force - everything from turning to potholes was causing the values to go out of sync with what was really happening.

下一步是添加条件,即 iPhone 的方向必须使屏幕朝向汽车后部.使用这种方法,我尝试仅跟踪 z 轴上的力,但这显然会导致问题,除非 iPhone 因重力而直接竖直放置.

The next run was to add the condition that the iPhone must be oriented in such a way that the screen was facing toward the back of the car. Using this method, I attempted to follow only force on the z-axis, but this obviously lead to problems unless the iPhone was oriented directly upright, because of gravity.

一些三角学之后,我设法摆脱了等式中的重力,因此 iPhone 实际上非常非常好地读取了汽车.

Some trigonometry later, and I had managed to work gravity out of the equation, so that the car was actually being read very, very well by the iPhone.

直到我撞上斜坡.汽车的角度一改变,突然我就收到了毫无意义的加速和减速,我们又一次不同步了.

Until I hit a slope. As soon as the angle of the car changed, suddenly I was receiving accelerations and decelerations that didn't make sense, and we were once again going out of sync.

与在数学上比我聪明得多的人交谈会找到一个解决方案,我尝试实施的时间比我想承认的要长.其步骤如下:

Talking with someone a lot smarter than me at math lead to a solution that I have been trying to implement for longer than I would like to admit. It's steps are as follows:

1) 在校准期间,将重力测量为矢量而不是大小.存储该向量.2)当汽车开始向前移动时,取运动矢量并减去重力.以此作为前进的动力.(暂时忽略这将是困难的用户案例,让我们专注于数学:)3) 从前向向量和重力向量,构造一个平面.4)每当受到力时,将其投射到所述平面上以消除侧向力/等.5) 然后,使用该力、已知的重力大小和已知的向前运动方向来本质上求解三角形以获得前向矢量.

1) During calibration, measure gravity as a vector instead of a size. Store that vector. 2) When the car initially moves forward, take the vector of motion and subtract gravity. Use this as the forward momentum. (Ignore, for now, the user cases where this will be difficult and let's concentrate on the math :) 3) From the forward vector and the gravity vector, construct a plane. 4) Whenever a force is received, project it onto said plane to get rid of sideways force/etc. 5) Then, use that force, the known magnitude of gravity, and the known direction of forward motion to essentially solve a triangle to get the forward vector.

在这个新系统中造成最大困难的问题不是第 5 步,我已经达到了所有数字看起来都应该如此的程度.难点其实是前向向量的检测.我正在选择大小超过重力的向量,然后对它们求平均值并减去重力.(我正在做一些错误检查,以确保我不会仅仅因为 iPhone 加速度计有点关闭而使用力,这种情况发生的频率比我想要的要高).但是,如果我绘制我正在使用的这些向量,它们实际上会以大约 20-30 度的角度变化,这可能会导致一些严重的不准确.最终结果是该应用现在比以前更不准确.

The problem that is causing the most difficulty in this new system is not step 5, which I have gotten to the point where all the numbers look as they should. The difficult part is actually the detection of the forward vector. I am selecting vectors whose magnitude exceeds gravity, and from there, averaging them and subtracting gravity. (I am doing some error checking to make sure that I am not using a force just because the iPhone accelerometer was off by a bit, which happens more frequently than I would like). But if I plot these vectors that I am using, they actually vary by an angle of about 20-30 degrees, which can lead to some strong inaccuracies. The end result is that the app is even more inaccurate now than before.

所以基本上 - 你所有的数学和 iPhone 大脑 - 有什么明显的错误吗?任何可能更好的解决方案?任何可能有用的经验?

So basically - all you math and iPhone brains out there - any glaring errors? Any potentially better solutions? Any experience that could be useful at all?

奖励:对第一个找到解决方案的答案提供 250 美元的奖励.

Award: offering a bounty of $250 to the first answer that leads to a solution.

推荐答案

你需要一个陀螺仪.否则,在山坡上加速汽车的多种配置可以在加速度计上产生完全相同的读数.他们将完全无法区分.这就是惯性导航系统结合陀螺仪和加速度计的原因.

You need a gyro. Otherwise there are multiple configurations of an accelerating car on a hill that can give rise to exactly the same readings on an accelerometer. They will be completely impossible to distinguish. That's why inertial navigation systems combine a gyro and accelerometer.

你不能这样做的原因是爱因斯坦给出的!使用本地测量,您无法区分重力和加速度.您确实有一些有用的非本地信息 - 假设这里的重力和那里几码处的重力具有相同的值.但是,如果没有执行所谓的平行传输"的方法,就无法比较两个不同位置的重力.这就是陀螺仪的作用.

The reason you can't do this was given by Einstein! Using a local measurement, you can't distinguish between gravity and acceleration. You do have some useful non-local information - the assumption that gravity here, and gravity a few yards over there, have the same value. But you can't compare gravity in two different locations without a means to carry out what's called "parallel transport". This is what a gyro does.

忘记 250 美元,但我认为你应该给我一杯啤酒,因为我为你节省了大量的研发时间.:-)

Forget the $250, but I think you should give me a beer for the amount of R&D time I'm saving you. :-)

这篇关于检测汽车的加速度(iPhone 加速度计)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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