CARVIEW |
Accelerometer Sensor
W3C First Public Working Draft,
- This version:
- https://www.w3.org/TR/2016/WD-accelerometer-20160913/
- Latest published version:
- https://www.w3.org/TR/accelerometer/
- Editor's Draft:
- https://w3c.github.io/accelerometer/
- 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
Copyright © 2016 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and permissive document license rules apply.
Abstract
This specification defines accelerometer sensor interface 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.
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 Accelerometer Sensor 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 AccelerometerSensor({includeGravity: false, frequency: 60}); sensor.start(); sensor.onchange = event => { console.log("Linear acceleration for an X-axis: " + event.reading.accelerationX); console.log("Linear acceleration for an Y-axis: " + event.reading.accelerationY); console.log("Linear acceleration for an Z-axis: " + event.reading.accelerationZ); } 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 Accelerometer Sensor’s associated Sensor subclass is the AccelerometerSensor
class.
The Accelerometer Sensor’s associated SensorReading subclass is the AccelerometerSensorReading
class.
The Accelerometer Sensor has a default sensor, which is the device’s main accelerometer sensor.
The Accelerometer Sensor has a single supported reporting mode which is "auto".
The Accelerometer Sensor’s permission name is "accelerometer". It has no associated PermissionDescriptor.
The Accelerometer Sensor has an associated abstract operation to retrieve the sensor permission which must simply return a permission whose name is "accelerometer".
The Accelerometer Sensor has an associated abstract operation
to construct a SensorReading object which creates a new AccelerometerSensorReading
object and sets its accelerationX, accelerationY and accelerationZ attributes
to zero.
The linear acceleration is an acceleration that is applied to the device that hosts the sensor, without the contribution of a gravity force.
The AccelerometerSensorReading
's attribute values must be in [SI] units for acceleration, metre
per second squared (m/s^2), expressed in a three-dimentional Cartesian local coordinate system defined by the device.
The frame of reference for the acceleration measurement must be inertial, such as device in free fall would provide 0 (m/s^2) 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.
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).
5. API
5.1. The AccelerometerSensor Interface
[Constructor(optional AccelerometerSensorOptions accelerometerSensorOptions)] interface AccelerometerSensor : Sensor { readonly attribute AccelerometerSensorReading? reading; readonly attribute boolean includesGravity; };
To Construct an AccelerometerSensor Object the user agent must invoke the construct a Sensor object abstract operation.
5.2. The AccelerometerSensorOptions Dictionary
dictionary AccelerometerSensorOptions : SensorOptions { boolean includeGravity = true; };
By default, the Accelerometer sensor would provide acceleration information including
the effect of the gravity force. In cases, when linear acceleration information is
required, AccelerometerSensorOptions
dictionary with and dictionary member includeGravity that is set to false,
must be provided to AccelerometerSensor
constructor.
5.3. The AccelerometerSensorReading Interface
[Constructor(AccelerometerSensorReadingInit AccelerometerSensorReadingInit)] interface AccelerometerSensorReading : SensorReading { readonly attribute double accelerationX; readonly attribute double accelerationY; readonly attribute double accelerationZ; }; dictionary AccelerometerSensorReadingInit { double accelerationX = 0; double accelerationY = 0; double accelerationZ = 0; };
5.3.1. The AccelerometerSensor attributes
The includesGravity attribute of the AccelerometerSensor
interface represents whether the acceleration information provided by the sensor includes effect of the gravity
force. In case when includesGravity equals to false, AccelerometerSensor
will provide linear acceleration information.
5.3.2. The AccelerometerSensorReading constructor
The AccelerometerSensorReading constructor accepts AccelerometerSensorReadingInit
dictionary that is used
for initialization of AccelerometerSensorReading
attributes.
5.3.3. The AccelerometerSensorReading attributes
The accelerationX attribute of the AccelerometerSensorReading
interface represents the acceleration along X-axis.
The accelerationY attribute of the AccelerometerSensorReading
interface represents the acceleration along Y-axis.
The accelerationZ attribute of the AccelerometerSensorReading
interface represents the acceleration along 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
- accelerationX
- accelerationY
- accelerationZ
- AccelerometerSensor, in §5.1
- AccelerometerSensor(), in §5.1
- AccelerometerSensor(accelerometerSensorOptions), in §5.1
- AccelerometerSensorOptions, in §5.2
- AccelerometerSensorReading, in §5.3
- AccelerometerSensorReading(AccelerometerSensorReadingInit), in §5.3
- AccelerometerSensorReadingInit, in §5.3
- conformant user agent, in §7
- Construct an AccelerometerSensor Object, in §5.1
- Construct SensorReading Object, in §4
- includeGravity, in §5.2
- includesGravity, in §5.1
- linear acceleration, in §4
- local coordinate system, in §4
- reading, in §5.1
- retrieve the sensor permission, in §4
Terms defined by reference
- [GENERIC-SENSOR] defines the following terms:
- [permissions] defines the following terms:
- [GENERIC-SENSOR] defines the following terms:
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: https://www.bipm.org/en/publications/si-brochure/
IDL Index
[Constructor(optional AccelerometerSensorOptions accelerometerSensorOptions)] interface AccelerometerSensor : Sensor { readonly attribute AccelerometerSensorReading? reading; readonly attribute boolean includesGravity; }; dictionary AccelerometerSensorOptions : SensorOptions { boolean includeGravity = true; }; [Constructor(AccelerometerSensorReadingInit AccelerometerSensorReadingInit)] interface AccelerometerSensorReading : SensorReading { readonly attribute double accelerationX; readonly attribute double accelerationY; readonly attribute double accelerationZ; }; dictionary AccelerometerSensorReadingInit { double accelerationX = 0; double accelerationY = 0; double accelerationZ = 0; };