# Measuring Inclination Angle Using Accelerometer/Magnetometer

Hello Everyone,

I work at a Rock Climbing gym and we are attempting to setup a system for measuring the degree of a hydraulic climbing wall that moves in and out from a vertical to create varying angles for the climber to climb. I need to create a system for measuring the angle and reporting it to the operator for setting the wall to certain degrees. With no easy place to mount a pot, I would like to try to accomplish this with an accelerometer/magnetometer setup. Is this possible and could you give me some insight on how to use the raw data from one of these types of sensors (outputting x,y,z) in order to find the inclination angle. Also, when the setup is powered off and powered on (like during a surge) will it need recalibration or will it be able to give the current angle upon startup?

Cheers!

The magnetometer isn’t particularly useful. This web page explains how to measure tilt using an accelerometer.

I have been reading on the subject, however I am worried about if the accelerometer was to lose power and re-establish a reference point upon powering that all of my angle measurements would be incorrect. Can I used the direction of earths magnetic field as a reference for down so that I don’t have to worry about power cycles?

If I were going to measure inclination, I would use an inclinometer.

re-establish a reference point

What reference point?

An accelerometer measures absolute tilt, just like an inclinometer. The Earth's gravity defines "down".

I guess what I am trying to figure out is that if the wall is calibrated straight up and down (|) and then tilted out to 45 degrees towards the climber (/) then if a power cycle happened, as long as the accelerometer was not recalibrated would I still get 45 degrees as the output?

I am placing the sensor against the back side of the climbing wall. The only value I care about is pitch, roll and yaw are impossible given the wall only has one axis of rotation.

as long as the accelerometer was not recalibrated would I still get 45 degrees as the output?

Yes. You do have to mount the accelerometer such that it reads zero when the wall is vertical.

If you just want inclination, that is easier to calculate than roll and pitch. Here is the formula for inclination in degrees:

``````float inclination=180.0*acos(az/sqrt(ax*ax+ay*ay+az*az))/M_PI;
``````

Where ax, ay and az are the raw accelerometer values, as floating point numbers.

Again, this formula requires you to carefully mount the accelerometer such that inclination=zero when the wall is straight up and down.

If you don’t want to worry about mounting the accelerometer carefully, mount it any way you like and take a reading with the wall straight up. Call those raw accelerometer values ax0, ay0 and az0 (as floats) and put the numbers in your final program.

Then for any other orientation, the inclination in degrees is:

``````float inclination = 180.0*acos( (ax0*ax + ay0*ay + az0*az)/sqrt( (ax*ax + ay*ay + az*az)*(ax0*ax0 + ay0*ay0 + az0*az0)))/M_PI;
``````

This is the most accurate method.

Thank you so much for the information and help!