DeviceMotion


Purpose

Constitutes the object that enables access to data from various hardware sensors to return measurements of the attitude, rotation rate, and acceleration of a device.

Once data gathering is started using the start method, the API starts sending data objects at set intervals.

You can establish the object by using the following reference:

launchbox.Motion.DeviceMotion (interval, dataCallback, errorCallback)

Module

This object belongs to the Motion product module.

Parameters

Name Description Type Use
interval Defined to set an expected interval (in miliseconds) at which data is collected from the sensors. integer required
dataCallback

Defined to receive the data JSON object similar to the one presented below the table.

function required
errorCallback

Defined to receive the error JSON object similar to the one presented below the table.

function required

JSON objects received by the callbacks

The data JSON object contains the following values:

{
  "timestamp" = 1455810375223, // Time of the event in [ms], counted from the 1 January 1970 (long)
  "acceleration" = {
    "timestamp" = 1455810375223,
    "x" = 0.0075626, // Acceleration force around the X axis in [m/s2] (double)
    "y" = -0.0020835, // Acceleration force around the Y axis in [m/s2] (double)
    "z" = 0.0043765 // Acceleration force around the Z axis in [m/s2] (double)
  },
  "attitude" = {
    "timestamp" = 1455810375223,
    "roll" = -0.1220835, // Rotation vector component along the x axis (x * sin(θ/2)).
    "pitch" = 0.4357812, // Rotation vector component along the y axis (y * sin(θ/2)).
    "yaw" = 0.1175626 // Rotation vector component along the z axis (z * sin(θ/2)).
  },
  "gravity" = {
    "timestamp" = 1455810375223,
    "x" = -0.0020835, // Gravity force around the X axis in [m/s2] (double)
    "y" = 0.0075626, // Gravity force around the Y axis in [m/s2] (double)
    "z" = 9.12345678 // Gravity force around the Z axis in [m/s2] (double)
  },
  "gyroscope" = {
    "timestamp" = 1455810375223,
    "x" = 9.12345678, // Rotation rate around the X axis in [rad/s] (double)
    "y" = 0.0, // Rotation rate around the Y axis in [rad/s] (double)
    "z" = -1.4357812 // Rotation rate around the Z axis in [rad/s] (double)
  }
  },
  "magnetometer" = {
    "timestamp" = 1455810375223,
    "x" = 51.321, // Strength of the magnetic field around the X axis [uT] (double)
    "y" = 0.01, // Strength of the magnetic field around the Y axis [uT] (double)
    "z" = 49.765 // Strength of the magnetic field around the Z axis [uT] (double)
  }
}

The error JSON object contains one attribute that passes an error message delivered by the device:

{
  "message" = "Sensor 'DEVICE_MOTION' is not available on this device."
}

Methods

Name Return type Description
start undefined

Initiates gathering of data from various hardware sensors to enable measurements of the attitude, rotation rate, and acceleration of a device.

stop undefined

Stops gathering of data from the sensors used to measure the attitude, rotation rate, and acceleration of a device.

Related topics

Public API reference
Legal notice | Copyright © 2018 and Confidential to Pegasystems Inc. All rights reserved
PDN | Feedback
Advanced...