Skip to content
Select language:English

Calibration

Updated 1 min read

Depending on location configuration, it may be necessary to calibrate the device’s inertial sensors. This can be achieved using the CalibrationManager class.

To initiate the calibration process, call CalibrationManager.beginCalibration and provide a listener (instance of CalibrationListener) for calibration events.

If the calibration targets the magnetometer, the user must rotate the phone in the air to ensure accurate readings.

During calibration, the CalibrationListener.onProgress method is invoked, providing the calibration percentage and a boolean flag (enough) indicating whether sufficient data has been collected to complete the process.

Once the acquired calibration percentage reaches the required threshold, call CalibrationManager.endCalibration to finalize the procedure. If needed, the process can be aborted at any time using CalibrationManager.abortCalibration.

Most smartphones are factory-calibrated, meaning that the accelerometer, gyroscope, and soft iron component of the magnetometer generally do not require calibration. However, the magnetometer’s hard iron distortion can change frequently, depending on sensor quality. As a result, regular calibration may be necessary, ranging from every few hours to once per day, depending on the chip.

This code demonstrates how to execute a calibration when requested by the MDK.

object MyCalibrationListener: CalibrationListener {
override suspend fun onProgress(percentage: Int, enough: Boolean) {
println("Percentage: $percentage")
if (enough) {
CalibrationManager.endCalibration()
}
}
}
object MyLocationListener : LocationListener {
override suspend fun onCalibrationRequest(type: CalibrationType) {
CalibrationManager.beginCalibration()
}
...
}