简体   繁体   English

Android Smartwatch采样频率

[英]Android Smartwatch sampling frequency

I've been using Sony Smartwatch 3 for recording accelerometer data on long time periods (8 hour on average). 我一直在使用Sony Smartwatch 3记录长时间(平均8小时)的加速度计数据。 Below is the main code block: ax,ay and az are arraylists for storing the sensor values and ta is an arraylist with the corresponding timestamps. 以下是主要代码块:ax,ay和az是用于存储传感器值的数组列表,而ta是具有相应时间戳的数组列表。

private void startMeasurement() {
    mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
    Log.d("lister", "listeners");
    Sensor accelerometerSensor = mSensorManager.getDefaultSensor(SENS_ACCELEROMETER);

    // Register the listener
    if (mSensorManager != null) {
        mSensorManager.registerListener(this, accelerometerSensor,25000);
    }
}

    @Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() == SENS_ACCELEROMETER){
        ax.add(event.values[0]);
        ay.add(event.values[1]);
        az.add(event.values[2]);
        ta.add(System.currentTimeMillis());
    }

}

public void write(){
    String timeStamp = new SimpleDateFormat("yyMMdd_HHmmss").format(Calendar.getInstance().getTime());
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/sensor_data/" + timeStamp + ".csv");
    try{
        FileWriter fw = new FileWriter(file);
        BufferedWriter buffWriter = new BufferedWriter(fw,50*1024);
        for(int i=0;i<ax.size();i++){
            buffWriter.write(String.valueOf(ax.get(i)));
            buffWriter.write(",");
            buffWriter.write(String.valueOf(ay.get(i)));
            buffWriter.write(",");
            buffWriter.write(String.valueOf(az.get(i)));
            buffWriter.write(",");
            buffWriter.write(String.valueOf(ta.get(i)));
            buffWriter.write("\n");
        }
        buffWriter.flush();
        buffWriter.close();
    }catch (IOException e){
        e.printStackTrace();
    }

}

When taking a look at the time difference between samples I notice an increase in that time after some time recording the data. 当查看样本之间的时间差时,我注意到在记录数据一段时间后该时间增加了。 In the link below you can see the plot of the time difference between samples in seconds. 在下面的链接中,您可以查看以秒为单位的样本之间的时间差图。 在此处输入图片说明

Why is it happening that the difference jumps abruptly to 50 after some time recording? 为什么一段时间记录后差异突然跳到50?

Ended up solving the problem by using Android's PowerManager and PARTIAL_WAKE_LOCK. 最终使用Android的PowerManager和PARTIAL_WAKE_LOCK解决了问题。 It consumes more battery but I really need the sampling frequency to be kept nearly constant. 它消耗更多的电池,但是我确实需要使采样频率保持几乎恒定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM