问题描述:

I have a really weird issue on my Samsung Galaxy Nexus - I try to read out some sensor values e.g. from the gyroscope. Very basic code, just a sensor listener putting the value in a list after doing simple integration over time.

When I run the code on a Nexus S for about 60 seconds, I can register about 60.000 sensor events (SENSOR_DELAY_FASTEST) but if I ran it on the Galaxy Nexus, I only get about 6000 values in 60 seconds.

Is there a way to increase this? I really need more sensor data for what I'm doing and apart from the device, the only difference is the OS version: 4.0.2 on the Galaxy Nexus - 4.0.3 on the Nexus S.

Any advice would be appreciated!

Edit - the code:

SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);

LogSensorEventListener listener = new LogSensorEventListener(

SensorLoggerActivity.this, Sensor.TYPE_GYROSCOPE);

sm.registerListener(listener, sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE),

SensorManager.SENSOR_DELAY_FASTEST);

LogSensorEventListener is also a very basic implementation of the SensorEventListenerInterface:

@Override

public void onSensorChanged(SensorEvent event) {

final float dT = (event.timestamp - mTimestamp) / 1000000000.f;

if (dT < 1) { // just a fix for the first step

mRelZ += event.values[2] * dT;

list.add(mRelZ);

list2.add(event.timestamp);

}

mTimestamp = event.timestamp;

mRelZ is initially set to 0 and the two lists should keep track of time and measured value. If finished with my measurement (clicking a button) the values are written to file:

 try {

for (int i = 0; i < list.size(); i++) {

long time = list2.get(i);

if (mStartTime < 0) {

mStartTime = time;

time = 0;

} else {

time = time - mStartTime;

}

float timef = time / 1000000000.0f;

sb.append(timef);

sb.append(";");

sb.append(Math.toDegrees(list.get(i)));

sb.append("\n");

}

mOutFileStream.write(sb.toString().getBytes());

mOutFileStream.flush();

mOutFileStream.close();

} catch (IOException e) {

}

网友答案:

Android devices have no standards for how and when they report sensor changes. For instance, some devices won't report changes unless there ARE changes (e.g. the device is moving). Some devices will report tons of changes and others less changes even if you use the delay e.g. SensorManager.SENSOR_DELAY_FASTEST.

相关阅读:
Top