Accelerometer

W3C Working Draft,

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

Abstract

This specification defines Accelerometer, LinearAccelerationSensor and GravitySensor interfaces for obtaining information about acceleration applied to the X, Y and Z axis of a device that hosts the sensor.

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 “accelerometer” in the subject, preferably like this: “[accelerometer] …summary of comment…”. All comments are welcome.

Publication as a 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 March 2017 W3C Process Document.

1. Introduction

The Accelerometer, LinearAccelerationSensor and GravitySensor APIs extends the Generic Sensor API [GENERIC-SENSOR] interface to provide information about acceleration applied to device’s X, Y and Z axis in local coordinate system defined by device.

2. Examples

let sensor = new Accelerometer();
sensor.start();

sensor.onreading = () => {
    console.log("Acceleration along X-axis: " + sensor.x);
    console.log("Acceleration along Y-axis: " + sensor.y);
    console.log("Acceleration along Z-axis: " + sensor.z);
}

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

3. Use Cases and Requirements

The use cases and requirements are listed in the Motion Sensors Explainer and Sensor use cases documents.

4. Security and Privacy Considerations

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

5. Model

The Accelerometer sensor type’s associated Sensor subclass is the Accelerometer class.

The Accelerometer has a default sensor, which is the device’s main accelerometer sensor.

The Accelerometer has an associated PermissionName which is "accelerometer".

A latest reading for a Sensor of Accelerometer sensor type includes three entries whose keys are "x", "y", "z" and whose values contain device’s acceleration about the corresponding axes. Values can contain also device’s linear acceleration or gravity depending on which object was instantiated.

The acceleration is the rate of change of velocity of a device with respect to time. Its unit is the metre per second squared (m/s2) [SI].

The frame of reference for the acceleration measurement must be inertial, such as, the device in free fall would provide 0 (m/s2) acceleration value for each axis.

The sign of the acceleration values must be according to the right-hand convention in a local coordinate system defined by the device.

The LinearAccelerationSensor class is an Accelerometer's subclass. The LinearAccelerationSensor's latest reading contains device’s linear acceleration about the corresponding axes.

The linear acceleration is an acceleration that is applied to the device that hosts the sensor, without the contribution of a gravity force.

The GravitySensor class is an Accelerometer's subclass. The GravitySensor's latest reading contains device’s acceleration due to the effect of gravity force about the corresponding axes.

The gravity is a force that attracts an object to the center of the earth, or towards any other physical object having mass.

Note: The local coordinate system of a mobile device is usually defined relative to the device’s screen when the device in its default orientation (see figure below).

Accelerometer coordinate system.

6. API

6.1. The Accelerometer Interface

[Constructor(optional SensorOptions options), SecureContext, Exposed=Window]
interface Accelerometer : Sensor {
  readonly attribute double? x;
  readonly attribute double? y;
  readonly attribute double? z;
};

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

6.1.1. Accelerometer.x

The x attribute of the Accelerometer interface returns the result of invoking get value from latest reading with this and "x" as arguments. It represents the acceleration along x-axis.

6.1.2. Accelerometer.y

The y attribute of the Accelerometer interface returns the result of invoking get value from latest reading with this and "y" as arguments. It represents the acceleration along y-axis.

6.1.3. Accelerometer.z

The z attribute of the Accelerometer interface returns the result of invoking get value from latest reading with this and "z" as arguments. It represents the acceleration along z-axis.

6.2. The LinearAccelerationSensor Interface

[Constructor(optional SensorOptions options), SecureContext, Exposed=Window]
interface LinearAccelerationSensor : Accelerometer {
};

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

6.2.1. LinearAccelerationSensor.x

The x attribute of the LinearAccelerationSensor interface returns the result of invoking get value from latest reading with this and "x" as arguments. It represents the linear acceleration along x-axis.

6.2.2. LinearAccelerationSensor.y

The y attribute of the LinearAccelerationSensor interface returns the result of invoking get value from latest reading with this and "y" as arguments. It represents the linear acceleration along y-axis.

6.2.3. LinearAccelerationSensor.z

The z attribute of the LinearAccelerationSensor interface returns the result of invoking get value from latest reading with this and "z" as arguments. It represents the linear acceleration along z-axis.

6.3. The GravitySensor Interface

[Constructor(optional SensorOptions options), SecureContext, Exposed=Window]
interface GravitySensor : Accelerometer {
};

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

6.3.1. GravitySensor.x

The x attribute of the GravitySensor interface returns the result of invoking get value from latest reading with this and "x" as arguments. It represents the effect of acceleration along x-axis due to gravity.

6.3.2. GravitySensor.y

The y attribute of the GravitySensor interface returns the result of invoking get value from latest reading with this and "y" as arguments. It represents the effect of acceleration along y-axis due to gravity.

6.3.3. GravitySensor.z

The z attribute of the GravitySensor interface returns the result of invoking get value from latest reading with this and "z" as arguments. It represents the effect of acceleration along z-axis due to gravity.

7. Acknowledgements

Tobie Langel for the work on Generic Sensor API.

8. 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]
Rick Waldron; et al. Generic Sensor API. URL: https://w3c.github.io/sensors/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/
[PERMISSIONS]
Mounir Lamouri; Marcos Caceres; Jeffrey Yasskin. Permissions. URL: https://w3c.github.io/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; Tobie Langel. Web IDL. URL: https://heycam.github.io/webidl/

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 options), SecureContext, Exposed=Window]
interface Accelerometer : Sensor {
  readonly attribute double? x;
  readonly attribute double? y;
  readonly attribute double? z;
};

[Constructor(optional SensorOptions options), SecureContext, Exposed=Window]
interface LinearAccelerationSensor : Accelerometer {
};

[Constructor(optional SensorOptions options), SecureContext, Exposed=Window]
interface GravitySensor : Accelerometer {
};