Gyroscope Sensor

W3C First Public Working Draft,

This version:
https://www.w3.org/TR/2016/WD-gyroscope-20160913/
Latest published version:
https://www.w3.org/TR/gyroscope/
Editor's Draft:
https://w3c.github.io/gyroscope/
Version History:
https://github.com/w3c/gyroscope/commits/gh-pages/index.bs
Feedback:
public-device-apis@w3.org with subject line “[gyroscope] … message topic …” (archives)
Issue Tracking:
GitHub
Editors:
Anssi Kostiainen (Intel Corporation)
Mikhail Pozdnyakov (Intel Corporation)
Bug Reports:
via the w3c/gyroscope repository on GitHub
Test Suite:
web-platform-tests on GitHub

Abstract

This specification defines a concrete sensor interface to monitor the rate of rotation around the device’s local three primary axes.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

This document was published by the Device and Sensors Working Group as a Working Draft. This document is intended to become a W3C Recommendation.

If you wish to make comments regarding this document, please send them to public-device-apis@w3.org (subscribe, archives). When sending e-mail, please put the text “gyroscope” in the subject, preferably like this: “[gyroscope] …summary of comment…”. All comments are welcome.

This document is a First Public Working Draft.

Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 September 2015 W3C Process Document.

1. Introduction

The Gyroscope Sensor extends the Generic Sensor API [GENERIC-SENSOR] to provide information about the angular velocity around the device’s local X, Y and Z axis in terms of radian per seconds units.

2. Examples

let sensor = new GyroscopeSensor();
sensor.start();
    
sensor.onchange = event => {
    console.log("Rotation rate around the X-axis " + event.reading.rotationRateX);
    console.log("Rotation rate around the Y-axis " + event.reading.rotationRateY);
    console.log("Rotation rate around the Z-axis " + event.reading.rotationRateZ);
};

sensor.onerror = event => console.log(event.error.name, event.error.message);

3. Security and Privacy Considerations

There are no specific security and privacy considerations beyond those described in the Generic Sensor API [GENERIC-SENSOR].

4. Model

The Gyroscope Sensor’s associated Sensor subclass is the GyroscopeSensor class.

The Gyroscope Sensor’s associated SensorReading subclass is the GyroscopeSensorReading class.

The Gyroscope Sensor has a default sensor, which is the device’s main gyroscope sensor.

The Gyroscope Sensor has a single supported reporting mode which is "auto".

The Gyroscope Sensor’s permission name is "gyroscope". It has no associated PermissionDescriptor.

The Gyroscope Sensor has an associated abstract operation to retrieve the sensor permission which must simply return a permission whose name is "gyroscope".

The Gyroscope Sensor has an associated abstract operation to construct a SensorReading object which creates a new GyroscopeSensorReading object and sets each of its rotationRateX rotationRateY and rotationRateZ attributes to the current angular velocity about the corresponding axis.

The current angular velocity is the rate at which the device rotates about a specified axis. Its unit is the radian per second (rad/s) [SI].

The sign of the current angular velocity depends on the rotation direction and it must be according to the right-hand convention, such that positive rotation around an axis is clockwise when viewed along the positive direction of the axis (see figure below).

Device’s local coordinate system and rotation.

5. API

5.1. The GyroscopeSensor Interface

[Constructor(optional SensorOptions sensorOptions)]
interface GyroscopeSensor : Sensor {
  readonly attribute GyroscopeSensorReading? reading;
};

To Construct an GyroscopeSensor Object the user agent must invoke the construct a Sensor object abstract operation.

5.2. The GyroscopeSensorReading Interface

[Constructor(GyroscopeSensorReadingInit GyroscopeSensorReadingInit)]
interface GyroscopeSensorReading : SensorReading {
    readonly attribute unrestricted double rotationRateX;
    readonly attribute unrestricted double rotationRateY;
    readonly attribute unrestricted double rotationRateZ;
};
  
dictionary GyroscopeSensorReadingInit {
    unrestricted double rotationRateX = 0;
    unrestricted double rotationRateY = 0;
    unrestricted double rotationRateZ = 0;
};

5.2.1. The GyroscopeSensorReading constructor

5.2.2. The attribute

The rotationRateX attribute of the GyroscopeSensorReading interface represents the current angular velocity around X-axis.

The rotationRateY attribute of the GyroscopeSensorReading interface represents the current angular velocity around Y-axis.

The rotationRateX attribute of the GyroscopeSensorReading interface represents the current angular velocity around Z-axis.

6. Acknowledgements

Tobie Langel for the work on Generic Sensor API.

7. Conformance

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

A conformant user agent must implement all the requirements listed in this specification that are applicable to user agents.

The IDL fragments in this specification must be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [WEBIDL]

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[GENERIC-SENSOR]
Tobie Langel; Rick Waldron. Generic Sensor API. 24 March 2016. WD. URL: https://www.w3.org/TR/generic-sensor/
[PERMISSIONS]
Mounir Lamouri; Marcos Caceres. The Permissions API. 7 April 2015. WD. URL: https://www.w3.org/TR/permissions/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119
[WEBIDL]
Cameron McCormack; Boris Zbarsky. WebIDL Level 1. 8 March 2016. CR. URL: https://www.w3.org/TR/WebIDL-1/

Informative References

[SI]
SI Brochure: The International System of Units (SI), 8th edition. 2014. URL: http://www.bipm.org/en/publications/si-brochure/

IDL Index

[Constructor(optional SensorOptions sensorOptions)]
interface GyroscopeSensor : Sensor {
  readonly attribute GyroscopeSensorReading? reading;
};

[Constructor(GyroscopeSensorReadingInit GyroscopeSensorReadingInit)]
interface GyroscopeSensorReading : SensorReading {
    readonly attribute unrestricted double rotationRateX;
    readonly attribute unrestricted double rotationRateY;
    readonly attribute unrestricted double rotationRateZ;
};
  
dictionary GyroscopeSensorReadingInit {
    unrestricted double rotationRateX = 0;
    unrestricted double rotationRateY = 0;
    unrestricted double rotationRateZ = 0;
};