Using the Sensors API

Accessing Sensor Data

The data from the different sensors is accessible with the SensorsData class. This class contains the raw and calibrated values of each sensor. It also provides a camera state that defines if the camera is moving, static or even falling.

To retrieve all the sensor values synchronized with the last image of the camera, you will need to:

  • Open the camera.
  • Grab the current image.
  • Get sensors data corresponding to this image using TIME_REFERENCE::IMAGE.
// Create and open the camera
Camera zed;
zed.open();
SensorsData sensors_data;

// Grab new frames and retrieve sensors data
while(zed.grab() == SUCCESS){
  zed.getSensorsData(sensors_data, TIME_REFERENCE::IMAGE); // Get only frame synchronized sensor data
}
# Create and open the camera
zed = sl.Camera()
zed.open()
sensors_data = sl.SensorsData()

# Grab new frames and retrieve sensors data
while zed.grab() == sl.ERROR_CODE.SUCESS :
  zed.get_sensors_data(sensors_data, sl.TIME_REFERENCE.IMAGE) #  Get only frame synchronized sensor data

The function getSensorsData can be called with a different TIME_REFERENCE. For example you can use TIME_REFERENCE::CURRENT to get the sensor data corresponding the timestamp of the function call, or TIME_REFERENCE::IMAGE to get the data synchronized with the current camera image.

Code Example

For code example, check out the Getting Sensor Data tutorial.