我正在使用三星銀河ace3來加速採樣。 getMinDelay()
給我10 000μs。當我將那段時間的加速度記錄到一個csv文件時,我會在正確的時間週期出現延遲,並伴隨着一個隨機抖動,這個抖動有時很大(0.5秒以上)。'onSensorChanged'加速度計採樣率抖動
有人知道如何改善這一點嗎?
這是我得到的樣本之間的延遲。
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mSensor;
private int cpt = 0;
private boolean start;
private List<String> records = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
public final File dir = new File("/mnt/extSdCard/test/");
public FileOutputStream afos = null;
public OutputStream stream = null;
public void startButton(View view) {
start = true;
cpt = 0;
mSensorManager.registerListener((SensorEventListener) this, mSensor, 10000); // 10000 µs -> 10 ms
openCsvFiles(dir, "data.csv");
stream = new BufferedOutputStream(afos);
}
public void stopButton(View view) {
for (String record: records) {
try {
stream.write(record.getBytes());
} catch (IOException e) {
}
}
try {
stream.flush();
stream.close();
afos.close();
start = false;
} catch (IOException e) {
Toast.makeText(MainActivity.this, "exception: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_SHORT).show();
}
@Override
public final void onSensorChanged(SensorEvent event) {
float ax, ay, az;
String axs, ays, azs, ts, line;
if (start) {
cpt++;
ax = event.values[0];
ay = event.values[1];
az = event.values[2];
ts = String.valueOf(event.timestamp);
long ns = android.os.SystemClock.elapsedRealtimeNanos();
line = ns+", "+ cpt+", "+ ts + "," + ax + "," + ay + "," + az + "\n";
records.add(line);
}
}
}
它不會好轉。此外,我想以固定速率採樣,不一定是100Hz。 – user1035648