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
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
This discussion has been closed.
Comments
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();
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.
I configured with every possible combination but did not get any response at all.
Could not detect tap even once.