Gyroscope

Provides a consistent API to estimate the rotation rate about each axis in the device frame.

Rotation rate is measured in degrees per second. For more information on coordinate frames, refer to the Coordinate Frames page.

When motion events are not available on the device, Gyroscope events are polyfilled with pan touch events.

Example

var gyroscope = new MotionStack.Gyroscope();

gyroscope.start(function(e) {
  console.log(e.alpha, e.beta, e.gamma);
});

gyroscope.stop();

Constructor

new MotionStack.Gyroscope([options])

Create a new Gyroscope instance object.

Argument Type Description
options Object Options to pass in for the new Gyroscope instance (optional)

  • source {String}
  • The source from which to derive gyroscope data:

    • "motion" Observe rotation rate of the device directly from the gyroscope.
    • "orientation" Estimated rotaton rate of the device from the accelerometer and magnetometer.

    Default: "motion"

  • fireOnAnimationFrame {Boolean}
  • Only emit the latest event within requestAnimationFrame intervals.


    Default: false

  • source {String}
  • The source used to calculate the reported data in order of approximation. If the specified source is not available, then the next available source is used.

    • "motion" gyroscope sensor.
    • "orientation" orientation estimate.
    • "touch" touch sensor.


    Default: "motion"

var gyroscope = new MotionStack.Gyroscope({source: "motion"});

Static Methods

isSupported()

Returns a Boolean value describing whether the device has access to a gyroscope.

MotionStack.Gyroscope.isSupported(); // true or false

Instance Methods

start(callback, [context])

Start receiving gyroscope updates.

Argument Type Description
callback Function Callback function that receives an object as an argument

  • function(e)
  • e.alpha, e.beta, e.gamma {Number}
    Axial components of the rotation rate of the device about the x, y, and z axes of the device, respectively (radians / second)
  • e.interval {Number}
    The time in milliseconds between successive readings of the gyroscope
  • e.timeStamp {Number}
    The time in milliseconds when the data is collected
  • e.source {String}
    The source used to calculate the reported data.

    • "motion" gyroscope sensor.
    • "rawOrientation" browser estimate.
    • "sensorFusion" sensor fusion via a Kalman filter.
    • "filteredOrientation" dynamic low-pass filter on the browser estimate.
    • "gravityPolyfill" accelerometer gravity estimate.
    • "touch" touch sensor.

context Object Context in which to invoke the callback (optional).
gyroscope.start(function(e) {
  console.log(e.alpha, e.beta, e.gamma);
});

stop()

Stop gyroscope updates.

gyroscope.stop();

Source

src/interfaces/Gyroscope.js