Using quaternion instead of roll, pitch and yaw to track device motion

前端 未结 2 1314
余生分开走
余生分开走 2020-12-05 12:20

Please bear with my long question, I am trying to make it as clear as possible.

What i am trying to do is, get the attitude(roll pitch and yaw) when a picture is tak

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 13:08

    I am not saying that the following is the solution to your problem, I have no idea how user-friendly this will be but I believe it is worth a shot. I see two issues: how you store the attitude and how you visualize them.

    Storage. I would save the attitude either as a quaternion or as a rotation matrix; CMAttitude provides both. (I personally prefer rotation matrices to quaternions as rotation matrices are easier to understand in my opinion. It is just a personal preference.)

    Visualization. You are using 3 markers to bring the phone to the same attitude as the saved one. These 3 markers came from yaw, pitch and roll, effectively ruining the stability of your application. Instead of these 3 markers I would visualize the rotation between the saved attitude and the current one. One way of doing it is to project the rotated 3 basis vectors onto the phone's screen. The nice thing about rotation matrices is that they give you exactly this without any extra computation. For example, to visualize the

    | 1 0 0 |
    | 0 1 0 |
    | 0 0 1 |
    

    rotation this rotation matrix represents, I only need to plot 3 arrows from [0, 0, 0] to (i) [1, 0, 0], (ii) [0, 1, 0] and (iii) [0, 0, 1]. That is, I only need to plot either the rows or the columns of the matrix (also depends on what you want whether the rows or the columns are better).

    To get the rotation between a saved rotation matrix S and the current rotation matrix C you need to compute CTS (in words: C transpose times S). You have aligned the phone with the saved attitude if your rotation matrix is the one shown above.

    An excellent tutorial on rotation matrices is the Direction Cosine Matrix IMU: Theory manuscript.

    Another way of visualizing the rotation between the saved and the current attitude is to transform it to angle-axis form. Then, I would project the axis to the phone's screen. The user first aligns the phone with the axis, than needs to rotate around the axis to match the saved attitude. Quaternions basically represent the axis-angle form, although in a nontrivial way.


    It requires significant further work on your part to alter this idea according to your needs; this is definitely not a complete answer. Nevertheless, I hope this help a bit.

提交回复
热议问题