BMI160 Gyro

The Bmi160Gyro class is an extension of the Gyro class that interacts specifically with the BMI160 chip, the gyro on the MetaWear R Pro/RG boards.

Rotation Sampling

Rotation sampling measures the rotation around the XYZ axes. Configuring the sampling is done with a ConfigEditor, letting you set the measurement range and output data rate.

Available data sources are the rotation around all XYZ axes and from the individual axis. Three axis data can be interpreted as a CartesianFloat (degrees/s) whereas single axis data can be interpreted as a float (degrees/s).

When processing the three axis data, you are restricted to only data filters, minus the comparison and sample filters, and the rms and rss transformers. In order to access the full library of data processors, they must be chained after an rms or rss transformer. On firmware v1.1.2 and later, you can use the math processor on rotation data. Each axis will be treated as separate inputs to the operation defined.

import com.mbientlab.metawear.module.Bmi160Gyro;
import com.mbientlab.metawear.module.Bmi160Gyro.*;

Bmi160Gyro bmi160GyroModule= mwBoard.getModule(Bmi160Gyro.class);
// Set the measurement range to +/-2000 degrees/s
// Set output data rate to 100Hz
bmi160GyroModule.configure()
    .setFullScaleRange(FullScaleRange.FSR_2000)
    .setOutputDataRate(OutputDataRate.ODR_100_HZ)
    .commit();

//Stream rotation data around the XYZ axes from the gyro sensor
bmi160GyroModule.routeData().fromAxes().stream("gyro_stream").commit()
    .onComplete(new CompletionHandler<RouteManager>() {
        @Override
        public void success(RouteManager result) {
            result.subscribe("gyro_stream", new RouteManager.MessageHandler() {
                @Override
                public void process(Message msg) {
                    final CartesianFloat spinData = msg.getData(CartesianFloat.class);

                    Log.i("MainActivity", spinData.toString());
                }
            });

            bmi160GyroModule.start();
        }
    });

High Frequency Streams

Firmware v1.2.3+ contains a packed mode for the gyro which combines 3 rotation data samples into 1 ble packet allowing the board to stream data at a throughput higher than 100Hz. To build a data route for the high frequency data, use the fromHighFreqAxes function as your route starting point.

Remember that the high frequency is for streaming only; you cannot use it for data processing or logging.

bmi160GyroModule.routeData().fromHighFreqAxes().stream("high_freq").commit()
    .onComplete(new CompletionHandler<RouteManager>() {
        @Override
        public void success(RouteManager result) {
            result.subscribe("high_freq", new RouteManager.MessageHandler() {
                @Override
                public void process(Message msg) {
                    Log.i("test", "high freq: " + msg.getData(CartesianFloat.class));
                }
            });

            bmi160GyroModule.setOutputDataRate(200.f);
            bmi160GyroModule.start();
        }
    });