本文介绍了如何使用加速度计检测iPhone在空间中的移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试制作一个应用程序来检测您使用加速度计使用iPhone制作的形状。
例如,如果用手拿着iPhone绘制一个圆圈,应用程序就可以在屏幕上重绘它。
这也适用于正方形,甚至更复杂的形状。
我见过这样做的唯一应用示例是AirPaint(),但它似乎无法实时完成。

I am trying to make an application that would detect what kind of shape you made with your iPhone using accelerometer.As an example, if you draw a circle with your hand holding the iPhone, the app would be able to redraw it on the screen.This could also work with squares, or even more complicated shapes.The only example of application I've seen doing such a thing is AirPaint (http://vimeo.com/2276713), but it doesn't seems to be able to do it in real time.

我的第一个尝试是对它应用低通滤波器来自加速度计的X和Y参数,并使指针移动到这些值,与屏幕的大小成比例。
但显然不是这样,我的准确度非常低,如果我摇动设备它也会使指针移动......

My first try is to apply a low-pass filter on the X and Y parameters from the accelerometer, and to make a pointer move toward these values, proportionally to the size of the screen.But this is clearly not enought, I have a very low accuracy, and if I shake the device it also makes the pointer move...

任何想法关于那个 ?
您认为加速计数据是否应该这样做?或者我应该考虑使用其他数据,例如指南针?

Any ideas about that ?Do you think accelerometer data is enought to do it ? Or should I consider using other data, such as the compass ?

提前致谢!

推荐答案

好的我找到了似乎有用的东西,但我还是有一些问题。
以下是我的处理方法(承认设备是垂直的):

OK I have found something that seems to work, but I still have some problems.Here is how I proceed (admiting the device is hold verticaly) :

1 - 我有我的默认x,y和z值。

2 - 我使用低通滤波器从这些数据中提取重力矢量。

3 - 我从每个x,y和z中减去归一化的重力矢量,然后得到运动加速。

4 - 然后,我将这个加速度值与时间相结合,所以我得到了速度。

5 - 我再次将这个速度与时间相结合,并找到一个位置。

1 - I have my default x, y, and z values.
2 - I extract the gravity vector from this data using a low pass filter.
3 - I substract the normalized gravity vector from each x, y, and z, and get the movement acceleration.
4 - Then, I integrate this acceleration value with respect to time, so I get the velocity.
5 - I integrate this velocity again with respect to time, and find a position.

所有以下代码都在加速度计中:didAccelerate:我的控制器的委托。
我试图根据我找到的位置让球移动。
这是我的代码:

All of the below code is into the accelerometer:didAccelerate: delegate of my controller.I am trying to make a ball moving according to the position i found.Here is my code :

NSTimeInterval interval = 0;
NSDate *now = [NSDate date];
if (previousDate != nil)
{
    interval = [now timeIntervalSinceDate:previousDate];
}
previousDate = now;

//Isolating gravity vector
gravity.x = currentAcceleration.x * kFileringFactor + gravity.x * (1.0 - kFileringFactor);
gravity.y = currentAcceleration.y * kFileringFactor + gravity.y * (1.0 - kFileringFactor);
gravity.z = currentAcceleration.z * kFileringFactor + gravity.z * (1.0 - kFileringFactor);
float gravityNorm = sqrt(gravity.x * gravity.x + gravity.y * gravity.y + gravity.z * gravity.z);

//Removing gravity vector from initial acceleration
filteredAcceleration.x = acceleration.x - gravity.x / gravityNorm;
filteredAcceleration.y = acceleration.y - gravity.y / gravityNorm;
filteredAcceleration.z = acceleration.z - gravity.z / gravityNorm;

//Calculating velocity related to time interval
velocity.x = velocity.x + filteredAcceleration.x * interval;
velocity.y = velocity.y + filteredAcceleration.y * interval;
velocity.z = velocity.z + filteredAcceleration.z * interval;

//Finding position
position.x = position.x + velocity.x * interval * 160;
position.y = position.y + velocity.y * interval * 230;

如果我执行此操作,我会获得相当不错的价值,我的意思是我可以看到加速进入正值根据我的动作或负值。
但是当我尝试将这个位置应用到我的球视图中时,我可以看到它正在移动,但是在一个方向上比在另一个方向上更加擅长。这意味着,例如,如果我用我的设备绘制圆圈,我将看到球描述朝向屏幕左上角的曲线。
类似的东西:

If I execute this, I get quite good values, I mean I can see the acceleration going into positive or negative values according to the movements I make.But when I try to apply that position to my ball view, I can see it is moving, but with a propencity to go more in one direction than the other. This means, for example, if I draw circles with my device, i will see the ball describing curves towards the top-left corner of the screen.Something like that : http://img685.imageshack.us/i/capturedcran20100422133.png/

您对发生的事情有什么想法吗?
提前致谢!

Do you have any ideas about what is happening ?Thanks in advance !

这篇关于如何使用加速度计检测iPhone在空间中的移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:08