[URGENT] Extra Data Points being logged by Accelerometer in Android

edited February 2018 in Android

Hello MbientLab,

We are currently using a MetaMotion C board to log data from the Accelerometer and Sensor Fusion separately (Quaternion, Linear Acceleration and Gravity).

It appears that there are extra data points being logged, but we are unsure of what this data is. Since these extra points slow down the download process, we would appreciate any insight on what this data could be, and how we can prevent these extraneous points from being logged.

Below, we have a minimum working Android example for the Accelerometer. The counter variable updates every time a accelerometer datapoint is being added, but the total is only about one third of the number of points being logged. This behavior is observed for the Sensor Fusion as well. We decided to log 3 types of data (Linear Acceleration, Gravity and Quaternion) for Sensor Fusion and the log shows that we logged about 3 times more data than the amount of data that we have actually collected. We did not observe this behavior in the C# API.

We would really appreciate your help on this and we hope to hear from you soon!

Here is a snippet of the Logcat from Android Studio:

Here is a minimum working example of the code to reproduce this behavior:

public class DataSensorFusionActivityExample extends AppCompatActivity implements ServiceConnection{
        public static final String METAWEAR_DEVICE_KEY = "MetaWearDeviceKey";
        private MetaWearBoard board;
        private BluetoothDevice btDevice;
        private SensorFusionBosch sensorFusion;
        private final static int DELAY_CONST = 1000;
        private static int counter = 0;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_data_sensor_fusion_example);
            btDevice = getIntent().getParcelableExtra(METAWEAR_DEVICE_KEY);
            getApplicationContext().bindService(new Intent(this, BtleService.class), this, BIND_AUTO_CREATE);
        }

    // Declared as static variable so no reference to outer Activity class
    // is held by this object
    private static Subscriber linAccelLogSubscriber = new Subscriber() {
        private static final long serialVersionUID = -9205392334730595800L;

        @Override
        public void apply(Data data, Object... env) {
            Acceleration linAccelCasted = data.value(Acceleration.class);
            Log.i("DataSensorFusion", "Linear Acceleration Logged: " + linAccelCasted.toString());
            counter += 1;
        }
    };

    public void startLoggingOnClick(View v) {
        try {
            SensorFusionBosch sensorFusionBosch = board.getModule(SensorFusionBosch.class);
            sensorFusionBosch.configure()
                    .mode(SensorFusionBosch.Mode.NDOF)
                    .accRange(SensorFusionBosch.AccRange.AR_16G)
                    .gyroRange(SensorFusionBosch.GyroRange.GR_2000DPS)
                    .commit();

            sensorFusion.linearAcceleration().addRouteAsync(new RouteBuilder() {
                @Override
                public void configure(RouteComponent source) {
                    source.log(linAccelLogSubscriber);
                }
            }).continueWith(new Continuation<Route, Void>() {
                @Override
                public Void then(Task<Route> task) throws Exception {
                    sensorFusion.linearAcceleration().start();
                    sensorFusion.start();
                    final Logging logging = board.getModule(Logging.class);
                    logging.clearEntries();
                    logging.start(true);
                    datahandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            logging.stop();
                        }
                    }, 1000);
                    return null;
                }
            });

        } catch (Exception e) {
            Log.e("Start Logging", "Unexpected Exception while requesting to start log sensorfusion data", e);
        }
    }

        public void stopLoggingOnClick(View v) {
            // stop the logger
            final Logging logging = board.getModule(Logging.class);
            logging.stop();
            sensorFusion.linearAcceleration().stop();
            sensorFusion.stop();
        }

        public void startDownloadOnClick(View v) {
        // download log data and send 100 progress updates during the download
            final Logging logging = board.getModule(Logging.class);
            logging.downloadAsync(100, new Logging.LogDownloadUpdateHandler() {

                @Override
                public void receivedUpdate(long nEntriesLeft, long totalEntries) {
                    Log.i("DataSensorFusion", "Progress Update = " + nEntriesLeft + "/" + totalEntries);
                }
            },
                    new Logging.LogDownloadErrorHandler(){
                        @Override
                        public void receivedError(Logging.DownloadError errorType, byte logId, Calendar timestamp, byte[] data) {
                            Log.e("DataSensorFusion", "ErrorType: " + errorType + " logId: " + Byte.toString(logId));
                        }
                    }).continueWithTask(new Continuation<Void, Task<Void>>() {
                @Override
                public Task<Void> then(Task<Void> task) throws Exception {
                    Log.i("DataSensorFusion", "Download completed");
                    Log.i("DataSensorFusion", "Number of Total DataPoints " + counter);
                    board.tearDown();
                    return null;
                }
            });
        }
}

Comments

  • Number of log entries is not the same as number of data points. Log entry count is only relevant for having an accurate download progress.

  • edited February 2018

    Hello Eric,

    Got it, no worries! Thank you so much for your help once again!

This discussion has been closed.