Skip to content Skip to sidebar Skip to footer

Android Sampling Rates Variation Of Hardware Sensors On Nexus 6P

I'm developing an Android app, for a research, and im reading several Sensor data like accelerometer, gyroscope, barometer etc. So I have 4 Nexus 6P devices all with the newest Fac

Solution 1:

I work with Android sensors a lot, and i can tell you the hardware is of variable quality. I usually use a filter if I need the results to be consistent across phones:

// Filter to remove readings that come too often
        if (TS < LAST_TS_ACC + 100) {
            //Log.d(TAG, "onSensorChanged: skipping");
            return;
        }

however this means you can only set the phones to match the lowest common denominator. If it helps I find that getting any more than 25hz is overkill for most applications, even medical ones.

It can also help to make sure any file writes you are doing are done off thread, and in batches, as writing to file is an expensive operation.

accelBuffer = new StringBuilder();
accelBuffer.append(LAST_TS_ACC + "," + event.values[0] + "," + event.values[1] + "," + event.values[2] + "\n");

if((accelBuffer.length() > 500000) && (writingAccelToFile == false) ){
                writingAccelToFile = true;

                AccelFile = new File(path2 +"/Acc/"  + LAST_TS_ACC +"_Service.txt");
                Log.d(TAG, "onSensorChanged: accelfile created at : " + AccelFile.getPath());

                File parent = AccelFile.getParentFile();
                if(!parent.exists() && !parent.mkdirs()){
                    throw new IllegalStateException("Couldn't create directory: " + parent);
                }

                //Try threading to take of UI thread

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        //Log.d(TAG, "onSensorChanged: in accelbuffer");
                        // Log.d(TAG, "run: in runnable");
                        //writeToStream(accelBuffer);
                        writeStringBuilderToFile(AccelFile, accelBuffer);
                        accelBuffer.setLength(0);
                        writingAccelToFile = false;

                    }
                }).start();

            }

Doing all of the above has got me reasonably good results, but it will never be perfect due to differences in the hardware.

Good luck!


Post a Comment for "Android Sampling Rates Variation Of Hardware Sensors On Nexus 6P"