SENSOR_TYPE_GRAVITY的工作机制来获得它的数据是什么? - Android电子 [英] What is the working mechanism of SENSOR_TYPE_GRAVITY to get its data? - Android

查看:941
本文介绍了SENSOR_TYPE_GRAVITY的工作机制来获得它的数据是什么? - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3-D加速度矢量(A,B,C)来自Android手机的加速度计获得的。

我要计算这个向量(A,B,C)和重力矢量,这点正好向下之间的角度。

我注意到在机器人,有电话的上下文中获得重力矢量坐标系统,而不是世界坐标系统的一种方式。通过简单地使用传感器类型 SENSOR_TYPE_GRAVITY ,我可以得到三维重力矢量(D,E,F)。因为两者的载体是相同的坐标系下,该手机的坐标系。通过简单的向量的内积,其角度可以很容易找到。

找到这个角度,即使我们从电话移动坐标系到现实世界坐标系后,将角保持不变。

我的问题:

什么是背后的工作机制 SENSOR_TYPE_GRAVITY

我不认为有是衡量重力其他硬件。因此,它仅仅是谁测量重力acclerometer。重力如何萃取所得accleration我们?

我问,因为我关心的是获得重力这种方法的准确性。

如果它是不准确的,我可以实现LPF出由我自己来过滤直流分量,重力。我不知道是否从 SENSOR_TYPE_GRAVITY 得到它更准确的比我做我自己。

================================== UPDATES ============ ===========================

只是为了澄清,我可以用下面的$ C $正确地获得加速度和重力数据CS?

通过正确,我的意思做的加速度和重力同属一个特定的时刻?我需要在同一时间瞬间使用的值。那么,加速度时间的情况= 13:12:00和重力是在稍后的时间,说时间= 13:12:01不希望

 公共无效onSensorChanged(SensorEvent事件){    如果(event.sensor.getType()== Sensor.TYPE_ACCELEROMETER){
        加速度[0] = event.values​​ [0];
        加速度[1] = event.values​​ [1];
        加速度[2] = event.values​​ [2];
    }    如果(event.sensor.getType()== Sensor.TYPE_GRAVITY){
        重力[0] = event.values​​ [0];
        重力[1] = event.values​​ [1];
        重力[2] = event.values​​ [2];
    }}


解决方案

这三个传感器Sensor.TYPE_ACCELEROMETER,Sensor.TYPE_GRAVITY和Sensor.TYPE_LINEAR_ACCELERATION由公式相关

 Sensor.TYPE_ACCELEROMETER=Sensor.TYPE_GRAVITY+Sensor.TYPE_LINEAR_ACCELERATION

如果您注册了所有三个更新,你发现的是,Sensor.TYPE_ACCELEROMETER总是最先到达,其次是Sensor.TYPE_GRAVITY和Sensor.TYPE_LINEAR_ACCELERATION,并且该值始终满足该方程。在内部,Android是使用滤波,并且特别是卡尔曼滤波器,分开的两个

一个低通滤波器是做类似事情的简单方式。然而,花了很多心思会已经进入了Android机制,所以我敢肯定,如果一个低通滤波器是更好的,那么Android的就已经实施了。

I have a 3-D acceleration vector (a, b, c) obtained from an Android phone accelerometer.

I wish to calculate the angle between this vector (a, b, c) and the gravity vector, which points exactly downwards.

I notice that in Android, there is a way of getting gravity vector under the context of the phone coordinate system instead of the world coordinate system. By simply use sensor type SENSOR_TYPE_GRAVITY, I can get the 3-D gravity vector (d, e, f). Since both vectors are under the same coordinate system, the phone coordinate system. By simple vector inner product, their angle can be easily found.

After finding this angle, even if we move from the phone coordinate system to the real world coordinate system, the angle remains unchanged.

My question:

What is the working mechanism behind the SENSOR_TYPE_GRAVITY?

I don't think there is another hardware that measures the gravity. Thus, it is just the acclerometer who measures the gravity. How is the gravity extracted our of the resultant accleration?

I am asking because I am concerned with the accuracy of this way of getting the gravity.

If it is inaccurate, I can implement a LPF to filter the DC component, the gravity, out by myself. I am not sure whether getting it from SENSOR_TYPE_GRAVITY is more accurate than I do it myself.

================================== UPDATES =======================================

Just to clarify, can I get the BOTH acceleration and gravity data correctly with the following codes?

By correctly, I mean do the acceleration and the gravity belong to one same particular time instant? I need to use the values at ONE time instant. So the situation where the acceleration is for time=13:12:00 and the gravity is for a later time, say time=13:12:01 is NOT desired.

public void onSensorChanged(SensorEvent event) { 

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 
        acceleration[0] = event.values[0];
        acceleration[1] = event.values[1];
        acceleration[2] = event.values[2];
    }

    if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
        gravity[0] = event.values[0];
        gravity[1] = event.values[1];
        gravity[2] = event.values[2];
    }

}

解决方案

The three sensors Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_GRAVITY and Sensor.TYPE_LINEAR_ACCELERATION are related by the equation

"Sensor.TYPE_ACCELEROMETER" =  "Sensor.TYPE_GRAVITY" + "Sensor.TYPE_LINEAR_ACCELERATION"

If you register for updates for all three, what you find is that Sensor.TYPE_ACCELEROMETER always arrives first, followed by Sensor.TYPE_GRAVITY and Sensor.TYPE_LINEAR_ACCELERATION, and that the values always satisfy that equation. Internally, Android is using filtering, and in particular a Kalman filter, to separate the two.

A low pass filter is a simple way of doing something similar. However, a lot of thought will have gone into the Android mechanism, so I'm sure that if a low pass filter was better, then Android would have implemented that.

这篇关于SENSOR_TYPE_GRAVITY的工作机制来获得它的数据是什么? - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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