Go Down

Topic: Guide to gyro and accelerometer with Arduino including Kalman filtering (Read 313 times) previous topic - next topic

totyforever

Man, you are great :) , the problem was in this function:-
R = sqrt(pow(accXval,2)+pow(accYval,2)+pow(accZval,2));
accXangle = acos(accXval/R)*RAD_TO_DEG-90;
accYangle = acos(accYval/R)*RAD_TO_DEG-90;

I think it's not accurate or something as I was applying it in my old code and instead of (accXval/R), it was (Rxest/R) where Rxest is calculated using both acc and gyro readings. However, after I changed it with the one u sent me in the previous post, it worked so fine. Thank you so much.

Lauszus

@totyforever
Nice. You welcome :)
atan2 will also give you 360 degrees resolution!

totyforever

Yup I noticed that :), but shouldn't I use the acc sensitivity in this function and for the Y angle as well :
double getXangle() {
double accXval = Accx-zeroValue[0];
double accZval = Accz-zeroValue[2];
double angle = (atan2(accXval,accZval))*RAD_TO_DEG;
return angle;

I mean would be like this: (4095 = sens in 2g range)

double getXangle() {
  double accXval = (Accx-zeroValue[0])/4095;
  double accZval = (Accz-zeroValue[2])/4095;
  double angle = (atan2(accXval,accZval))*RAD_TO_DEG;
  return angle;

Lauszus

It does not make any difference.

For instance take a look at this picture: http://upload.wikimedia.org/wikipedia/commons/7/7e/Trigonometry_triangle.svg
You can get the angle using atan(a/b).

For instance if a=100 and b=500, then the angle would be:
atan(100/500)=11.31deg
Then if you divide both of them with the same constant (this could be the sensitivity) lets say it's 100. Then a=100/100=1 and b=500/100=5, so:
atan(1/5)=11.31deg

atan2 is used to get 360 resolution and is dealt within the function. See this wiki page: http://en.wikipedia.org/wiki/Atan2#Definition

totyforever

yes got it :) Thanks Lauszus a lot for ur efforts, wish u all the best

Go Up