Go Down

Topic: Why is the angle between vector from accelerometer and compass not constant? (Read 2975 times)previous topic - next topic Jun 15, 2016, 08:23 pm
I'm using a gy80 board and reading the raw sensor data using the arduino serial. The angle between these two vectors are not constant. Shouldn't this angle be constant as the angle between north and gravity is constant?

Southpark #1
Jun 15, 2016, 08:57 pm
Maybe need to read up on calibration procedures. Also.... need to be more specific about 'not constant'. #2
Jun 15, 2016, 11:31 pmLast Edit: Jun 15, 2016, 11:37 pm by username1092
My understanding is that the vector from 3 axis compass points in the direction of the magnetic field and the vector from 3 axis accelerometer points in the direction of acceleration due to gravity. Since both these are constant, shouldn't the angle between them also be constant.

And to find the angle, I read the data from the board through serial and used python. Here is the code

Code: [Select]

import serial
import numpy as np

ser = serial.Serial('/dev/ttyACM1',9600)

def fn():
while True:
try:
data = ser.readline().split(' ')
global_down = np.array(data[0:3],dtype = np.float)
mag_down = np.linalg.norm(global_down)
global_down /= mag_down
global_north = np.array(data[6:9],dtype = np.float)
mag_north = np.linalg.norm(global_north)
global_north /= mag_north
print np.arccos(np.dot(global_north,global_down))*180/np.pi
except Exception,e:
print e

This code prints different angles based on how I hold the board,its not constant as I thought it would be.
And even if I don't calibrate the compass, the angle between these two vectors must be same right?

Southpark #3
Jun 16, 2016, 02:51 am
My understanding is that the vector from 3 axis compass points in the direction of the magnetic field and the vector from 3 axis accelerometer points in the direction of acceleration due to gravity. Since both these are constant, shouldn't the angle between them also be constant.
Earth's magnetic field and gravity are unrelated/uncorrelated as far as I know. So whichever direction a 3 axis magnetometer vector reading points is unrelated to the direction of a 3-axis accelerometer vector. #4
Jun 16, 2016, 04:54 amLast Edit: Jun 16, 2016, 05:00 am by username1092
Say my gy80 board is flat on the table and the x axis is pointing north, y axis pointing west and z axis pointing upwards. Now, the uncalibrated acceleroter would read a value in the direction of z axis and the other two axis having zero component, acc = 0i + 0j -1k. Similarly, the compass vector reads a value in the direction of x axis, comp = 1i + 0j + 0k.
These vectors are perpendicular.

Now, say I rotate my board 90 degrees in the horizontal plane and make the x axis point east. In this case, the acceleration vector is still the same, acc = 0i + 0j -1k. However, the compass vector is comp = 0i + 1j + 0k.Again, these vectors  are perpendicular.

This is my reason as to why they should be constant. The angles should always be 90. Even if I haven't accounted for declination, the angle may not be 90 degrees, but should still remain constant.

Southpark #5
Jun 16, 2016, 05:36 amLast Edit: Jun 16, 2016, 05:43 am by Southpark
Yeah..... but regardless of what measurement device you use..... if you stand still at the same spot (away from the north or south pole), then the 'actual' direction of north vector is always perpendicular to the force vector due to gravity.

But, when you use a measurement device to measure the north/south field, the 'vector' RELATIVE to an initial reference measurement direction will certainly change if you rotate your measurement device. In other words..... relative to your initial reference direction, a 3-d cartesian coordinate measurement of 1,0,0 is clearly different from a measurement of 0,1,0. Although, we know that your measurement device still tells you which way 'north' is. #6
Jun 16, 2016, 06:03 am
Quote
But, when you use a measurement device to measure the north/south field, the 'vector' RELATIVE to an initial reference measurement direction will certainly change if you rotate your measurement device.
So will the gravity vector. In my example the gravity vector doesn't change because I'm rotating about the gravity vector. It was a simple case I considered to explain my problem. The example can be extended to any rotation I guess.

Quote
In other words..... relative to your initial reference direction, a 3-d cartesian coordinate measurement of 1,0,0 is clearly different from a measurement of 0,1,0. Although, we know that your measurement device still tells you which way 'north' is.
That's kinda my point. The device tells me which way north is and which way down is in the new coordinate system after the rotation. Despite this, my angles are varying as the orientation changes.

I may have misunderstood what you tried to say, so please do clarify. Thanks.

Southpark #7
Jun 16, 2016, 06:17 amLast Edit: Jun 16, 2016, 06:22 am by Southpark
It is like..... you are now facing toward a reference direction, which you will call '0 degrees', and straight in front of you is a bright light. Now you turn clockwise 45 degrees. The angle you are now facing is +45 degrees relative to the reference direction.

Now, if you forget about the original reference direction, and then you assume that the direction that you are FACING is the new reference, then the bright light is located at -45 degrees (relative to the direction that you are facing). If you then rotate clockwise an additional 45 degrees, then the light will be at -90 degrees (relative to the direction that you're facing). The light is always at the same actual location in space. But the angle that you're 'measuring' (in order to keep track of the light) changes when you rotate. This means...... if you have a hypothetical device that is always able to tell you the angle of the light (relative to the direction you're facing), then sure.... the 'measured' angle will certainly change when you rotate. Afterall, it's a measured angle relative to the direction you're facing. #8
Jun 16, 2016, 06:47 am
The example you gave does not fully answer my question.

If my intention is to just measure the angle between my sensor orientation and north, or just the sensor orientation and down, your example will help.

However, my problem in terms your example would be something like this:

There are two lights glowing and not just one: one in front of me and another below me. If I rotate like you said, 45 degrees, the light    doesn't move and with respect to my new position, it is at -45 degrees. If I again move 45 degrees relative to the new position, I'm at 90 degrees or the light is at -90 degrees. And in these movements, the light at the bottom is not changing its angle, Its 90 degrees throughout.

This same movements can be extended to the vertical direction. So, say I'm looking up at an angle of 45 degrees. Again, this rotation would cause the horizontal bulb to move.

Now, what I'm calculating is the relative position of these two bulbs. So, no matter how I tilt or move my head, the relative position of these two bulbs should not change. This is what I don't understand.

Thanks.

Southpark #9
Jun 16, 2016, 08:56 amLast Edit: Jun 16, 2016, 09:10 am by Southpark
Now, what I'm calculating is the relative position of these two bulbs. So, no matter how I tilt or move my head, the relative position of these two bulbs should not change. This is what I don't understand.

Thanks.

Ok.... I see. Maybe you need to check out 3-D coordinate transformations...... maybe focusing on "changing" 3-D coordinate systems.

http://www.math.tau.ac.il/~dcor/Graphics/cg-slides/geom3d.pdf

Maybe read the part that says "Given the XYZ orthogonal coordinate system, find a transformation, M, that maps XYZ to an arbitrary orthogonal system UVW." #10
Jun 16, 2016, 10:23 am
Interesting. It looks like what I've been trying to do in my project.
I want to generate XYZ(north,down,west) from the sensors and UVW is the coordinate frame local to sensor. UVW is not my concern as of now.
The XYZ generation is what is the problem. The down vector works fine. The north vector is the problem. If I find out whats wrong, I can generate the XYZ using simple vector cross products.
This is the guide I used and tried to implement it.

http://www.starlino.com/dcm_tutorial.html

specifically "Part 4. DCM complimentary filter algorithm using 6DOF or 9DOF IMU sensors" .

Any other way to generate XYZ will also be helpful.

Thanks.

MarkT #11
Jun 16, 2016, 01:24 pm
MEMS compasses are awful.  You only get something vaguely useful if and only if:

1) You properly calibrate for soft and hard iron errors - even then there will be errors.
2) Don't use magnetic components nearby on the board (ie steel-containing resistors, capacitors
within a cm or two, note most have steel end-caps)
3) Use away from any ferrous metals (ie outside away from buildings, not in a steel box!) - this applies to all compasses

Also they produce a lot of noise, several degrees worth typically.

Having said they are awful, they are the best you can do in a small package (assuming household
rather than government budget is available).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ] #12
Jun 16, 2016, 01:58 pm
Even after considering all these factors, I can't explain why there is so much variation in the angles I calculated. I could share the raw values and the angles calculated if that would help.They from as low as 30 to about 120. And if I hold the board at one position, the angles don't jump around much.

Thanks.

Southpark #13
Jun 16, 2016, 09:28 pmLast Edit: Jun 17, 2016, 02:29 am by Southpark
This means you need to first make sure that your mathematical mapping or calculations are correct. So use mathematical simulations through matlab or something.... to ensure your method works in simulated scenarios.

Then you need to look at measurements from your measurement devices to ensure that the readings are accurate and that they make sense. Assess the noise level. Determine if the noise will cause issues with your computations.

Also.... if your simulation starts with a true north direction and a gravity force direction at a particular location.... then that's certainly fixed. If your computations in your coordinate system do not reflect this .... then the issue is with your computations...since you already know what is expected in advance. But if your computations are influenced by incorrect or bad data.... then that is something else to consider.

You need to see have correct computations and good input data in order to determine the angle between two measured vectors. You also know that the centres of the magnetometer system and the accelerometer system (in a real MPU device) are not located at the same physical spot - just in case.

MarkT #14
Jun 18, 2016, 12:47 am
Even after considering all these factors, I can't explain why there is so much variation in the angles I calculated. I could share the raw values and the angles calculated if that would help.They from as low as 30 to about 120. And if I hold the board at one position, the angles don't jump around much.

Thanks.
Have you done compensation?  MEMS magnetometers out of the box are not usable, they must be
calibrated in-situ.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up