2

I'm currently working on a project that is supposed to represent data collected from gyroscope as a simple 3d graph, but what I wrote doesn't quite work - I simply integrated axes and then rotated the object.

Been looking for a solution and found something called rotation matrix, but I don't quite understand how it works - guess I need to take start angles [0,0,0] and convert them into such matrix, then take gyro data [yaw,pitch,roll] and convert them into similar matrix, multiply them and calculate new angles based on this new matrix? And repeat this every time I get new package of gyro data using previous matrix as 'base'?

Did I get it right? What I need is how to rotate object that's already rotated, are there any resources about on this subject somewhere? Been looking for '3d rotation matrix' but not quite what I've been looking for...

Ali
  • 56,466
  • 29
  • 168
  • 265
Benji
  • 23
  • 4

1 Answers1

2

A tutorial on rotation matrices, as well as the integration you need is described in the

Direction Cosine Matrix IMU: Theory

manuscript.

Long story short, you cannot "simply integrate the axes and then rotate the object", unfortunately it's more sophisticated than that. :( Don't worry though, the manuscript tells you step-by-step what to do.

Euler angles (aka roll, pitch and yaw) are evil, they screw up the stability of your app, see for example

They are not useful for interpolation either. Just use rotation matrices and you will be happy you did.

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • Just for my understanding -- how do you think Euler angles differ from rotation matrices? How I learned it, Euler angle triplets can always be translated into a rotation matrix, and vice versa...I've been using *quaternions* to avoid the problems you mention; I know *they* are substantially different... – Rody Oldenhuis Aug 15 '12 at 18:37
  • 1
    "Euler angle triplets can always be translated into a rotation matrix, and vice versa" -- Well, most of the time, if you neglect the double cover and the singularity (gimbal lock) problems with Euler angles. You can also convert quaternions to rotation matrices and vice versa but you have double cover there too (AFAIK, never used). Euler angles, rotation matices and quaternions can all be used to represent the exact same thing, rotation, just be aware of the corner cases. – Ali Aug 15 '12 at 18:59
  • Correct me if Im wrong, but according to first link all I need to do is implement equation 17 (page 15), in which I multiply R(t) by matrix containing derivatives of gyro data? – Benji Aug 15 '12 at 20:03
  • @Benji Yes, equation 17. No, no derivatives of the gyro data. The gyroscopes give you the omega, and you have to the sampling rate, dt. And that is all you need to compute R(t). – Ali Aug 15 '12 at 20:52
  • @Ali-'The gyroscopes give you the omega, and you have to the sampling rate, dt.' - I dont understand this one - you mean I need to use angle calculated from gyro data and sampling rate (like, it shows 300 DPS with sampling 100 so I use 3?) One more thing - OK, so Ive got R(t), and I need to multiply it with my coordinates... but now, which coordinates? I have 4 points which form a square - I multiply R(t) with those points coordinates and get new coordinates. Next sample, and I have R(t+1). What do I multiply my new R(t+1) to obtain (t+1) point coordinates? Starting coordinates? – Benji Aug 15 '12 at 21:21
  • @Benji OK, there are 3 points. (i) Yes, you calculate the angle (d theta in equation 17) by multiplying the gyro data omega (degrees per second) and the sampling rate dt (second). (ii) The R(t) is the upper 3 by 3 elements of the OpenGL matrix. When you do any multiplication with the R(t), you just use these elements, and leave the 4. row and 4. column of the OpenGL matrix untouched. (iii) You either have to know the initial orientation, that is, the starting coordinates; or just start from the 3D identity matrix. – Ali Aug 16 '12 at 08:24
  • @Ali thanks for your time and help, I think Ive got this right now, but Im still unsure about something - could you take a look at [**this image**](http://i.imgur.com/paAih.jpg) ? (explaining it here without proper formatting would be difficult). Not sure if first or second version written in bold is correct (aka do I use starting coordinates and R(n) to calculate n+1 coordinates, or do I use coordinates from previous iteration) – Benji Aug 16 '12 at 09:44
  • @Benji Please give me some time, I can only check it later. – Ali Aug 16 '12 at 09:50
  • In mean time Ive tried implementing this in MatLab, but Im doing something wrong. Here's [my lame code](http://pastebin.com/S2vZgE9E). It DOES rotate, but way too fast compared with previous metod Ive used and starts expanding, reaching outside of axes before the other plot even STARTS moving - gyroscope noise alone makes it go crazy in less than 10 seconds... – Benji Aug 16 '12 at 18:46
  • @Benji I haven't forgotten you, don't worry, I just have to do something else, sorry... In the meantime, the Renormalization is missing from your code, please read and implement page 16-17. – Ali Aug 16 '12 at 18:53
  • @Benji OK, I have read the image you sent 9 hours ago. If I understand your notation correctly, it is the 1. pont that is correct. Everyting is very well explained on page 4. of the Direction Cosine Matrix IMU: Theory manuscript I linked in my answer. If it is rotating too fast it is perhaps due to using wrong units, make sure the `d theta = omega*dt` is in radian. And as I said before, the renormalization has to be implemented as well, see page 16-17. But it isn't the lack of renormalizaton that makes it rotate so fast. Fix the fast rotation first, before implementing the renormalization. – Ali Aug 16 '12 at 20:01
  • @Ali hello again :) Ive implemented renormalization, but it doesnt seem to help that much - [even more code](http://pastebin.com/kwQRzDwM). Im fairly sure angles are in radians, theyre even scaled in the code Ive pasted. This might be some big error I just dont see now... because even with normalization from eqn 21 the coordinates go nuts (start expanding). Ive implemented the other method and it works, yet the shape still rotates violently. One thing I couldnt find in paper - do I multiply new R with old R and then normalize or normalize first and then multiply? Neither seems to work correct – Benji Aug 16 '12 at 20:37
  • I FOUND THE SOURCE OF PROBLEM! Yes, gyroscope data were scaled to radians. Exept I forgot to divide them by sampling rate (/facepalm). Now its working. its... alive... ALIIIIVEEEE! Thanks a bunch for your help and time. – Benji Aug 16 '12 at 21:10