Monday 2 March 2020

Custom Flight Controller Part 2.8: Gyro and Accelerometer Calibration

This post documents the implementation of the gyro and accelerometer calibration. The complete code can be found in my Github.

Unfortunately raw IMU data tends to have bias and noise, and they need to be calibrated. For Gyro, the calibration aims to remove static bias, that is, when the quadcopter lies still, the gyro reading should be zero across all axes. Similarly, we want accelerometer to report acceleration only in vertical z direction when quadcopter lies still on a horizontal surface. 

With the above principle, I implemented a simple piece of code to calibrate IMU. When CalibrateSensorBias() is called, it will collect 100 data from both gyrocopter and accelerometer in each axis and average them to be the bias for each axis. Afterwards, the bias calculated will be deducted from raw sensor reading when GetGyroData() or GetAccData() is called.

In my case, my accelerometer is found to have about 0.024 m/s/s in x direction, 0.01 m/s/s in y direction and 0.045 m/s/s in z direction. After calibration, it helped mitigate the problem that my quadcopter keeps drifting to one side. 


No comments:

Post a Comment