1. Introduction
The Gyroscope API 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 Gyroscope(); sensor.start(); sensor.onchange = event => { console.log("Rotation rate around the X-axis " + event.reading.x); console.log("Rotation rate around the Y-axis " + event.reading.y); console.log("Rotation rate around the Z-axis " + event.reading.z); }; 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’s associated Sensor subclass is the Gyroscope
class.
The Gyroscope’s associated SensorReading subclass is the GyroscopeReading
class.
The Gyroscope has a default sensor, which is the device’s main gyroscope sensor.
The Gyroscope has a single supported reporting mode which is "periodic".
The Gyroscope Sensor’s permission name is "gyroscope"
.
It has no associated PermissionDescriptor.
The Gyroscope has an associated abstract operation to retrieve the sensor permission which must simply return a permission whose name is "gyroscope".
The Gyroscope has an associated abstract operation
to construct a SensorReading object which creates a new GyroscopeReading
object and sets each of its x y and z 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).
5. API
5.1. The Gyroscope Interface
[Constructor(optional SensorOptions sensorOptions)] interface Gyroscope : Sensor { readonly attribute GyroscopeReading? reading; };
To Construct an Gyroscope Object the user agent must invoke the construct a Sensor object abstract operation.
5.2. The GyroscopeReading Interface
[Constructor(GyroscopeReadingInit GyroscopeReadingInit)] interface GyroscopeReading : SensorReading { readonly attribute unrestricted double x; readonly attribute unrestricted double y; readonly attribute unrestricted double z; }; dictionary GyroscopeReadingInit { unrestricted double x = 0; unrestricted double y = 0; unrestricted double z = 0; };
5.2.1. The GyroscopeReading constructor
5.2.2. The attribute
The x attribute of the GyroscopeReading
interface represents the current angular velocity around X-axis.
The y attribute of the GyroscopeReading
interface represents the current angular velocity around Y-axis.
The x attribute of the GyroscopeReading
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]