Galaxy Nexus:对更多传感器进行采样时,传感器采样率变得更快 [英] Galaxy Nexus: Sensor Sampling Rate becomes faster when sampling more Sensors

查看:66
本文介绍了Galaxy Nexus:对更多传感器进行采样时,传感器采样率变得更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Samsung Galaxy Nexus(带有Android 4.0)中尽可能快地读出传感器值.为此,我使用不同的传感器和采样率进行了一些实验,并得出了非常奇怪的行为.当我仅使用Acc-Sensor时,采样率约为50Hz.但是,当我还使用陀螺仪传感器(或磁场传感器)时,加速度传感器的采样率会增加,并且两者的采样率都在90到100 Hz之间.传感器延迟的更改(例如,从SENSOR_DELAY_FASTEST更改为SENSOR_DELAY_UI)对采样率没有影响,并且当我还添加磁场传感器时,所有三个传感器的采样率都很高(90-100Hz). 另一个奇怪的事情是,来自三个传感器的值总是以相同的时间戳到达(有时一个具有1或2 ms的差异,而另外两个具有完全相同的时间戳). 我还使用Android-NDK测试了相同的行为,并且存在完全相同的行为,包括更改采样率(使用ASensorEventQueue_setEventRate())无效.

I'm trying to read out sensor values as fast as possible from a Samsung Galaxy Nexus (with Android 4.0). For this I did a few experiments using different sensors and sampling rates and figured out a very weird behaviour. When I use only the Acc-Sensor the sampling-rate is about 50Hz. But when I also use the Gyro-Sensor (or magnetic-field-sensor) the sample-rate of the Acc-Sensor increases and both have a sample-rate of between 90 and 100 Hz. A change of the sensor-delay (e.g. from SENSOR_DELAY_FASTEST to SENSOR_DELAY_UI) has no effect on the sampling rate and when I add also the magnetic-field-sensor all three sensors have a high sampling-rate (90-100Hz). Another strange thing is that the values from the three sensors arrive always with the same timestamp (sometimes one has 1 or 2 ms difference, but the other two have exactly the same timestamp). I also tested the same with Android-NDK and there is exactly the same behaviour including that a change of the sampling-rate (using ASensorEventQueue_setEventRate()) has no effect.

我的一个朋友在HTC Desire HD(配备Android 2.3且只有acc-和磁传感器,因为他没有陀螺仪)上尝试了相同的操作,并且传感器的采样率彼此不同,并且acc传感器的采样率与磁传感器的使用无关(这是我期望的正常行为).

A friend of mine tried the same things on a HTC Desire HD (with Android 2.3 and only acc- and magnetic-sensor, since he has no gyro) and there the sampling-rate of the sensors was different from each other and the sampling-rate of the acc-sensor was independent on the use of the magnetic sensor (that's what I would expect as normal behaviour).

如果另外使用其他传感器,为什么会更快地成为acc传感器?有人发现类似的行为吗?这是一个错误吗?还是我的代码有错误?

Why becomes the acc-sensor faster if other sensors are used additionally? Did someone figure out a similar behaviour? Is this a bug? Or maybe a bug with my code?

这是我用于Android-SDK测试的代码(我计算了对每个传感器执行1000次测量所需的时间):

Here is the code I used for testing with Android-SDK (I calculate the time it takes for doing 1000 measures on each of the sensors):

package de.tum.sdktest;

import java.util.ArrayList;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class TestSDKActivity extends Activity implements SensorEventListener {

private SensorManager mSensorManager;
private Sensor mAccSensor;
private Sensor mGyroSensor;
private Sensor mMagSensor;

private int accCounter = 0;
private long lastAccTime = 0;

private int gyroCounter = 0;
private long lastGyroTime = 0;

private int magCounter = 0;
private long lastMagTime = 0;

private int measuresPerInterval = 1000;

private ArrayList<Float> accValues;
private ArrayList<Float> gyroValues;
private ArrayList<Float> magValues;


private static final String TAG = "TestSDKActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    accValues = new ArrayList<Float>();
    gyroValues = new ArrayList<Float>();
    magValues = new ArrayList<Float>();

    mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    TextView  tv = new TextView(this);
    tv.setText("Hello World!!!");
    setContentView(tv);
}

protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(this, mAccSensor, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, mGyroSensor, SensorManager.SENSOR_DELAY_UI);
    mSensorManager.registerListener(this, mMagSensor, SensorManager.SENSOR_DELAY_UI);
}


public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // TODO Auto-generated method stub

}


public synchronized void onSensorChanged(SensorEvent event) {



    if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
    {
        if(accCounter == 0 || accCounter == measuresPerInterval)
        {
            String s = String.valueOf("acc: "+(event.timestamp-lastAccTime)/1000000000.0);
            lastAccTime = event.timestamp;
            Log.i(TAG, s);
            accCounter = 0;
            accValues.clear();
        }
        accValues.add(event.values[0]);

        accCounter++;
    }
    else if(event.sensor.getType() == Sensor.TYPE_GYROSCOPE)
    {
        if(gyroCounter == 0 || gyroCounter == measuresPerInterval)
        {
            String s = String.valueOf("gyro: "+(event.timestamp-lastGyroTime)/1000000000.0);
            lastGyroTime = event.timestamp;
            Log.i(TAG, s);
            gyroCounter = 0;
        }
        gyroValues.add(event.values[0]);

        gyroCounter++;
    }
    else if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
    {
        if(magCounter == 0 || magCounter == measuresPerInterval)
        {
            String s = String.valueOf("mag: "+(event.timestamp-lastMagTime)/1000000000.0);
            lastMagTime = event.timestamp;
            Log.i(TAG, s);
            magCounter = 0;
        }
        magValues.add(event.values[0]);

        magCounter++;
    }

}

}

推荐答案

您看到的是Invensense提供的智能传感器"的结果,而绝对不是来自应用程序级代码中的错误.这是平台软件实施中的一个错误,该错误在该设备的肠道中处处处于较低位置.

What you are seeing is a result of the "smart sensor" from Invensense, and is definitely not from a bug in your application level code. It's a bug in the implementation of platform software much lower down in the bowels of this device.

此手机上的Invensense MPU3050芯片具有除了其MEM陀螺仪外,还包括一个运动处理单元.它控制加速度计和磁力计,合并数据,运行传感器融合将数据发送回Android ,您的应用会在其中看到数据.

The Invensense MPU3050 chip on this phone has a Motion Processing Unit in addition to its MEMs gyroscope. It controls the accelerometer and magnetometer, coalesces the data, runs the sensor fusion, and sends the data back up to Android, where your app sees it.

摘录自 MPU3050数据表 :

嵌入式数字运动处理器(DMP)位于MPU-30X0内,可以分 来自主机处理器的运动处理算法. DMP 从加速度计,陀螺仪和其他传感器获取数据 例如磁力计,并处理数据. [..snip ...] DMP的目的是卸载 主处理器的时序要求和处理能力都如此

The embedded Digital Motion Processor (DMP) is located within the MPU-30X0 and offloads computation of motion processing algorithms from the host processor. The DMP acquires data from accelerometers, gyroscopes, and additional sensors such as magnetometers, and processes the data. [..snip...]The purpose of the DMP is to offload both timing requirements and processing power from the host processor

这篇关于Galaxy Nexus:对更多传感器进行采样时,传感器采样率变得更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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