Author Topic: calculating angle with accelometer help ?  (Read 3872 times)

0 Members and 1 Guest are viewing this topic.

Offline koray692Topic starter

  • Contributor
  • Posts: 13
calculating angle with accelometer help ?
« on: February 15, 2016, 01:49:06 pm »
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.72

  G_ACCx = (double)( ((float)ACCx- 819.0f )/(16384.0f)   );              //     AFS_SEL=0   16,384 LSB/g DE
  G_ACCy = (double)( ((float)ACCy -819.0f)/(16384.0f)   );               //     AFS_SEL=0   16,384 LSB/g DE
  G_ACCz = (double)( ((float)ACCz -1310.72.0f)/(16384.0f)   );              //     AFS_SEL=0   16,384 LSB/g DE
 
abc=(G_ACCx*G_ACCx) + (G_ACCy*G_ACCy) + (G_ACCz*G_ACCz);

  G_ACC=(double) sqrt(abc);                                                                // R^2 = Rx^2 + Ry^2 + Rz^2
  ACI_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);   
 
 

Offline andre_teprom

  • Regular Contributor
  • *
  • Posts: 71
  • Country: br
    • Aluis-Rcastro
Re: calculating angle with accelometer help ?
« Reply #1 on: February 15, 2016, 10:40:19 pm »
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 ?
"Part of the world that you live in, You are the part that you're giving" ( Renaissance )
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: calculating angle with accelometer help ?
« Reply #2 on: February 15, 2016, 11:12:02 pm »
Why are you subtracting off 819 counts from x/y and 1310.72 counts from z?
 

Offline uncle_bob

  • Supporter
  • ****
  • Posts: 2441
  • Country: us
Re: calculating angle with accelometer help ?
« Reply #3 on: February 15, 2016, 11:26:46 pm »
Hi

Ok 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
 

Offline ve7xen

  • Super Contributor
  • ***
  • Posts: 1193
  • Country: ca
    • VE7XEN Blog
Re: calculating angle with accelometer help ?
« Reply #4 on: February 15, 2016, 11:27:17 pm »
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 ?
I 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.
73 de VE7XEN
He/Him
 

Offline uncle_bob

  • Supporter
  • ****
  • Posts: 2441
  • Country: us
Re: calculating angle with accelometer help ?
« Reply #5 on: February 16, 2016, 01:01:54 am »
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 ?
I 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.

Hi

Once 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
 

Offline pmbrunelle

  • Regular Contributor
  • *
  • Posts: 183
  • Country: ca
  • lost mech. guy
Re: calculating angle with accelometer help ?
« Reply #6 on: February 16, 2016, 01:32:37 am »
Why are you trying to calculate three angles?  :-//

Look here for the transformation:
https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf