9 years, 8 months ago.

How to you get exact angle values?

I've downloaded the helloworld programme and its gives me integer values for X,Y and Z. However I have no idea what theses values represent and was wondering if it possible to get exact angle values?

Question relating to:

Hello Liam Brown,

the integer values you are getting represent the acceleration in units of 0.004g. If you place your sensor parallel to the surface of the earth you should get a value of around -2452 for Z and when you multiply it by 0.004g you will get -2452 * 0.004 g = -1 g = -9.81 m/s^2 wich is the acceleration caused by gravity. If you move your sensor around you will get additional accelerations for X, Y and Z. In general an accelerometer is not able to tell you the orientation of the sensor in space (angle values?) because there is no way to distinguish between gravitational acceleration and acceleration caused by movement. To measure spacial orientation you will need something like a gyroscope.

posted by iliketux the penguin 10 Aug 2014

However if the sensor is sitting stationary (or very close to it) then you can tell orientation by looking at the relative magnitudes of the values, e.g. If x = sqrt(1/2), y=0 and z=-sqrt(1/2) then you are tilted 45 degrees from horizontal about the y axis. You can check that you are stationary easily by checking that sqrt(x*x + y*y + z*z) = 1g (plus or minus a little to allow for noise). It is possible to move in such a way that you get that result when not stationary but it's fairly tricky.

posted by Andy A 11 Aug 2014

Greetings Guys,

my name is Denis. I work with Liam on this Uni project, and you help is grately appreciated!

I would like to quickly elaborate on his question and bring some clarity. We are using a stationary accelerometer attached to the base of a beam. The movement of a beam is only on the other end. (Imagine the little hand of a clock, and the accelerometer is position on the hand at the center of the clock.)

Thus we are interested in the angle of the beam.

My questions are basically: 1) Are the values that we get from the accelerometer liniar with respect to the angle that the beam will be positioned at? (again exact analogy with the clock hand.) 2) Calibration on the current product? 3) In order to filter the noise, I will be taking a certain set of values and will be averaging them. As the movement of the beam is quite slow. (0degrees to 45degrees) in 2 seconds, I think that this will not be a big of an issue. Any comments on this will be valuable. 4) I have been reading on some solutions to increase the accuract of the readings by using the two moving axis. The vertical and the horisontal and use the following measurements - angle = atan2(x_acc, y_acc); Again comments on this will be beneficial. 5) And one final - as u said that we will be getting values up to 2452, to -2452. I think this is not the case fod ADXL345. As we are getting values only to 256.

Thank you very much in advance for your time!

Kind Regards, Denis

posted by Liam Brown 18 Aug 2014

1) NO. It's a trigonometric function as I would have hoped any first year A level physics student could have told you. Rotating systems almost always come down to using the sine and cosine of the angle to get the values in a fixed direction.

2) Calibration - See below.

3) Yes, average. Once you have some history of the movement and making the large assumption that the rotation speed is constant you could in theory calculate the rotation speed and compensate for the lag in your measurements.

4) See below

5) The datasheet for the part you are using ( http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf ) indicates that you will typically get a sensitivity of 256 LSB per g. In other words +/-1 g will give you values in the range of +/- 256 but you could get larger values if the system is accelerating in any way. You will also get slightly different ranges for different sensors and at different temperatures. Again the data sheet gives ranges and statistics on that.

For the following I'm going to assume that Z is the axis that the hand rotates about and X is the axis in the direction of the clock hand. If things are moving slowly then you can assume that the only values you will see are due to gravity. This means that when the hand is pointing straight up you would see 1g in the X direction, when it's pointing down you should see -1g in the x direction. When it's pointing to the right you will see 0g in the x direction and 1g in the y direction (or -1g depending on whether Z is towards or away from the clock). You should never see anything other than 0 in the z direction.

The values you get on the X and Y axis will be x = 256*COS(angle) and y = 256 * SIN(angle) (or maybe y=-256*SIN(angle), see above). Which means sin(angle)/cos(angle) = y/x. Since sin/cos = tan this gives y/x=tan(angle). All atan2 gives you over the straight atan() that you would need to use to get any result is that it will automatically handle +/- side of things to give you a value in the range +/-PI rather than the +/- PI/2 that atan will give. It also handles the possible divide by 0 error correctly. I suppose you could just use the X axis value and then look at the approximate value on the Y axis to tell you if it's a plus or minus angle but that would be a stupid way to do it, firstly you would need to scale based on the exact reading value (that 256 constant above which may not always be 256 depending on things like temperature), by using y/x the two constants cancel out and you don't need to worry about the actual values you're getting, secondly you'd be throwing away useful information (the y value) and not gaining any meaningful simplification in the code in return.

The datasheet gives information on the accuracy and error over time and temperature of the sensor. It also details the process for calibrating and removing bias from the sensor if you want to get a more accurate number.

posted by Andy A 18 Aug 2014

Andy thank you for your time. This has answered all my questions and I have finished the code spicific to the angle.

Kind Regards

posted by Liam Brown 20 Aug 2014

1 Answer

Liam Brown
poster
9 years, 8 months ago.

Test


Assigned to Liam Brown 9 years, 8 months ago.

This means that the question has been accepted and is being worked on.