/cmotion

Sensor Logging with Matroska Storage on Android

Primary LanguageJava

CMotion - Multi-Device, -Sensor Synchronized Logging

Android application for recording sensor data from multiple devices in a parallel, synchronized way. Data is stored locallly on each device in matroska/mkv format. FFMpeg is used for compressing this data. Video, Audio as well as other Android sensors can be recorded and compressed in a single file. Metdata like recording date, sample rate, sample format etc. is stored side-by-side with the data streams.

Building and Deploying

For the Smartphone app, with the Smartphone connected via USB:

cd mobile && ../gradlew installDebug

and for each Wearable connected via USB:

cd wear && ../gradlew installDebug

Starting a Recording

You can either use the GUI to select the sensors and devices to record or you can control the whole process via Android Intents programmatically:

screenshot

Recordings can be started via broadcast intents, for example from the adb shell:

adb shell am broadcast -a senserec -e -i acceleration 

which will record only the acceleromteter for the default duration of 5 seconds, at the default rate of 50 Hz.

The start command can take these arguments:

-i select the input sensor you like to read [string or list of strings]
-r the rates in Hz at which to recored [float or list of floats]
-o output directory beneath to write files to [defaults to /sdcard/DCIM/<current time>/]
-d number of seconds to record for [float, defaults to 5 seconds]

The -i and -r can either be a list or a single value. For the input (-i) multiple sensor can be recorded in parallel. A single rate (-r) will be used for all sensors, or if a list is given the matching rate will be chosen for the respective sensor. In the latter case the number of supplied rates must match the number of supplied inputs.

The allowed values for the input can be displayed by running the intent and monitoring the logcat output, e.g.:

adb shell am broadcast -a senserec -e -i alop 

The output on an LG G Watch W100 looks like this:

adb logcat | grep Recorder
de.uni_freiburg.es.sensorrecordingtool.Recorder: alop: no matches for alop found.Options are: 
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.wrist_tilt_gesture
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.gyroscope
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.gyroscope_uncalibrated
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.accelerometer
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.magnetic_field
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.magnetic_field_uncalibrated
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.orientation
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.rotation_vector
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.game_rotation_vector
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.linear_acceleration
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.gravity
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.significant_motion
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.step_detector
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.step_counter
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.sensor.geomagnetic_rotation_vector
de.uni_freiburg.es.sensorrecordingtool.Recorder: android.hardware.sensor.Location

You can use any string of the ones listed there. Matching works by choosing the shortest possible match, i.e. if looking for step sensor, the android.sensor.step_counter will be selected as it is shorter than android.sensor.step_detector.

Multiple sensor can be recored at multiple rates like this:

adb shell am broadcast -a senserec --esa -i accel,gyro --efa -r 50,25 --ef -d 120 

This will record acceleration at 50Hz and the gyroscope at 25Hz for a total time of 2minutes. If you have multiple nodes in a Wearable network (for example by starting this on a smartwatch), all other nodes will also start to record sensor data. See the adb shell am broadcast -h help to learn howto forward argument values.

Results

Results from recording sessions and broadcast invocations will be communicated back by broadcast intents. Those can only be captured programmatically...

Notifcations

Notifications on both the Wearable and the Smartphone will be displayed throughout a recordings session. Dismissing the notification, as well as pressing cancel, will cancel the current recording and only what has been recorded so far will be left over.

Gotchas

The broadcast receiver does not receive the above mentioned when the package has been just installed. In order for it to work the application must have been started at least once! This is a security measure of Android.