Pages: 1 2 [3] 4 5 ... 37   Go Down
Author Topic: Guide to gyro and accelerometer with Arduino including Kalman filtering  (Read 286241 times)
0 Members and 4 Guests are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi chaps. I've been playing around with this board and the code and I must say, thanks for this. Its definitely been a big help.

Im porting this to C++ and Cinder for use in an experiment. I need to get all 3 axes represented though. Is there any particular reason that the Z Axis is not represented?

I notice that altering the Y rotation also alters the Z rotation on the Gyros but not on the Accelerometers. I believe I need to compute the Z somehow but I'm really not too sure on the math.
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It is not possible to calculate the z-axis with the accelerometer. Remember that it measures earth gravitational force, and it does not change when you rotate the IMU horizontal. You need something like a magnetometer to calculate the last angle smiley
If you only need to see if it changes you can just use the gyro and then compensate for drift in the code.
- Lauszus
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok that can't be right surely? I get that its not a compass but its billed as 6 Degrees of Freedom which suggests Z. Indeed, its even marked on the board so surely, if can measure the other 2, this 3rd is nothing special. I mean, I own a pair of these vuzix glasses things and they only have a set of gyros and accelerometers. Im not after a direct heading, thats not a problem and I know we cant get that but we most definitely should be able to get the 3rd.
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not as far as I know. You can easily get the z-axis from the gyro, but it will drift. It is not possible to get the z-axis using the accelerometer.
- Lauszus
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting. I need to look over this compensation for drift then. However, Im still not sure why one cant get acceleration on the Z axis (Im British though, so Z axis means depth to me but in this case, I believe we mean yaw). There is a yaw gyro indeed but it is claimed there is a yaw accelerometer as well. Why is it there if it can't be used? It seems confusing. Clearly I must be missing something.
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes it is yaw (the rotation around the z-axis). The reason why you can not measure yaw with a accelerometer is because the gravitational force from earth does not change when you rotate the IMU horizontal. In theory you will not measure any difference at all, in pratical however you see the acceleration from the movement. I use the z-value from the accelerometer together with pitch and roll to calculate the force vector (this is theoretical 1, but in practice there is a small difference). I also use the z-value from the accelerometer to know when the IMU is tilted more than 90 degrees to both side, so I can get 360 degree resolution instead of only 180 smiley  
- Lauszus
« Last Edit: May 18, 2011, 07:56:29 pm by Lauszus » Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2066
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

.."while the accelerometer measures Earth gravitational acceleration (g) in three dimensions"..
not only, it measures the acceleration of the unit as well..P. smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I understand in the case of the accelerometer now. That does make sense. So, do you use the gyro at all for the Yaw calculation?
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pito: exactly! That is why you can not count on the accelerometer on short terms, because it is to unstable. For example it will jump all over the place if you shake it. That is why you have to combine it with a gyro, that do not change when you for example shake it.

Onidaito: I do not use it right now, but if you look in my code I actualy calculate the yaw. Just write
Code:
Serial.println(gyroZangle);
and you will see the yaw, but remember it will drift!
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If it is an ITG a simple offset calibration is enought to cancel the drift, or almost all of it.
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you mean? Will you just keep calibratrating all the time, to compensate for drift?
- Lauszus
 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey Lauszus,

I got my sensor (nice and fast too,thanks for the germany tip!)

I have it all connected and it seems to be working. One thing i notice though is that tilting forward on the y-axis gives me values up to 60 but backwards on the y-axis i only get as high as 20. on the x-axis then i an even 40 on each side.

I notice you wrote to add in a piece of code to make it read full 360, is that why mine isn't reading right?

i tried putting in that code after
"  R = sqrt(pow(accXval,2)+pow(accYval,2)+pow(accZval,2));//the force vector
  accXangle = acos(accXval/R)*RAD_TO_DEG-90;
  accYangle = acos(accYval/R)*RAD_TO_DEG-90;"

But didnt change anything.

also i'm not connecting the z-axis because i don't need it. I assumed it wouldnt make a difference.

Just wanted to say thanks again for the code. Looks like my project will become what i dreamed  smiley I'll post a video up here when its done
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad I could help. Have you connected the accelerometers z-value? If not that is why you data is getting weird. Remember that the code uses the z-value from the accelerometer to calculate the force vector.
Looking forward to see your project in action smiley
- Lauszus
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no i didn't plug it in because i didnt need to measure the x-axis.

I am using a pressure sensor also, and using an arduino Uno so only have 6 inputs  smiley-confuse

so it needs to be used for calculation even if you dont plan on printing the value?
Logged

Denmark
Offline Offline
Sr. Member
****
Karma: 10
Posts: 287
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't you mean the z-axis (yaw)? You need it for my code, but yes it it possible to calculate the angle with just one two values I think, haven't really researched on that, because it hasn't been a problem to me.

- Lauszus
Logged

Pages: 1 2 [3] 4 5 ... 37   Go Up
Jump to: