Read gyro/accelerometer data with lower sampling rate

Is there a way to read gyro and accelerometer sensor data every few seconds (for instance every 2 or 3 or 4 seconds) ? Below are the only possible values which is not of use for me.
enum OutputDataRate {
ODR_25_HZ,
ODR_50_HZ,
ODR_100_HZ,
ODR_200_HZ,
ODR_400_HZ,
ODR_800_HZ,
ODR_1600_HZ,
ODR_3200_HZ;

}

Comments

  • Set ODR to minimum and add the Time processor before stream.
    bmi160GyroModule.routeData()
    .fromAxes()
    .process(new Time(Time.OutputMode.ABSOLUTE, 2000))
    .stream("gyro_stream").commit()
  • Hi @propan, thanks for the help. The above code is not fetching data every 2 seconds, I am getting data every 50 milliseconds. Below is my code snippet.
    try {
    final Bmi160Gyro gyroModule = mwBoard.getModule(Bmi160Gyro.class);
    final Logging loggingModule = mwBoard.getModule(Logging.class);
    if (mySwitch.isChecked()) {
    if (!gyroSetup) {
    gyroModule.routeData().fromAxes().stream("gyroAxisSub")
    .commit().onComplete(new CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    result.subscribe("gyroAxisSub", new RouteManager.MessageHandler() {
    @Override
    public void process(Message msg) {
    final CartesianFloat spinData = msg.getData(CartesianFloat.class);
    Log.i("test", spinData.toString());
    ((TextView) findViewById(R.id.textView7)).setText(spinData.toString() + Units.DEGS_PER_SEC);
    }
    });
    }
    });
    gyroModule.routeData().fromYAxis().log("gyroAxisLogger").commit()
    .onComplete(new CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    result.setLogMessageHandler("gyroAxisLogger", new RouteManager.MessageHandler() {
    @Override
    public void process(Message msg) {
    final float ySpinData = msg.getData(Float.class);
    Log.i("!test", String.format("Log Gyro: %.3f", ySpinData));
    }
    });

    loggingModule.startLogging();


    gyroModule.configure().setOutputDataRate(Bmi160Gyro.OutputDataRate.ODR_25_HZ)
    .setFullScaleRange(Bmi160Gyro.FullScaleRange.FSR_250);
    gyroModule.routeData()
    .fromAxes()
    .process(new Time(Time.OutputMode.ABSOLUTE, 2000))
    .stream("gyro_stream").commit();

    gyroModule.start();
    }
    });
    gyroSetup = true;
    } else {
    loggingModule.startLogging();
    gyroModule.configure().setOutputDataRate(Bmi160Gyro.OutputDataRate.ODR_25_HZ)
    .setFullScaleRange(Bmi160Gyro.FullScaleRange.FSR_125)
    .commit();
    gyroModule.start();
    }
    } else {
    loggingModule.stopLogging();
    gyroModule.stop();
    }
    } catch (UnsupportedModuleException e) {
    Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
    }
  • edited November 2016
    pradeepvr 
    You need to add the filter before the stream or logging that you are using. It will pass the data further every 2 seconds. Check in the API docs how filters are working.

    in your case put it before .stream("gyroAxisSub")
    and .log("gyroAxisLogger")

    .process(new Time(Time.OutputMode.ABSOLUTE, 2000))
This discussion has been closed.