Tap detection with BMI160Accelerometer Metawear v3.0

Hi,

I am using Metawear RPRO which has BMI160 accelerometer+gyro, want to do tap detection.
have been using Metawear api v2.3.0, but tap detection is not available with earlier so updated to v3, but in v3 lots of classes and methods have been either renamed or removed.
for e.g can't find AsyncOperation, RouteManager, connectionStatehandler, can someone help me with sample code for streaming data from sensor.

Thanks

Comments

  • edited March 2017
    Documentation, sample code, etc. are provided in the api v3 thread:

    The project README has a section highlighting some important changes:

    If migrating to v3 is not something you have the time for at the moment, I suggest upgrading to the latest v2 release instead.
  • Thanks so much Eric.
    Trying in v2, sorry for being so naive, but not able to detect tap.In debugging also nothing caught up.

    stateHandler = new ConnectionStateHandler() {
    @Override
    public void connected() {
    try {
    ledModule = mwBoard.getModule(Led.class);
    accelModule = mwBoard.getModule(Bmi160Accelerometer.class);
    loggingModule = mwBoard.getModule(Logging.class);
    gyroModule = mwBoard.getModule(Bmi160Gyro.class);

    } catch (UnsupportedModuleException e) {
    e.printStackTrace();
    }
    //Compound Switch Button//
    final Switch accel_switch = (Switch) findViewById(R.id.accel_switch);
    accel_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {




    //Accelerometer & Gyro Routing//
    accelModule.setOutputDataRate(ACC_FREQ);
    accelModule.setAxisSamplingRange(ACC_RANGE);
    gyroModule.configure()
    .setOutputDataRate(OutputDataRate.ODR_50_HZ)
    .setFullScaleRange(FullScaleRange.FSR_2000)
    .commit();

    AsyncOperation routeManagerResultAccel = accelModule.routeData().fromAxes()
    .stream(STREAM_KEY).commit();

    AsyncOperation routeManagerResultGyro = gyroModule.routeData().fromAxes().stream(GYRO_STREAM_KEY).commit();
    routeManagerResultAccel.onComplete(new CompletionHandler() {
    @Override
    public void success(RouteManager result) {
    result.subscribe(STREAM_KEY, new RouteManager.MessageHandler() {
    @Override
    public void process(Message msg) {

    Log.i(TAG, String.format("Accelerometer %s %s", msg.getData(CartesianFloat.class), msg.getTimestampAsString()));
    sensorMsg(String.format(msg.getData(CartesianFloat.class).toString()), "accel");



    routeManagerResultGyro.onComplete(new CompletionHandler() {
    @Override
    public void success(RouteManager result) {
    result.subscribe(GYRO_STREAM_KEY, new RouteManager.MessageHandler() {
    @Override
    public void process(Message msg) {
    Log.i(TAG, String.format("Gyroscope %s %s", msg.getData(CartesianFloat.class), msg.getTimestampAsString()));

    sensorMsg(String.format(msg.getData(CartesianFloat.class).toString()), "gyro");



    accelModule.configureTapDetection().setThreshold(.5f)
    .setShockTime(Bmi160Accelerometer.TapShockTime.TST_50_MS).commit();

    // Route data from the chip's tap detector
    AsyncOperation routeManagerResultTap = accelModule.routeData().fromTap()
    .stream("Tap").commit();
    routeManagerResultTap.onComplete(new CompletionHandler() {
    @Override
    public void success(RouteManager result) {
    result.subscribe("tap", new RouteManager.MessageHandler() {
    @Override
    public void process(Message msg) {
    TapResponse response= msg.getData(TapResponse.class);
    Log.i("tap",msg.getData().toString());
    switch(response.type()) {
    case SINGLE:
    Log.i("MainActivity", "Single tap");
    break;
    case DOUBLE:
    Log.i("MainActivity", "Double tap");
    break;

    }
    }
    });
    }
    });

    accelModule.enableTapDetection(TapType.DOUBLE);
    accelModule.enableAxisSampling();
    accelModule.start();
    gyroModule.start();
  • Hi,
    Is there anything wrong with my code?
    I am able to get results from high/low detection and orientation detection, but not the tap detection.
    don't know what to do.
  • Double tap can be pretty finicky to configure correctly so you'll have to experiment with different configurations to find what works for your use case.
  • edited March 2017
    Eric,
    I configured with every possible combination but did not get any response at all.
    Could not detect tap even once.

  • edited March 2017
    These settings worked for me on an RPro board. I was also tapping the board directly so some further tweaking may be needed if you are using a case.
    AccelerometerBosch accBosch = metawear.getModule(AccelerometerBosch.class);
    accBosch.configure()
            .range(2f)
            .odr(100f)
            .commit();
    accBosch.tap().configure()
            .enableDoubleTap()
            .threshold(0.7f)
            .quietTime(AccelerometerBosch.TapQuietTime.TQT_30_MS)
            .shockTime(AccelerometerBosch.TapShockTime.TST_75_MS)
            .doubleTapWindow(AccelerometerBosch.DoubleTapWindow.DTW_100_MS)
            .commit();
This discussion has been closed.