Measure the inclination of an object - IMU

Hi, i'm new to the world of IMU. I want a sensor that accurately measure the inclination of an object. The IMU is the right choise? What is its sensivity in term of measuring inclination?

An IMU is intended for monitoring motion and general orientation. You can buy an inclinometer, or make one using just a 2D or 3d accelerometer. See this application note for how to do the latter.

There was a relative recent thread about using an accelerometer to measure incline.

Here's a quote from one of my posts in the thread.

****** Start of Quote ******

The acceleration from gravity will be

a = g * cosθ

So to find θ you use:

θ = acos(a / g)

****** End of Quote ******

I just now realized the above equation isn't a good one to use.

Let's say we're using a 12-bit accelerometer with a range of +/- 2g.

1 g should equal 1024 with this accelerometer. So the first reading one would read from the accelerometer as you tilted the sensor would be 1023. We can compute the able of this single bit difference with the equation:

acos(1023/1024) = 2.5323 degrees

The doesn't strike me as very precise.

However, if we use a different axis, and use the arcsine function we will get better precision.

If we use the axis which is zero when the sensor is level and 1024 when at 90 degrees, then our smallest detectable tilt will be:

asin(1/1024) = 0.05595 degrees.

This is much better than the 2.5323 degree figure we had earlier.

At 45 degree, we'll likely get the poorest performance from the sensor.

The closest reading to an exact 45 degree tilt would be 724. the difference in angles between 723 and 724 is:

asin(724/1024) - asin(723/1024) = 44.99388 - 44.91481 = 0.07907 degrees. This isn't as good as the 0.05595 degrees figure but it is still better than 2.5323 degrees.

So with a 3-axis accelerometer, if one axis returns a value larger than the g/(2-2) then you should use a different axis to compute the tilt. (2-2 is the square root of 2. sin(45) = 1 divided by the square root of 2. To me, one over the square root of 2 is an easier figure to remember than sin(45).)

Sorry for getting a bit technical. I still think this method is simpler than using the methods described in the app note to which jremington linked. Of course there a huge disadvantage to the method I just described, it assumes rotation in a single axis. The above method will allow you to calculate roll or pitch but if you're calculating roll, there can't be any pitch (and visa versa when calculating pitch).

Thank you very much, your answer is very useful and clear, this is exactly what I was looking for.

Megas112:
Thank you very much, your answer is very useful and clear, this is exactly what I was looking for.

Good to hear.

I should add the "1024" figure was what 1g should be for a 12-bit +/-2g accelerometer. It would be a good idea to experimentally measure what 1g is in your area and with your sensor.

The complicated-appearing application note that I linked boils down to a very simple equation that works much better than either of the two single-axis possibilities discussed above.

For a 2D or 3D accelerometer, with Z down and tilting around the Y axis, the tilt angle in degrees is

float tilt_angle = atan2(ax, az)*180./3.14159.;

You may need to change the sign of ax, so that the sign of the angle produced agrees with your definition of a positive rotation angle.

For the most accurate results, you need to calibrate the accelerometer measurements so that "1 g" gives the same result regardless of which axis is pointing straight down.

jremington:
For a 2D or 3D accelerometer, with Z down and tilting around the Y axis, the tilt angle in degrees is

float tilt_angle = atan2(ax, az)*180./3.14159.;

Thanks for the clarification.

I'm trying to get the possible accuracy/precision of various attitudes straight in my head. It seems like the above equation will favor some orientations over others.

I've got my BNO055 up and running and I'll need to see how the roll and pitch data compares with computing tilt from the raw acceleration values.

Thanks again for the app note link.

I'm trying to get the possible accuracy/precision of various attitudes straight in my head. It seems like the above equation will favor some orientations over others.

That is definitely true of sin() or cos().

The sin() function loses accuracy at close to 90 degrees, and cos() loses accuracy at close to 0 degrees. The atan2() function balances those two sources of inaccuracy out.

Here is a short C program to show the accuracy of atan2, acting on the simulated output of a 10 bit accelerometer tilted through 90 degrees. To conclude, the math has an inherent "sensitivity" of better than 0.1 degree, but consumer grade accelerometers are noisy, and you could expect perhaps 1 degree accuracy.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int i;
    int x,z;

    printf("tilt   ax    az   diff\r\n");

    for(i=0; i<91; i++) {
    z = 1023.*cos(i*3.14159265/180.);  //accelerometer az
    x = 1023.*sin(i*3.14159265/180.);  //accelerometer ax

    printf("%3d %5d %5d  %6.4f\r\n",i, x, z,((float)i) - 180.*atan2(x,z)/3.14159265);
    }
    return 0;
}

The result:

Columns are tilt angle (degrees), ax, az, difference between tilt angle and the result of atan2() in degrees.

tilt   ax    az   diff
  0     0  1023  0.0000
  1    17  1022  0.0470
  2    35  1022  0.0386
  3    53  1021  0.0284
  4    71  1020  0.0182
  5    89  1019  0.0084
  6   106  1017  0.0497
  7   124  1015  0.0348
  8   142  1013  0.0204
  9   160  1010  -0.0018
 10   177  1007  0.0310
 11   195  1004  0.0087
 12   212  1000  0.0305
 13   230   996  -0.0030
 14   247   992  0.0181
 15   264   988  0.0397
 16   281   983  0.0469
 17   299   978  0.0002
 18   316   972  -0.0095
 19   333   967  -0.0019
 20   349   961  0.0408
 21   366   955  0.0309
 22   383   948  0.0009
 23   399   941  0.0222
 24   416   934  -0.0080
 25   432   927  0.0136
 26   448   919  0.0114
 27   464   911  0.0089
 28   480   903  0.0066
 29   495   894  0.0271
 30   511   885  -0.0022
 31   526   876  0.0170
 32   542   867  -0.0113
 33   557   857  -0.0215
 34   572   848  -0.0008
 35   586   837  0.0034
 36   601   827  -0.0068
 37   615   817  0.0292
 38   629   806  0.0316
 39   643   795  0.0339
 40   657   783  0.0006
 41   671   772  0.0038
 42   684   760  0.0128
 43   697   748  0.0214
 44   710   735  -0.0088
 45   723   723  -0.0000
 46   735   710  0.0088
 47   748   697  -0.0214
 48   760   684  -0.0128
 49   772   671  -0.0038
 50   783   657  -0.0006
 51   795   643  -0.0339
 52   806   629  -0.0316
 53   817   615  -0.0292
 54   827   601  0.0068
 55   837   586  -0.0034
 56   848   572  0.0008
 57   857   557  0.0215
 58   867   542  0.0113
 59   876   526  -0.0170
 60   885   511  0.0022
 61   894   495  -0.0271
 62   903   480  -0.0066
 63   911   464  -0.0089
 64   919   448  -0.0114
 65   927   432  -0.0136
 66   934   416  0.0080
 67   941   399  -0.0222
 68   948   383  -0.0009
 69   955   366  -0.0309
 70   961   349  -0.0408
 71   967   333  0.0019
 72   972   316  0.0095
 73   978   299  -0.0002
 74   983   281  -0.0469
 75   988   264  -0.0397
 76   992   247  -0.0181
 77   996   230  0.0030
 78  1000   212  -0.0305
 79  1004   195  -0.0087
 80  1007   177  -0.0310
 81  1010   160  0.0018
 82  1013   142  -0.0204
 83  1015   124  -0.0348
 84  1017   106  -0.0497
 85  1019    89  -0.0084
 86  1020    71  -0.0182
 87  1021    53  -0.0284
 88  1022    35  -0.0386
 89  1022    17  -0.0470
 90  1023     0  -0.0000

Process returned 0 (0x0)   execution time : 0.062 s
Press any key to continue.

jremington:
Here is a short C program to show the accuracy of atan2, acting on the simulated output of a 10 bit accelerometer tilted through 90 degrees.

Shouldn't the sensitivity of the accelerometer be considered, such as ±2g ?

There's another approach here:
http://www.hobbytronics.co.uk/accelerometer-info but the atan2 function should be used.