DSPRelated.com
Forums

Getting Rotation Matrix from Gyro Data

Started by sia4uin May 7, 2015
Hello All

Need some clarification and help.

I have raw acceleration data, A, from the SmartPhone which is in the
coordinate frame of the device.

I need to find a rotation matrix R which describes the rotation from the
earth coordinate system to the coordinate system of the device. 

I then need to multiply the (R*A) and then get the mean of it.

The ultimate goal is to estimate Gravity from acceleration data.

But I do not know how to obtain the rotation matrix R? Is it possible to
obtain it from the Gyro data?

I really need some help on this.

Best Regards

Sia
---------------------------------------
Posted through http://www.DSPRelated.com
"sia4uin" <105263@DSPRelated> writes:

> Hello All > > Need some clarification and help. > > I have raw acceleration data, A, from the SmartPhone which is in the > coordinate frame of the device. > > I need to find a rotation matrix R which describes the rotation from the > earth coordinate system to the coordinate system of the device. > > I then need to multiply the (R*A) and then get the mean of it. > > The ultimate goal is to estimate Gravity from acceleration data. > > But I do not know how to obtain the rotation matrix R? Is it possible to > obtain it from the Gyro data? > > I really need some help on this. > > Best Regards > > Sia
Sia, Caveat: I am not an expert. The following just follows from the "laws of physics" (which you "canna change" --Scottie, Star Trek) and a little knowledge/experience. If all you have is linear acceleration data, then theoretically you cannot find R. Finding R essentially means finding the gravity vector - cart before the horse. With linear acceleration AND gyro, you can do it theoretically. The problem is that a real-world implementation will have things like biases in your gyro and accelerometer which will throw you off (assume you begin with proper initial conditions) eventually. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
> >Sia, > >Caveat: I am not an expert. The following just follows from the "laws >of >physics" (which you "canna change" --Scottie, Star Trek) and a little >knowledge/experience. > >If all you have is linear acceleration data, then theoretically you >cannot find >R. Finding R essentially means finding the gravity vector - cart before >the horse. > >With linear acceleration AND gyro, you can do it theoretically. The >problem is that a real-world implementation will have things like >biases >in your gyro and accelerometer which will throw you off (assume you >begin with proper initial conditions) eventually. >-- >Randy Yates >Digital Signal Labs >http://www.digitalsignallabs.com
Hello Randy Thanks for your reply. The ultimate goal is to implement a mobile Orientation tracker. The following paragraph is from a published paper. Assume we want to estimate the gravity vector at time t given a window of historical accelerometer data a(t&minus;T:t) of size T. We first rotate acceleration signals a(t&minus;T:t&minus;1) to the same orientation as a(t), and then estimate the gravity at time t as the mean of the acceleration readings after the rotation. Specifically, the gravity at time t is estimated as g(t) = R(t) sum_k[ (R(k) * a(k))/T ] where k goes from t-T to t where a(k) is the acceleration vector in the coordinate frame of the device, and R(k) is the rotation matrix describing the rotation from the earth coordinate system to the coordinate system of the device at time k, as obtained from the Kalman Filter. Now the paper does not say how R(k) is obtained. I can send the post the link of the paper if you prefer. (The problem is that I know never worked with sensors before and I have no clue about Rotations and the associated concepts. And the boss needs results rather immediately). Best Regards Sia --------------------------------------- Posted through http://www.DSPRelated.com
On Thu, 07 May 2015 13:20:19 -0500, sia4uin wrote:


>>Sia, >> >>Caveat: I am not an expert. The following just follows from the "laws of >>physics" (which you "canna change" --Scottie, Star Trek) and a little >>knowledge/experience. >> >>If all you have is linear acceleration data, then theoretically you >>cannot find R. Finding R essentially means finding the gravity vector - >>cart before the horse. >> >>With linear acceleration AND gyro, you can do it theoretically. The >>problem is that a real-world implementation will have things like biases >>in your gyro and accelerometer which will throw you off (assume you >>begin with proper initial conditions) eventually. >>-- >>Randy Yates Digital Signal Labs http://www.digitalsignallabs.com > > Hello Randy > > Thanks for your reply. > > The ultimate goal is to implement a mobile Orientation tracker. The > following paragraph is from a published paper. > > Assume we want to estimate the gravity vector at time t given a window > of historical accelerometer data a(t&minus;T:t) of size T. We first rotate > acceleration signals a(t&minus;T:t&minus;1) to the same orientation as a(t), and > then estimate the gravity at time t as the mean of the acceleration > readings after the rotation. Specifically, the gravity at time t is > estimated as > > g(t) = R(t) sum_k[ (R(k) * a(k))/T ] > > where k goes from t-T to t > > where a(k) is the acceleration vector in the coordinate frame of the > device, and R(k) is the rotation matrix describing the rotation from the > earth coordinate system to the coordinate system of the device at time > k, as obtained from the Kalman Filter. > > Now the paper does not say how R(k) is obtained. I can send the post the > link of the paper if you prefer. > > (The problem is that I know never worked with sensors before and I have > no clue about Rotations and the associated concepts. And the boss needs > results rather immediately). >
"K&aacute;lm&aacute;n" is a Hungarian name that most likely means "remainder", but definitely does not mean "magic". Thus, a "Kalman filter" is not a Magic filter, and cannot do magic things. There simply is not enough information available from a gyro and accelerometer alone* to get a decent rotation vector. Can't do it. Won't work. There are all sorts of accelerated frames of reference that can give the same readings, but where the "down" vector doesn't point down, never mind the unreliability of the "north" vector. With sensors that are far, far better than you find in a cell phone, a vehicle that's moving (and accelerating) slowly compared to the earth's surface, and a location far enough away from the North or South pole (how far depends on how good the sensors are), you can get a reliable direction indication -- this is how gyro compasses work. You can get orientation from cell phone quality sensors AND GPS -- but only if you are getting decent GPS, and only if the phone is experiencing changing acceleration (that's right: sometimes you need to know a little jerk to know which way is up (that's a joke)). If there were a Kalman filter to give you R, then you wouldn't need to do what you're doing. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
On Thu, 07 May 2015 13:44:41 -0400, Randy Yates wrote:

> "sia4uin" <105263@DSPRelated> writes: > >> Hello All >> >> Need some clarification and help. >> >> I have raw acceleration data, A, from the SmartPhone which is in the >> coordinate frame of the device. >> >> I need to find a rotation matrix R which describes the rotation from >> the earth coordinate system to the coordinate system of the device. >> >> I then need to multiply the (R*A) and then get the mean of it. >> >> The ultimate goal is to estimate Gravity from acceleration data. >> >> But I do not know how to obtain the rotation matrix R? Is it possible >> to obtain it from the Gyro data? >> >> I really need some help on this. >> >> Best Regards >> >> Sia > > Sia, > > Caveat: I am not an expert. The following just follows from the "laws of > physics" (which you "canna change" --Scottie, Star Trek) and a little > knowledge/experience. > > If all you have is linear acceleration data, then theoretically you > cannot find R. Finding R essentially means finding the gravity vector - > cart before the horse. > > With linear acceleration AND gyro, you can do it theoretically. The > problem is that a real-world implementation will have things like biases > in your gyro and accelerometer which will throw you off (assume you > begin with proper initial conditions) eventually.
Actually with linear accelerometers and gyro, and no other information, you _cannot_ do it, even theoretically. You can do it if you have position information (i.e. GPS) with cell-phone quality sensors and enough changing acceleration, you can get orientation _and_ latitude (but not longitude) if you have far better sensors than in a cell phone, if you aren't moving rapidly with respect to the earth, and if your longitude isn't too great -- but you can't do it with just inertial sensors. Blame Einstein, it's his fault. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
On Thu, 07 May 2015 11:52:23 -0500, sia4uin wrote:

> Hello All > > Need some clarification and help. > > I have raw acceleration data, A, from the SmartPhone which is in the > coordinate frame of the device. > > I need to find a rotation matrix R which describes the rotation from the > earth coordinate system to the coordinate system of the device. > > I then need to multiply the (R*A) and then get the mean of it. > > The ultimate goal is to estimate Gravity from acceleration data. > > But I do not know how to obtain the rotation matrix R? Is it possible to > obtain it from the Gyro data? > > I really need some help on this.
If you just need a fairly good estimate of "down", then pick some arbitrary value of R at power-up, and rotate it using the gyro information. Then whatever direction your rotated average acceleration is pointing must be "down". This won't work well if you're going hell-bent for leather on some circular track that takes longer to traverse than the time constant of your acceleration filter, but it's probably the best you'll do without more information than you can get from just inertial sensors. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
> >If you just need a fairly good estimate of "down", then pick some >arbitrary value of R at power-up, and rotate it using the gyro >information. Then whatever direction your rotated average acceleration >is >pointing must be "down". > >This won't work well if you're going hell-bent for leather on some >circular track that takes longer to traverse than the time constant of >your acceleration filter, but it's probably the best you'll do without >more information than you can get from just inertial sensors. > >-- > >Tim Wescott >Wescott Design Services >http://www.wescottdesign.com
Hello Tim, Thank you for your reply. Here is the paper that I am trying to decode. Please have a look at Equation 1. I find it confusing and it is making me mad. www.ipin2014.org/wp/pdf/3A-4.pdf Best Regards Sia --------------------------------------- Posted through http://www.DSPRelated.com
On Thu, 07 May 2015 16:28:51 -0500, sia4uin wrote:


>>If you just need a fairly good estimate of "down", then pick some >>arbitrary value of R at power-up, and rotate it using the gyro >>information. Then whatever direction your rotated average acceleration >>is pointing must be "down". >> >>This won't work well if you're going hell-bent for leather on some >>circular track that takes longer to traverse than the time constant of >>your acceleration filter, but it's probably the best you'll do without >>more information than you can get from just inertial sensors. >> > Hello Tim, > > Thank you for your reply. > > Here is the paper that I am trying to decode. Please have a look at > Equation 1. I find it confusing and it is making me mad. > > www.ipin2014.org/wp/pdf/3A-4.pdf
OK. Here goes: 1: Know that I'm a cynical bastard. This conditions just about everything else I say here. 2: In my opinion the bullshit:information ratio in this paper is high. This is backed by the fact that it's a conference paper and not something that's been refereed. But, that's my opinion. See (1). 3: The "Kalman filter" that they refer to is the "IMU Fusion" block in Figure 1. I have no clue what they think they mean when they say "standard Kalman filter", but they're proudly combining it with their "RIOT", which pretty much says to me that (a) their "standard Kalman filter" is severely lacking, and (b) instead of making it into a decent Kalman filter (by taking gyro drift into account), they're making a PPKF (Piss Poor Kalman Filter) out of the combination. See (1). 4: You have totally failed to mention the fact that compass directions are available. To the extent that they're actually reliable in anything but a lab setting (see (1)), that makes a huge difference on the useful information that you can pull out of the inertial sensors, because suddenly you know which way North is, and possible even the magnetic declination. So as long as you make sure to stay out of malls that are built out of anything ferrous (see (1)), you're in fine shape. 4a: Given a 3D magnetometer AND a 6-axis IMU (your accelerometer and gyro), then you actually have a hope of pulling this off. 5: What the author wants you to do is make a "standard Kalman filter". We'll call it a SKF, because that works for what it really is -- a Stupid Kalman Filter (see (1)), because it's ignoring some (theoretically) easy to correct for states, like gyro and accelerometer offsets. Then the author wants you to use the output of the SKF (which you have written, by the way) to generate an estimate of the gravity vector, which is then used in some unmentioned and probably sub-optimal way to correct the SKF. Hence, PPKF. You've mentioned that the boss is getting antsy. I assume that he got all starry-eyed on reading this paper, took the bullshit:information ratio as 0 because of the hifalutin' language, and now expects you to spin gold out of BS, without even having any clean straw in sight. I think that it's a pretty big assumption to think that this overall technique will work at all (see the phrase in the opening paragraph: "widely viewed as being a promising technique". Not "it works". See also (1)). I think that if it would work. the way to do it would be to pitch the PPKF, and replace it with a PRKF (perfectly reasonable Kalman filter). This would be one that uses the 9- or 10-element state vector [orientation, gyro offset, accelerometer offset] (Note that each named elements is 3-D, except for orientation which may be profitably implemented as a quaternion, if you don't mind mild physiological side-effects on the development staff such as exploding heads.) Frankly, I think that you are in over your head. I don't think there's a simple answer to this that does not involve you learning how a Kalman filter works, in depth, and that effort must be preceded by learning all the requisite mathematics. If you don't already know, figure that it's a good chunk of the first year of a Master's program, ASSUMING that your undergraduate course of study was heavy on the math. I recommend Dan Simon's "Optimal State Estimation" as a good book on Kalman Filter theory - but be warned that without a good grounding up through differential equations and at least one senior/graduate course in mathematical statistics it'll be just so much gobbledygook. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Tim Wescott <seemywebsite@myfooter.really> writes:

> On Thu, 07 May 2015 13:44:41 -0400, Randy Yates wrote: > >> "sia4uin" <105263@DSPRelated> writes: >> >>> Hello All >>> >>> Need some clarification and help. >>> >>> I have raw acceleration data, A, from the SmartPhone which is in the >>> coordinate frame of the device. >>> >>> I need to find a rotation matrix R which describes the rotation from >>> the earth coordinate system to the coordinate system of the device. >>> >>> I then need to multiply the (R*A) and then get the mean of it. >>> >>> The ultimate goal is to estimate Gravity from acceleration data. >>> >>> But I do not know how to obtain the rotation matrix R? Is it possible >>> to obtain it from the Gyro data? >>> >>> I really need some help on this. >>> >>> Best Regards >>> >>> Sia >> >> Sia, >> >> Caveat: I am not an expert. The following just follows from the "laws of >> physics" (which you "canna change" --Scottie, Star Trek) and a little >> knowledge/experience. >> >> If all you have is linear acceleration data, then theoretically you >> cannot find R. Finding R essentially means finding the gravity vector - >> cart before the horse. >> >> With linear acceleration AND gyro, you can do it theoretically. The >> problem is that a real-world implementation will have things like biases >> in your gyro and accelerometer which will throw you off (assume you >> begin with proper initial conditions) eventually. > > Actually with linear accelerometers and gyro, and no other information, > you _cannot_ do it, even theoretically. You can do it if you have > position information (i.e. GPS) with cell-phone quality sensors and enough > changing acceleration, you can get orientation _and_ latitude (but not > longitude) if you have far better sensors than in a cell phone, if you > aren't moving rapidly with respect to the earth, and if your longitude > isn't too great -- but you can't do it with just inertial sensors. Blame > Einstein, it's his fault.
Are you merely saying you can't do it without knowing initial conditions? Yes, you need initial conditions (linear position, linear velocity, angular position, angular velocity, in all three directions). If not, perhaps you should discuss this with Dr. Don Heckathorn (formerly of MIT Lincoln Labs) and the GEC-Marconi Hazeltine Hellfire Missile Inertial Measurement Unit team... -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
A pre-GPS (1976) book that develops, from scratch, coordinate frames, rotations, gyro theory, inertial nav, Kalman filtering, a matrix theory appendix and more -- is still being used for seminars I teach.  Kalman updates to an inertial nav system involves all those topics; gotta cover  `em all.
http://jameslfarrell.com/publications/published-books-gnss-aided-navigation-and-tracking/
==================================================
On Thursday, May 7, 2015 at 12:52:25 PM UTC-4, sia4uin wrote:
> Hello All > > Need some clarification and help. > > I have raw acceleration data, A, from the SmartPhone which is in the > coordinate frame of the device. > > I need to find a rotation matrix R which describes the rotation from the > earth coordinate system to the coordinate system of the device. > > I then need to multiply the (R*A) and then get the mean of it. > > The ultimate goal is to estimate Gravity from acceleration data. > > But I do not know how to obtain the rotation matrix R? Is it possible to > obtain it from the Gyro data? > > I really need some help on this. > > Best Regards > > Sia > --------------------------------------- > Posted through http://www.DSPRelated.com