Sensor Data Collection with MATLAB Mobile

Overview

You can stream sensor data to MATLAB® running in the MathWorks® Cloud in real-time with a WiFi or cellular connection. Or, if you don't have a WiFi or cellular connection, you can log data locally and upload later when you do have a connection.

MATLAB Mobile™ includes the command-line interface in MATLAB and the ability to interact with Android™ sensors. To connect to sensors on the device and collect data, you create a mobiledev object in MATLAB.

You can also acquire sensor data locally on the Android device, with or without a network connection. This is an alternative method of collecting the sensor data instead of streaming it from the device to the Cloud. This is especially useful if you want to collect sensor data while your device does not have a network connection. For examples of using this method of acquisition, see Log Sensor Data Locally (MATLAB Mobile for Android).

You can also access the camera and acquire images on your Android mobile device from MATLAB Mobile. Set camera properties including resolution, autofocus, and flash. For an example, see Acquire Images from Android Camera (MATLAB Mobile for Android). Then, process the acquired images. For an example, see Classify Images from Android Camera Using Pretrained Network (MATLAB Mobile for Android).

Use MATLAB to process sensor data in various ways, including creating plots. For an example of acquiring data and plotting it, see Use Logged Sensor Data Example (MATLAB Mobile for Android).

Requirements for Using Sensors

To use Android sensors with MATLAB Mobile, make sure you have the following:

  • Installation of MATLAB Mobile on your Android device. You can acquire this application from Google Play™ Store.

  • Android version 6.0 or later.

  • To stream or upload sensor data to the MathWorks Cloud, you must have a MathWorks Account. If you do not have an account, you can set one up in MATLAB Mobile.

MATLAB Mobile Sensors Screen

To open the Sensors screen in MATLAB Mobile, tap Sensors on the menu.

At the top of the sensor screen are the Sensor settings. See Sensor Settings (MATLAB Mobile for Android).

Below the settings are the sensor displays. They are arranged in the following order, and show these measurements:

  • Acceleration — the three data points are the acceleration reading in X, Y, and Z coordinates, in m/s2 (meters per second squared).

  • Magnetic Field — the three data points are the magnetic field reading in X, Y, and Z coordinates, in microtesla.

  • Orientation — the three data points are the position reading in X, Y, and Z coordinates, in degrees, for azimuth, pitch, and roll.

  • Angular Velocity — the three data points are the angular velocity reading in X, Y, and Z rotations, in radians per second.

  • Position — data points representing latitude, longitude, speed, course, altitude, and horizontal accuracy. Position data is obtained from GPS, Wi-Fi, or the cellular network, using whichever is available. The measurements are:

    • Latitude in degrees relative to the equator, with positive values indicating latitudes north of the equator

    • Longitude in degrees relative to the zero meridian, with positive values extending east of the meridian

    • Speed in m/s (meters per second)

    • Course in degrees relative to true north

    • Altitude in meters above sea level

    • Horizontal Accuracy in meters defined by a circle around the latitude and longitude

Turn individual sensors on and off using the toggle switch.

When you turn on a sensor, the measurement readings begin and are displayed in each sensor's section. In this example, Acceleration and Magnetic Field have been turned on.

After you have turned on one or more sensors, use the Start button to send the data to MATLAB on the MathWorks Cloud. See Stream Sensor Data with Sensor Controls (MATLAB Mobile for Android). To log data to file instead, go to the sensor settings and change the Stream to setting.

You can also start the transmission of data from MATLAB programmatically using the Logging property of the mobiledev object. See Stream Sensor Data with mobiledev.logging Property (MATLAB Mobile for Android).

Sensor Settings

Use the Sensors settings to manage sensor data collection on your device. The sensor settings appear before the sensor displays.

The options are:

  • Stream to — Select either MATLAB (in the Cloud) or Log.

  • Sensor Logs

    • View logs on MATLAB Drive — Displays a list of sensor logs uploaded to your MATLAB Drive™

    • Configure

      • Sensors — Controls MATLAB access to the sensors. The access is on by default and needs to remain on in order to control the sensors and data streaming from MATLAB.

      • Camera — Controls MATLAB access to the cameras. The access is on by default and needs to remain on in order to control camera input from MATLAB.

      • Acquire Data in Background — This setting is off by default, but you can turn it on to continue to send sensor data when the application goes into the background on the device.

      • Upload Folder — The destination folder for uploading log files. The default folder is MATLAB Drive/MobileSensorData. You can change the upload folder in this setting.

      • Auto Upload — This setting determines how data log files are uploaded to MATLAB Drive.

        • Enabled — If Auto Upload is on, and you have a network connection on your device, log files are automatically uploaded to MATLAB Drive. If Auto Upload is on and you do not currently have a network connection, the files will automatically upload the next time the device detects a network connection (WiFi or cellular, if selected).

        • Disabled — If Auto Upload is off, you must manually upload the file to your MATLAB Drive. See Step 2. Transfer Sensor Logs (MATLAB Mobile for Android).

        Note

        If you are using Wi-Fi as your connection method, the Wi-Fi on your device may have a sleep setting that you should adjust.

    • Logs on Your Device — Displays a list of sensor logs on your device. Logs that have already been successfully uploaded to your MATLAB Drive display a successful Cloud icon . When there is a failure uploading a log file, this display shows a failure Cloud icon .

  • Sample rate — Enter the sample rate to apply to the following sensors: acceleration, magnetic field, orientation, and angular velocity.

  • Tap More to access:

    • Sensors — Controls MATLAB access to the sensors. The access is on by default and needs to remain on in order to control the sensors and data streaming from MATLAB.

    • Camera — Controls MATLAB access to the cameras. The access is on by default and needs to remain on in order to control camera input from MATLAB.

    • Acquire Data in Background — This setting is off by default, but you can turn it on to continue to send sensor data when the application goes into the background on the device.

    • Upload Folder — The destination folder for uploading log files. The default folder is MATLAB Drive/MobileSensorData. You can change the upload folder in this setting.

    • Auto Upload — This setting determines how data log files are uploaded to MATLAB Drive.

      • Enabled — If Auto Upload is on, and you have a network connection on your device, log files are automatically uploaded to MATLAB Drive. If Auto Upload is on and you do not currently have a network connection, the files will automatically upload the next time the device detects a network connection (WiFi or cellular, if selected).

      • Disabled — If Auto Upload is off, you must manually upload the file to your MATLAB Drive. See Step 2. Transfer Sensor Logs (MATLAB Mobile for Android).

      Note

      If you are using Wi-Fi as your connection method, the Wi-Fi on your device may have a sleep setting that you should adjust.

Device Orientation

The Acceleration, Angular Velocity, Magnetic Field, and Orientation sensors all log data in relation to the X, Y and Z axes. This diagram shows these axes relative to the device.

Note that the Z axis is a positive value when the device is lying flat on a surface. This is by design and is consistent with MATLAB conventions. When the device lies flat on a surface, the acceleration value along the Z axis is +9.81, which corresponds to the acceleration of the device (0 m/s^2) minus the acceleration of gravity (-9.81 m/s^2).

For more information on orientation for position, see the Android documentation.

Related Topics