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.

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

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.source {String}
    The source used to derive the rotation rate. This may be "motion" or "orientation".
  • e.timeStamp {Number}
    The time in milliseconds when the data is collected
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