calculating angle with accelometer help ? - Page 1
Forum section: electronics / general

author: koray692
author_rank: Contributor
timestamp: February 15, 2016, 01:49:06 pm
content: hello friends ? am working to calculate angle with accelometer but results are wrong ...I coulndt find the problem where it is ..let me share code and datasheet ; (mpu6050)... sensor is in constant place...? choose afs_sel as 0 , zero-g output 50 mg is ? calculate type of lsb xy =819 z =1310,72// 819-xy z-1310.72G_ACCx = (double)( ((float)ACCx- 819.0f )/(16384.0f) ); // AFS_SEL=0 16,384 LSB/g DEG_ACCy = (double)( ((float)ACCy -819.0f)/(16384.0f) ); // AFS_SEL=0 16,384 LSB/g DEG_ACCz = (double)( ((float)ACCz -1310.72.0f)/(16384.0f) ); // AFS_SEL=0 16,384 LSB/g DEabc=(G_ACCx*G_ACCx) + (G_ACCy*G_ACCy) + (G_ACCz*G_ACCz);G_ACC=(double) sqrt(abc); // R^2 = Rx^2 + Ry^2 + Rz^2ACI_ACCx= 57.2958*acos(G_ACCx / G_ACC); // Axr = arccos(Rx/R)ACI_ACCy= 57.2958* acos(G_ACCy / G_ACC); // Ayr = arccos(Ry/R)ACI_ACCz= 57.2958*acos(G_ACCz / G_ACC);

author: andre_teprom
author_rank: Regular Contributor
timestamp: February 15, 2016, 10:40:19 pm
content: Your question could not be more vague: Accelerometers do not measure relative direction (angles), but acceleration, and to be able to do this, the sensor must be in motion. What is moving ? Is linear or rotational direction ?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: February 15, 2016, 11:12:02 pm
content: Why are you subtracting off 819 counts from x/y and 1310.72 counts from z?

author: uncle_bob
author_rank: Unknown
timestamp: February 15, 2016, 11:26:46 pm
content: HiOk so you have a three axis accelerometer from somebody (It would be nice to know who).It has a digital direct digital output. (or is it analog and you have run that through an ADC?).You have no sensitivity difference between the X,Y and Z. (Have you measured that or just assumed?)You have a static offset between the Z and the X, and Y. (Is that measured or from a data sheet?)Your code uses the terms X, Y and Z. Have you double checked the directions?Since you are measuring gravity, the first step is always to rotate through 360 degrees on each axis and make sure that things go right. It's a quick test and gravity is pretty dependable as a calibration source.That's probably enough to get straight before we start digging into the math.Bob

author: ve7xen
author_rank: Super Contributor
timestamp: February 15, 2016, 11:27:17 pm
content: Quote from: andre_teprom on February 15, 2016, 10:40:19 pmI think the question is regarding determining the vector angle of the force of gravity based on the accelerometer outputs.Not familiar enough with the vector math to help here, but it should be fairly straightforward.

author: uncle_bob
author_rank: Unknown
timestamp: February 16, 2016, 01:01:54 am
content: Quote from: ve7xen on February 15, 2016, 11:27:17 pmHiOnce you get it all set up it is a fairly direct calculation. The problems almost always come at the setup level. A sign error or the like gets things looking weird fast. A quick but imperfect demo (it's not 3D), rotate your mouse XX degrees and try to make sense out of some random motions. Once you see that is what happened (you calibrate the error) ... easy. Working through the output of a bunch of formulas to find an error ... not quite as easy.Bob

author: pmbrunelle
author_rank: Regular Contributor
timestamp: February 16, 2016, 01:32:37 am
content: Why are you trying to calculate three angles?Look here for the transformation:https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates