Accelerometer

The Accelerometer class is a generic class that provides some high level access to an accelerometer. As this class is unaware of any sensor specifics, it only provides limited functionality and only suitable for apps intending to interact with any MetaWear type i.e. the sample app. Users creating apps for a specific MetaWear board should use the MMA8452Q or BMI160 classes to have finer control over the sensor.

Accelerometers have an active and standby mode. The start and stop methods switch the device between active and standby mode respectively. You can only configure the accelerometer when it is in standby mode

Acceleration Sampling

Axis sampling measures the acceleration data on the XYZ axes. The methods for configuring the axis sampling are: setOutputDataRate (how often acceleration data is sampled) and setAxisSamplingRange (measurement range). When using these functions, the closest, valid value will be selected, which may not correspond to the value passed in. To enable axis sampling, call enableAxisSampling and conversely, to disable it, call disableAxisSampling.

Accelerometer accelModule= mwBoard.getModule(Accelerometer.class);

// Set the sampling frequency to 50Hz, or closest valid ODR
accelModule.setOutputDataRate(50.f);
// Set the measurement range to +/- 4g, or closet valid range
accelModule.setAxisSamplingRange(4.0);

// enable axis sampling
accelModule.enableAxisSampling();

// Switch the accelerometer to active mode
accelModule.start();

Available data sources are the acceleration from the XYZ axes and from the individual axis. Three axis data can be interpreted as a CartesianFloat (G’s) or a CartesianShort (milli G’s) whereas single axis data can be interpreted as a float (G) or short/integer/long (milli G). When processing the 3 axis data, you are restricted to only data filters, minus the comparison and sample filters, the rms and rss transformers, and on firmware v1.1.2 and later, the math transformer. In order to access the full library of data processors, they must be chained after an rms or rss transformer.

Accelerometer accelModule= mwBoard.getModule(Accelerometer.class);

// create a route handling data from XYZ axes
accelModule.routeData().fromAxes();

// create a route handling data from only the X axis
accelModule.routeData().fromXAxis();

High Frequency Streams

Firmware v1.2.3+ contains a packed mode for the accelerometer which combines 3 acceleration 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.

accelModule.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));
                }
            });

            accelModule.setOutputDataRate(200.f);
            accelModule.enableAxisSampling();
            accelModule.start();
        }
    });