如何使用加速度传感器在Android智能手机找到位移距离是多少? [英] How to find distance of displacement using accelerometer sensor in android smartphone?

查看:5882
本文介绍了如何使用加速度传感器在Android智能手机找到位移距离是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含加速传感器,指南针传感器和陀螺仪传感器的一款使用Android操作系统的智能手机。 我要计算位移使用这种传感器的距离。

I am having one android smart phone containing accelerator sensor, compass sensor and gyroscope sensor . i want to calculate the distance of displacement using this sensors.

我已经试图与基本方法,即,

I already tried with the basic method ie.,


final velocity = initial velocity + ( acceleration * time taken)
distance = time taken * speed

但我无法得到正确的位移。每次我试图为同排量我正在gettng不同势的结果。

But i am unable to get the correct displacement. Every time i tried for same displacement i am gettng diffrent results.

推荐答案

您可能会寻找寻找的公式为:

The equation you may be looking for looking for is:

Velocity = (Gravity*Acceleration)/(2*PI*freq)

这个方程(公制)正确的使用单位是

A correct use of units for this equation (metric) would be

Gravity = mm/s squared = 9806.65
Acceleration = average acceleration over 1 second
Frequency = Hz (of the acceleration waveform over 1 second)

例如,如果从加速度计全部3轴收集的数据,你会做以下获得加速度波形(原始值)三维空间:

For example, if you gathered data from all 3 axes of the accelerometer, you would do the following to get a acceleration waveform (in raw values) for a 3D space:

inputArray[i] = sqrt(X*X + Y*Y + Z*Z);

在收集了数据,只使用样品的量,将已收集的波形(如果有值之间的1ms的延迟只能使用1000个值)。

Once the data is collected, only use the amount of samples in the waveform that would have been collected (if there is a 1ms delay between values only use 1000 values).

由样本量在一起,除以添加的值,让您的平均值(你可能需要做的所有值正面的,如果加速计数据具有负值),你可以使用这个算法找到的平均之前做到这一点。

Add the values together and divide by the amount of samples to get your average (you may need to make all values positive if the accelerometer data have minus values) you could use this algorithm to do this before finding the average.

for(i = 0; i < 1000; i++){
    if(inputArray[i] < 0){
        inputArray[i] = inputArray[i] - (inputArray[i]*2);
    }
}

一旦你的加速度平均输出需要执行上述公式。

Once you have the acceleration average output you need to perform the equation above.

static double PI = 3.1415926535897932384626433832795;
static double gravity = 9806.65;

double Accel2mms(double accel, double freq){
    double result = 0;
    result = (gravity*accel)/(2*PI*freq);
    return result;
}

一个例子可以是,平均加速度是3 GS超过1秒的摆动:

An example could be that the average acceleration is 3 gs over 1 second in a swing:

注意::该计算基于正弦波形,因此频率将重新加速度计的物理运动的presentative采样率的不是频率

NOTE: This calculation is based on a sinusoidal waveform, so the frequency would be representative of the physical movement of the accelerometer not the frequency of the sampling rate

Accel2mms(3, 1);

3 GS 1秒以上1(1摆动一个方向)=4682.330468毫米/秒或4.7米的频率。

3 gs over 1 second with a frequency of 1 (1 swing in one direction) = 4682.330468 mm/s or 4.7 meters.

希望这有点像你在找什么。

Hope this is something like what you're looking for.

记住此计算是基于正弦的波形,但正在适于计算基于一个单一的运动(频率1),所以它可能不很精确。但在理论上应该工作。

Bear in mind this calculation is based on a sinusoidal waveform but is being adapted to calculate based on a single movement (frequency 1) so it may not be very accurate. But in theory should work.

这篇关于如何使用加速度传感器在Android智能手机找到位移距离是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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