Monday, January 14, 2013

Gyroscope calibration helper, for AVR Atmega, Arduino and other micro

update to version 02

A gyroscope is a device for measuring or maintaining orientation, based on the principles of angular momentum.
Almost every gyroscope chip has to be calibrated, because every device brings a manufacturing error.



In case of gyroscope the correction parameters we need are gain and offset.

Once you obtain those values you can get calibrated data by applying this formula:
x_calibrated = (x_raw-offsetx) / gainx
y_calibrated = (y_raw-offsety) / gainy
z_calibrated = (z_raw-offsetz) / gainz



This Python script implements a simple Gyroscope calibration routine to estimate offset and gain calibration values.

To calibrate offset we just leave gyroscope in a stable position.

To correct gain, this script do not use a calibrated rotation platform. I use an integration method. User must rotate it in 6 differenct way (see sheet provided) for a fixed angle, i use 90 degrees, cause i can do it with a simple calibration platiform (a cube), but greater angles (3600) would bring to better calibration.
The rotation plane of the gyroscope have to be parallel to the requested rotation, so try to be precise placing the sensor over a rotation platform, and rotating it.
During every rotation the script collect raw values. Integrating those values gives use the raw total values for the angle formed. Because we fixed the angle we should estimate the gain factor for the raw values. I sense the rotation stop evaluating raw values, a better way should be adding stop sensors. I suggest to repeat calibration more than one time, cause small rotation error can lead to calibration error.


To obtain values, run this script and follow the instructions, a calibration sheet is provived to help you directing the sensor.

If you run your sensor in a big range of temperature you should also consider a calibration dependent to temperature too.
You can run the script function that compute temperature compensation values.
Cool down you chip, then launch the script, while the sensor come back to ambient temperature, this script collect values, then compute linear regression to find suitable temperature compensation values.
Now, given a tempdelta, that is a temperature delta difference from the sensor start time
tempdelta = actualtemp - starttimetemp
The calibrated axis would became:
x_calibrated = (x_raw-((tempcompx*tempdelta) + offsetx)) / gainx
y_calibrated = (y_raw-((tempcompy*tempdelta) + offsety)) / gainy
z_calibrated = (z_raw-((tempcompz*tempdelta) + offsetz)) / gainz

You may repeat those tests a few times to get better results.

On the microcontroller side you have to setup a function that print out to UART raw values read from your chip.
Given 2 bytes (int16_t) variables for every axis, output the LSB and then MSB byte ((uint8_t)(int16_t>>0) + (uint8_t)(int16_t>>8)), follow by a '\n' char .

Snippets are provided for AVR Atmega and Arduino, but it can be setup for other micro too.


Changelog

  • 02: small fix on the gyro_docalibration.txt readme file for the tempcomp function for x_calibrated, y_calibrated, z_calibrated
  • 01: first version

Code


Notes
  • read risk disclaimer
  • excuse my bad english

15 comments:

  1. very good guide how to use gyro and accelerometer sensors. I add this tutorial on my article where a long list with sensors and tutorials about how to interface and programming accelerometer, gyro and IMU sensors http://www.intorobotics.com/accelerometer-gyroscope-and-imu-sensors-tutorials/

    ReplyDelete
  2. thank you for this calibration method
    can you give me your reference for this method? because I want calibrate mpu6050 for my master's thesis and I need to reference.
    please help me!

    ReplyDelete
    Replies
    1. my email is "alinezhad66@yahoo.com"
      please send me your reference.
      thank you.

      Delete
    2. Could you send me the reference too? I'm going to build a Lego Mindstrom robot using MPU6050.
      Thank you.
      My email is : peppepoma@virgilio.it

      Delete
    3. could you send me too ?
      My email : chongkamat@gmail.com
      Thank you very much
      Regards

      Delete
    4. Please send me also the references for mpu6050 calibration
      to : nedvedmuhammad@gmail.com
      Thank you very much
      Regards

      Delete
    5. for all who needs references:

      you can find it googling for : "gyroscope calibration by integration"

      Delete
  3. hi, Davide, I send you an E-Mail. Have you seen it?
    My E-Mail is: bow5152@gmail.com

    ReplyDelete
  4. Please send me also the references for mpu6050 calibration Sir.
    please send to nedvedmuhammad@gmail.com
    Thank's

    ReplyDelete
    Replies
    1. you can find references googling for : "gyroscope calibration by integration"

      Delete