Skip to main content
Version: 21 Aug 2024

Accessing Sensors on Magic Leap 2

Developers can access a variety of Magic Leap 2’s sensors to obtain information about the environment and the device’s orientation, motion, and position. These sensors can be accessed via the standard Android Sensor API, which allows you to register listeners for sensor events, get sensor data, and manage sensor resources. The available sensors include:

  • Ambient Light Sensor
  • Headset Pressure Sensor (Altimeter)
  • Compute Pack Pressure Sensor (Altimeter)
  • Compute Pack Gyroscope Sensor
  • Headset Left Gyroscope Sensor
  • Headset Right Gyroscope Sensor
  • Compute Pack Accelerometer Sensor
  • Headset Left Accelerometer Sensor
  • Headset Right Accelerometer Sensor
  • Headset Right Calibrated/Uncalibrated Magnetometer Sensor (Compass)
  • Headset Left Calibrated/Uncalibrated Magnetometer Sensor (Compass)
Specialized Magic Leap 2 sensors

While generic sensors such as the Light Sensor can be accessed using Android's Sensor API, more specialized sensors such as the World Cameras can only be accessed via the Magic Leap SDK.

Available Sensors

The following table lists the sensors that are available on Magic Leap 2 and their corresponding sensor types in the Android Sensor API. The names can be used to identify which sensor was updated when implementing the SensorEventListener interface to receive updates when sensor values change in Java.

Multiple Sensor Instances

Some sensors have multiple instances with different names, such as the gyroscope and accelerometer sensors which are available on both the headset and the compute pack.

note

If there is a sensor with a '*' next to it, please read additional information about it provided below the table.

Sensor NameSensor TypeDescription
Ambient Light SensorSensor.TYPE_LIGHTMeasures the ambient light level in lux and is located on the headset
Headset Pressure SensorSensor.TYPE_PRESSUREMeasures the atmospheric pressure in hectopascals at the headset
Compute Pack Pressure SensorSensor.TYPE_PRESSUREMeasures the atmospheric pressure in hectopascals at the compute pack
Compute Pack Gyroscope SensorSensor.TYPE_GYROSCOPEMeasures the angular velocity of the compute pack in radians per second
Headset Left Gyroscope SensorSensor.TYPE_GYROSCOPEMeasures the angular velocity of the left side of the headset in radians per second
Headset Right Gyroscope SensorSensor.TYPE_GYROSCOPEMeasures the angular velocity of the right side of the headset in radians per second
Compute Pack Accelerometer SensorSensor.TYPE_ACCELEROMETERMeasures the linear acceleration of the compute pack in meters per second squared
Headset Left Accelerometer SensorSensor.TYPE_ACCELEROMETERMeasures the linear acceleration of the left side of the headset in meters per second squared
Headset Right Accelerometer SensorSensor.TYPE_ACCELEROMETERMeasures the linear acceleration of the right side of the headset in meters per second squared
Headset Right Uncalibrated Magnetometer Sensor*Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATEDMeasures the magnetic field strength and bias of the right side of the headset in microteslas
Headset Left Uncalibrated Magnetometer Sensor*Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATEDMeasures the magnetic field strength and bias of the left side of the headset in microteslas
Headset Right Calibrated Magnetometer Sensor*Sensor.TYPE_MAGNETIC_FIELDMeasures the magnetic field strength and bias of the right side of the headset in microteslas and provides information about which way the headset user is facing.
Headset Left Calibrated Magnetometer Sensor*Sensor.TYPE_MAGNETIC_FIELDMeasures the magnetic field strength and bias of the left side of the headset in microteslas and provides information about which way the headset user is facing.

* Values only availible after performing Compass Calibration.

How to Calibrate Your Compass (Magnetometer)

To obtain data from the magnetometer sensors, the sensor must first be calibrated using the on-device Compass Calibration app, located in the Settings > Perception menu. See Customer Care's Calibrating the Magnetometer guide for more information. After successfully calibrating the sensor, the device will report both the calibrated and uncalibrated sensor data which can be be obtained using Android's Sensor API.

Using the Android Sensor API

To use the Android Sensor API, begin by registering a listener for sensor events through an object implementing the SensorEventListenerinterface. This interface comprises two methods: onSensorChanged(SensorEvent event) and onAccuracyChanged(Sensor sensor, int accuracy). Obtain an instance of the SensorManager class by invoking getSystemService(Context.SENSOR_SERVICE) and register your listener with one of the registerListener() methods. Specify the sensor, your desired sampling rate, or delay from constants like SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, and so on. Always unregister listeners when not needed. When a sensor event arises, the onSensorChanged method provides a SensorEvent object containing details like the generating sensor, event accuracy, timestamp, and the sensor data. The nature of this data varies with the sensor type. Lastly, manage sensor resources judiciously to save battery and processing power. Utilize methods from the SensorManager class to check sensor availability and manage dynamic sensors. For in-depth details, consult the Android Sensor Documentation.

References

For more information and examples on how to use the Android Sensor API, please refer to the following resources: