Gyro

As previously mentioned, the BMI160 is a 6-axis IMU that has both an accelerometer and gyroscope. The gyro sensor on this device is represented by the GyroBmi160 interface and uses the Coriolis effect to measure angular velocity .

import com.mbientlab.metawear.module.GyroBmi160;

final GyroBmi160 gyroBmi160 = board.getModule(GyroBmi160.class);

Configuration

Like the accelerometer, the gyro also has a configurable output data rate and range. Use the gyro’s ConfigEditor. to set these parameters.

import com.mbientlab.metawear.module.GyroBmi160.Range;
import com.mbientlab.metawear.module.GyroBmi160.OutputDataRate;

// set the data rat to 50Hz and the
// data range to +/- 2000 degrees/s
gyroBmi160.configure()
        .odr(OutputDataRate.ODR_50_HZ)
        .range(Range.FSR_2000)
        .commit();

Angular Velocity Data

To retrieve angular velocity data, add a data route to the async data producer returned by the angularVelocity function. Data values from that async producer are represented by the AngularVelocity class.

gyroBmi160.angularVelocity().addRouteAsync(new RouteBuilder() {
    @Override
    public void configure(RouteComponent source) {
        source.stream(new Subscriber() {
            @Override
            public void apply(Data data, Object ... env) {
                Log.i("MainActivity", data.value(AngularVelocity.class).toString());
            }
        });
    }
}).continueWith(new Continuation<Route, Void>() {
    @Override
    public Void then(Task<Route> task) throws Exception {
        gyroBmi160.angularVelocity();
        gyroBmi160.start();
        return null;
    }
});