Running Speed Estimator


Table of Contents

Introduction

The running speed estimator allows you to monitor the running speed of the user carrying the client device using collected accelerometer data. The estimator implements the learning based algorithm described in to predict the running speed. This estimator works periodically approximately every 2.5 seconds as accelerometer data is collected.

This tutorial will cover how to initialize the estimator and read running speed estimates periodically.

Initializing The Running Speed Estimator

Prerequisites

In order to estimate the running speed of a client, the client device must be equipped with a triaxial accelerometer. Most smartphones and other Android-capable devices come equipped with an accelerometer, so we assume that the current device has one. If, however, there are some prerequisites that the estimator does not meet, the function reqSatisfied() will throw an ExtractorPrerequisiteUnsatisfiedException instead of returning void ,  which is exemplified by the try-catch in  the code snippet below.

try {
    speedEstimator.reqSatisfied();
    speedEstimator.start();
} catch (ExtractorPrerequisiteUnsatisfiedException e) {
    // Prerequisites of the estimator were not met
}

// Keep collecting until
speedEstimator.terminate();

Holding Data

Once you have verified that the estimator can run on the client device using the reqSatisfied() method, we can create a place to store the data we are hoping to collect. This is done by creating a BackableEncapsulator  instance as shown in the following snippet. Note: we must define a collection period of either 2.56 seconds or 5.12 seconds:

int period = 2.56 * 1000; // The interval must be either 2560 or 5120 milliseconds.
DataJobIdentifier speedID = new DataJobIdentifier("Running Speed");
BackableEncapsulator<TimeZonedTimestampedObject<SpeedContainer>> speedData = new BackableEncapsulator<TimeZonedTimestampedObject<SpeedContainer>>(speedID);

Adding a Listener

We can now add a new listener for the extractor. This listener will be triggered whenever a new datapoint is added to the encapsulator.

speedData.addListener(new DoSomethingWithDataListener());

Running the Estimator

Finally, once we have a secure location to store our running speed data, we can initialize the estimator. This requires a single line of code as shown bellow:

speedEstimator = new SpeedEstimator(speedData, this.getApplicationContext(), period);

That’s it!

Running Example

(TODO: complete)

References