Android TYPE_LINEAR_ACCELERATION 传感器 - 它显示什么? [英] Android TYPE_LINEAR_ACCELERATION sensor - what does it show?

查看:28
本文介绍了Android TYPE_LINEAR_ACCELERATION 传感器 - 它显示什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于汽车加速跟踪的应用程序.我使用标准加速度计,事先在特定位置校准.

I am developing application for car acceleration tracking. I used standard accelerometer, calibrating it in specific position beforehand.

然后,假设手机的方向没有改变,我记录了指定时间的加速度计数据并计算了移动参数,其中之一是测试结束时汽车的速度.

Then, assuming phone's orientation is not changing, I logged the accelerometer data for a specified time and calculated move parameters, one of which is the car's speed at the end of the test.

在笔直的水平道路上效果很好:误差在百分之几.

It works rather well, on a straight, horizontal road: error of a few percent.

但后来我发现,在 API 级别 10 中有一个名为 TYPE_LINEAR_ACCELERATION 的虚拟传感器,据我所知,它必须满足我的需求:过滤重力、方向变化 -所以我可以使用它并获得移动设备的纯线性加速度.

But then I found out, that in API-level 10 there is a virtual sensor called TYPE_LINEAR_ACCELERATION and, as far as I understand, it must do what I need: filter gravity, orientation changes - so I may use it and get pure linear acceleration of mobile device.

但在现实生活中..

我做了一个简单的应用程序,做了一个小测试:

I made a simple application, that does a little test:

//public class Accelerometer implements SensorEventListener { ...
public void onSensorChanged(SensorEvent se) 
{
    if(!active)
        return;

    lastX = se.values[SensorManager.DATA_X];
    lastY = se.values[SensorManager.DATA_Y];
    lastZ = se.values[SensorManager.DATA_Z];
    long now = System.currentTimeMillis();
    interval = now - lastEvetn;
    lastEvetn = now;
    out.write(Float.toString(lastX) + ";" + 
                    Float.toString(lastY) + ";" + 
                    Float.toString(lastZ) + ";" + 
                    Long.toString(interval) + "
");
}

我用以下参数绑定了一个监听器:

I bind a listener with the following parameters:

  mSensorManager.registerListener(linAcc,
                mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                SensorManager.SENSOR_DELAY_GAME);

它工作正常,但是当我分析数据转储时,计算速度如 V = V0 + AT,其中 V0 = 0 首先,然后 - 间隔速度之前这个,A = 加速度(SQRT(x*x+y*y+z*z))(t = 间隔时间),最终我得到一个非常低的速度——比实际速度低三倍.

It works OK, but when I analyzed data dump, calculating speed like V = V0 + AT, where V0 = 0 at first, then - speed of interval before this, A = acceleration (SQRT (x*x+y*y+z*z)) (t = time of interval), eventually I get a very low speed - three times less than real speed.

将传感器类型更改为 TYPE_ACCELEROMETER,校准并使用相同的公式来计算速度 - 我得到了很好的结果,更接近现实.

Changing Sensor type to TYPE_ACCELEROMETER, calibrating and using same formula to calculate speed - I get good results, much closer to reality.

所以,问题是:

Sensor.TYPE_LINEAR_ACCELERATION 到底显示了什么?

我哪里错了,或者 Sensor.TYPE_LINEAR_ACCELERATION 实现有什么问题?

Where am I wrong, or is something wrong with Sensor.TYPE_LINEAR_ACCELERATION implementation?

我用的是三星 Nexus S 手机.

I used Samsung Nexus S phone.

推荐答案

非常有趣的问题!!!

我正在开发与您的应用程序类似的东西.我对 TYPE_LINEAR_ACCELERATION 的发现并不让我满意.

I'm developing somethig similar to your application. What i found about TYPE_LINEAR_ACCELERATION isn't happy for me.

1) TYPE_LINEAR_ACCELERATION、TYPE_GRAVITY、ecc 仅适用于 Android 2.3(及更高版本)所以我有 Android 2.2,我无法测试它们.

1) TYPE_LINEAR_ACCELERATION, TYPE_GRAVITY, ecc are implemented only for Android 2.3 (and up) So i have Android 2.2 and i can't test them.

2) TYPE_LINEAR_ACCELERATION 不是那么准确,因为在减去重力时有一些简单的问题.实际上是一种传感器融合",它使用加速度计和方向来知道重力的方向,然后是潜艇.

2) TYPE_LINEAR_ACCELERATION isn't so accurate as it would be, because there are some simple problem when substract the gravity. In fact is a "sensor fusion" that uses accelerometer and orientation to know where is directed the gravity and then subs. it.

在这里我找到了一个非常有用的答案来解释它:

Here i found a very usefull answer that explain it:

https://groups.google.com/forum/#!主题/android-developers/GOm9yhTFZaM

TYPE_ACCELEROMETER 使用加速度计且仅使用加速度计.它返回原始加速度计事件,在全部.

TYPE_ACCELEROMETER uses the accelerometer and only the accelerometer. It returns raw accelerometer events, with minimal or no processing at all.

TYPE_GYROSCOPE(如果存在)使用陀螺仪并且仅使用陀螺仪.像上面一样,它返回原始事件(角速度 un rad/s),没有处理(无偏移/比例补偿).

TYPE_GYROSCOPE (if present) uses the gyroscope and only the gyroscope. Like above, it returns raw events (angular speed un rad/s) with no processing at all (no offset / scale compensation).

TYPE_ORIENTATION 已弃用.它将方向返回为 yaw/俯仰/滚转度数.它没有很好的定义,只能是当设备没有滚动"时依赖.该传感器使用加速度计和磁力计的组合.边际上使用 SensorManager 的助手可以获得更好的结果.这个传感器经过大量处理".

TYPE_ORIENTATION is deprecated. It returns the orientation as yaw/ pitch/roll in degres. It's not very well defined and can only be relied upon when the device has no "roll". This sensor uses a combination of the accelerometer and the magnetometer. Marginally better results can be obtained using SensorManager's helpers. This sensor is heavily "processed".

TYPE_LINEAR_ACCELERATION、TYPE_GRAVITY、TYPE_ROTATION_VECTOR 是融合"传感器分别返回线性加速度,重力和旋转矢量(四元数).没有定义如何这些都得到了执行.在某些设备上,它们以硬件实现,在某些设备上,他们使用加速度计 + 磁力计,他们使用陀螺仪的其他一些设备.

TYPE_LINEAR_ACCELERATION, TYPE_GRAVITY, TYPE_ROTATION_VECTOR are "fused" sensors which return respectively the linear acceleration, gravity and rotation vector (a quaternion). It is not defined how these are implemented. On some devices they are implemented in h/w, on some devices they use the accelerometer + the magnetometer, on some other devices they use the gyro.

在 Nexus S 和 Xoom 上,目前不使用陀螺仪.他们的行为好像没有可用的陀螺仪,就像在 Nexus One 或 Droid 上一样.我们是计划在未来的版本中改善这种情况.

On Nexus S and Xoom, the gyroscope is currently NOT used. They behave as if there was no gyro available, like on Nexus One or Droid. We are planing to improve this situation in a future release.

目前,利用陀螺仪的唯一方法是使用TYPE_GYROSCOPE 并手动集成输出.

Currently, the only way to take advantage of the gyro is to use TYPE_GYROSCOPE and integrate the output by hand.

希望能帮到你,

马蒂亚斯

无论如何,在网络上的各个地方,我都没有找到关于手机传感器及其潜力的最佳词,因为这些词并不准确...

Anyway, in various place on the web i found no best word about phone sensor and their potential, due to the fact that aren't accurate...

使用卡尔曼滤波器可以达到更高的精度,但我不知道如何...

Some more precision can be reached using Kalman filter, but i have no idea how...

这篇关于Android TYPE_LINEAR_ACCELERATION 传感器 - 它显示什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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