MetaWearC timing issue

I am collecting streamed 200Hz packed acceleration data from a MetawearC sensor and also a MetaMotionC sensor (at different times). When I use the recommended approach to calculate the time by incrementing the timestamp by 5ms per value, the MetaWearC times are incorrect, while the MetaMotionC times are okay.

If I use a step value of 16.5ms for the MetaWearC sensor data, the times are correct.

What is the likely reason for this?

Comments

  • Post your code

  • public void onServiceConnected(ComponentName name, IBinder service) {
    ///< Typecast the binder to the service's LocalBinder class
    serviceBinder = (BtleService.LocalBinder) service;

        BluetoothManager btManager= (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
        BluetoothDevice btDevice= btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS);
    
        mwBoard= serviceBinder.getMetaWearBoard(btDevice);
        mwBoard.connectAsync().onSuccessTask(task -> {
            mwBoard.readBatteryLevelAsync()
                    .continueWith(info -> {
                        batteryLevelPercent = info.getResult();
                        if (batteryLevelPercent <= minBatteryLevel)
                            batteryStateText = "Battery Level Low, please change battery";
                        else
                            batteryStateText = "Battery Level: " + info.getResult() + "%";
    
                        Log.i(TAG, batteryStateText);
                        runOnUiThread(new Runnable() {
                            public void run() {
                                batteryLevel.setText(batteryStateText);
                            }
                        });
                        return null;
                    });
    
            accelerometer = mwBoard.getModule(Accelerometer.class);
            accelerometer.configure()
                    .odr(freq)
                    .range(4f)
                    .commit();
    
            runOnUiThread(new Runnable() {
                public void run() {
                    connectState.setText("Connected");
                    startAcc.setVisibility(View.VISIBLE);
                    stopAcc.setVisibility(View.VISIBLE);
                }
            });
            return accelerometer.packedAcceleration().addRouteAsync(source -> {
                source.stream((data, env) -> {
                    processAccelerationData(data, newFile);
                });
            });
            }).continueWith((Continuation<Route, Void>) task -> {
            if (task.isFaulted()) {
                Log.e(TAG, mwBoard.isConnected() ? "Error setting up route" : "Error connecting", task.getError());
                Log.i(TAG, "StartActivity: Faulted and Reset");
    
                runOnUiThread(new Runnable() {
                    public void run() {
                        connectState.setText("Failed to Connect, try a Reset");
                    }
                });
            } else {
    
                Log.i(TAG, "StartActivity: Connected");
                debug = mwBoard.getModule(Debug.class);
            }
    
            return null;
        });
    }
    
    private Void processAccelerationData(Data data, File file) {
        try {
            String newLine = "";
            Long time = data.timestamp().getTimeInMillis();
            if (firstTime == 0) {
                Log.i(TAG, "StartActivity: Processing");
                firstTime = time;
            }
            Long diff = time - firstTime;
            String s = diff.toString() ;
    
            Double x = (double)data.value(Acceleration.class).x();
            Double y = (double)data.value(Acceleration.class).y();
            Double z = (double)data.value(Acceleration.class).z();
            s = s +  "," + String.format("%.5f", x);
            s = s + "," +  String.format("%.5f",y);
            s = s + "," +  String.format("%.5f",z);
    
            count++;
            if (count > 0)
                newLine = s;
    
            writeDataToFile(file, newLine);
    
            Long countVal = count;
            runOnUiThread(new Runnable() {
                public void run() {
                    sampleCount.setText(countVal.toString());
                }
            });
        } catch (Exception e) {
            Log.e(TAG, "StartActivity: processAccelerationData() error - ", e);
        }
        return null;
    }
    
  • Noted.

    What is the default maximum Connection interval and why do the MetawearC and MetaMotionC boards perform differently?

  • edited July 2018

    Default connection intervals are whatever the central device wants them to be; there is no set default value.

    MetaWearC and MetaMotionC boards have different hardware and run different firmware.

This discussion has been closed.