Android的加速度计采样率/延迟稳定 [英] Android accelerometer sampling rate/delay stabilization
问题描述
我试图通过使用从加速度计和用该方法onTouch的数据,以检测一个抽头的力的强度
I'm trying to detect the force strength of a tap by using the data from the accelerometer and with the method onTouch.
据我知道,对于加速最快的采样频率为200-202Hz,而是试图以匹配加速度计数据的onTouch事件的时间戳和峰值时,这种变化是给我的问题。
As far as I know, the fastest sampling frequency for the accelerometer is 200-202Hz, but this variability is giving me problems when trying to match the timestamps for the onTouch event and the peak in the accelerometer data.
有没有办法来稳定加速度计的读数,以避免这个问题?像控制特定线程什么?
Is there a way to stabilize the readings of the accelerometer to avoid this problem? Like controlling the specific thread or something?
推荐答案
如果你想匹配的硬件提供的时间(event.timestamp)和系统时间,你可以通过调整时间做到这一点。
If you want to match the hardware-provided time (event.timestamp) and the System time you can do this by adjusting the times.
一般的时间是不一样的,但他们只是通过毫秒恒定量不同。我建议你打印出两次并进行比较。然后你会发现偏移量是什么:
Usually the times are not the same, but they just differ by a constant amount of milliseconds. I suggest you to print out both times and compare them. You will then notice what the offset is:
在我的问题,Ormi734建议使用以下code:
In my question, Ormi734 suggested to use the following code:
private long timeDiff = 0l; // this will be used to adjust the offset between the times
private boolean offsetDetermined = false;
@Override
public void onSensorChanged(SensorEvent event) {
// just determine the offset once, since it should remain constant
// you could also adjust it every n samples if it needs to be really accurate
if (!offsetDetermined) {
long MiliTime = System.currentTimeMillis();
long NanoTime = event.timestamp;
timeDiff = MiliTime - NanoTime / 1000000;
log.info("Synchornizing sensor clock. Current time= " + MiliTime+ ", difference between clocks = " + timeDiff);
offsetDetermined = true;
}
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
long ts = event.timestamp / 1000000 + timeDiff;
// do your stuff here
}
<一个href=\"http://stackoverflow.com/questions/15647841/accelerometer-logger-experiencing-occasional-long-delays-between-frames?noredirect=1#comment36392316_15647841\">Accelerometer记录:在经历帧之间偶有长期拖延
这篇关于Android的加速度计采样率/延迟稳定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!