Skip to content

Commit

Permalink
New core motion api documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfperusse committed Jan 21, 2025
1 parent c76dbf6 commit d148f9e
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
112 changes: 112 additions & 0 deletions docs/source/api/motion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
motion
======

Exposes Core Motion functionalities such as accessing the device's accelerometer, gyroscope, and magnetometer data.

Tracking of motion metrics can impact performance and battery drain. Use this feature judiciously to avoid negatively affecting the user experience.

.. lua:module:: motion
.. lua:attribute:: autoStart: boolean
If set, motion tracking will start automatically as soon as any attribute is read. Default is ``true``.

Set to false if you can to control when motion is tracked manually using the ``start`` and ``stop`` functions.

.. lua:function:: start(referenceFrame)
Start tracking motion metrics.

:param referenceFrame: The reference frame in which to track motion metrics. Can be one of the following values:
:type referenceFrame: number

- ``motion.referenceFrame.XArbitraryZVertical`` (default): The X-axis is arbitrary and the Z-axis is vertical.
- ``motion.referenceFrame.XArbitraryCorrectedZVertical``: The X-axis is arbitrary and the Z-axis is vertical. The system will attempt to correct for the device's orientation.
- ``motion.referenceFrame.XMagneticNorthZVertical``: The X-axis points toward the magnetic north and the Z-axis is vertical.
- ``motion.referenceFrame.XTrueNorthZVertical``: The X-axis points toward the true north and the Z-axis is vertical.

.. lua:function:: stop()
Stop tracking motion metrics.

.. lua:attribute:: updateInterval: number
The interval, in seconds, at which motion data is updated. This value can be set to control the frequency of motion updates. A lower value means more frequent updates, which can provide smoother motion tracking but may consume more power. The default value is 1/30 second.

Note that the interval is clamped between limits defined by the system.

.. lua:attribute:: gravity: vec2
The gravity vector in the device's reference frame.

.. lua:attribute:: acceleration: vec2
The acceleration vector in the device's reference frame.

.. lua:attribute:: rotationRate: vec2
The rotation rate in the device's reference frame.

.. lua:attribute:: sensorLocation: integer
The location of the device's sensors.

The value can be one of the following:

- ``motion.sensorLocation.default``: The location of the device's sensors is the default one.
- ``motion.sensorLocation.headphoneLeft``: The device's sensors are located near the left headphone.
- ``motion.sensorLocation.headphoneRight``: The device's sensors are located near the right headphone.

.. lua:attribute:: heading: number
The heading in degrees relative to the current reference frame.

.. lua:class:: attitude
.. lua:attribute:: pitch: number
The pitch of the device, in radians.

.. lua:attribute:: yaw: number
The yaw of the device, in radians.

.. lua:attribute:: roll: number
The roll of the device, in radians.

.. lua:attribute:: rotationMatrix: mat3x3
The rotation matrix that describes the device's orientation.

.. lua:attribute:: quaternion: quat
The quaternion that describes the device's orientation.

.. lua:attribute:: referenceFrame: integer
The reference frame in which motion metrics are tracked.

The value can be one of the following:

- ``motion.referenceFrame.XArbitraryZVertical``: The X-axis is arbitrary and the Z-axis is vertical.
- ``motion.referenceFrame.XArbitraryCorrectedZVertical``: The X-axis is arbitrary and the Z-axis is vertical. The system will attempt to correct for the device's orientation.
- ``motion.referenceFrame.XMagneticNorthZVertical``: The X-axis points toward the magnetic north and the Z-axis is vertical.
- ``motion.referenceFrame.XTrueNorthZVertical``: The X-axis points toward the true north and the Z-axis is vertical.

.. lua:class:: magnetic
.. lua:attribute:: field: vec3
The magnetic field vector in the device's reference frame.

.. lua:attribute:: accuracy: integer
The accuracy of the magnetic field data.

The value can be one of the following:

- ``motion.magneticAccuracy.uncalibrated``: The magnetic field data is uncalibrated.
- ``motion.magneticAccuracy.low``: The magnetic field data is of low accuracy.
- ``motion.magneticAccuracy.medium``: The magnetic field data is of medium accuracy.
- ``motion.magneticAccuracy.high``: The magnetic field data is of high accuracy.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Codea 4
api/light
api/tween
api/ui
api/motion
api/objc
api/pasteboard
api/physics2d
Expand Down

0 comments on commit d148f9e

Please sign in to comment.