如何从旋转矢量的欧拉-角(Sensor.TYPE_ROTATION_VECTOR) [英] How to get the euler-angles from the rotation vector (Sensor.TYPE_ROTATION_VECTOR)

查看:6077
本文介绍了如何从旋转矢量的欧拉-角(Sensor.TYPE_ROTATION_VECTOR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转动我的Andr​​oid设备在X方向(从-180度至180度),见下图。

结果
我只承担旋转矢量x值被改变。 Y和Z可能有一些噪音,但它应该是值之间没有太大的区别。

I rotated my android device in x direction (from -180 degree to 180 degree), see image below.
And I assume only Rotation vector x value is changed. Y and z maybe have some noise, but it should be not much difference among the values.

不过,我收到此。请参阅

However, I receive this. Kindly see

<一个href=\"https://docs.google.com/s$p$padsheets/d/1ZLoSKI8XNjI1v4exaXxsuMtzP0qWTP5Uu4C3YTwnsKo/edit?usp=sharing\" rel=\"nofollow\">https://docs.google.com/s$p$padsheets/d/1ZLoSKI8XNjI1v4exaXxsuMtzP0qWTP5Uu4C3YTwnsKo/edit?usp=sharing

我怀疑我的传感器有一些问题。

I suspect my sensor has some problem.

你知道吗?非常感谢你。

Any idea? Thank you very much.

吉米

推荐答案

您传感器是好的。结果嘛,旋转矢量项不能简单地与围绕一个特定轴旋转的角度。该 SensorEvent 结构构成的时间戳,传感器,准确性和值。根据矢量浮点[]的大小不一1-5。结果是基于单元quaternations值旋转向量,共同组成一个向量重新presenting相对于世界帧的装置(上述峰的帧​​)的方向如图所示:

他们是逆时针无单位的和积极的。

Your sensor is fine.
Well, the rotation vector entries cannot simply be related to the rotation angle around a particular axis. The SensorEvent structure constitutes of timestamp, sensor, accuracy and values. Depending on the vector the float[] of values vary in size 1-5.
The rotation vectors values are based on unit quaternations, all together forming a vector representing the orientation of the device(the frame of pic above) relative to the world frame as shown: They are unitless and positive counter-clockwise.

的旋转矢量的三个元素是等于一个的单元的最后三个组件四元数与所述; COS(θ/ 2)中,x的罪(θ/ 2)中,y 的罪(θ/ 2)中,z * SIN(θ/ 2)>。结果

The three elements of the rotation vector are equal to the last three components of a unit quaternion <cos(θ/2), xsin(θ/2), ysin(θ/2), z*sin(θ/2)>.

问:那么该怎么办呢?结果根据您的欧拉角约定(123或321 rot.序列,可能24序列),你可以ü计算出相应的角度:= [φ,θ,ψ]通过应用例如这个序列为321 konvention:结果
结果如果你已经有了旋转矩阵项获得欧拉像这样:结果的

Q: So what to do with it?
Depending on your Euler-angles convention (123 or 321 rot.-sequence, possible 24 sequences) you could calculate the corresponding angles u := [φ, θ, ψ] by applying e.g. this sequence for the 321 konvention:

If you already have the rotation matrix entries get euler like so:

酒店与Q1-3作为值[0-2] 结果别急,你的链接表不仅有3个值,这是类似我得到什么。这是一款 SensorEvent 矿,近三年从印刷值[] 搜索


with q1-3 being the values[0-2]
But wait, your linked table only does have 3 values, which is similar to what I get. This is oneSensorEvent of mine, the last three are printed from values[]

23191581386897 11 -75 -0.0036907701 -0.014922042 0.9932963
timestamp sensortype accuracy values[0 ] values[1 ] values[2 ]

4Q-3values​​ = 1Q未知。第一Q0是redunant信息(也是数独说它应该在那里下的值[3] ,但显然它不是)。因此,我们可以使用标准(=长度)来从其他三个计算Q0。结果 在这里输入的形象描述 结果将方程||常见问题|| = 1,解决Q0。现在,所有q0-3是已知的。
结果我的另外的是Android 4.4.2没有在第四估计航向精度(弧度)值[4] 但我得到了通过event.accuracy质的声明。这是code片段:)

4q-3values = 1q unkown. The first q0 is redunant info(also the
Set the equation ||q|| = 1 and solve for q0. Now all q0-3 are known.
Furthermore my android 4.4.2 does not have the fourth estimated heading Accuracy (in radians) inside value[4] but I got a qualitative statement via event.accuracy. This is the code snippet:)

                for (SensorEvent e : currentEvent) {
                    if (e != null) {
                        String toMsg = "";
                        for(int i = 0; i < e.values.length;i++) {
                            toMsg += " " + String.valueOf(e.values[i]);
                        }
                        iBinder.msgString(String.valueOf(e.timestamp) + " "+String.valueOf(e.sensor.getType()) + " " + String.valueOf(e.accuracy) + toMsg, 0);
                    }
                }

结果
把这些公式为code,你会得到的东西排序。结果正如我不得不处理转换quat-> EUL之前,这是功能转换季铵盐。最常见EULER_ANGLES(实际上应该是euler_parameters)konvention 321.号码重新present你通过旋转轴,由右至左读取它。 (所以首先1,然后2和最后3)在C ++中的转换是这样的:


Put those equations into code and you will get things sorted.
As I had to deal with conversion quat->eul before, this is the function converting quats. to the most common euler_angles(actually it should be euler_parameters) konvention 321. The numbers represent the axis you rotate through, reading it from right to left. (so first 1, then 2 and last 3) In C++ the conversion looks like:

    /*quaternation to euler_zyx (seq:321)*/
double* quat2eulerzyx(double* q){
    double qw =  sqrt(1. - q[0]*q[0] - q[1]*q[1] - q[2]*q[2]);
    double phi = atan2( 2.*(q[0]*q[1] + qw*q[2]), qw*qw + q[0]*q[0]- q[1]*q[1] - q[2]*q[2]);
    double theta = asin( -2.*(q[0]*q[2] - qw*q[1]));
    double psi = atan2( 2.*(q[1]*q[2] + qw*q[0]), qw*qw - q[0]*q[0]- q[1]*q[1] + q[2]*q[2]);
    //rad to deg
    phi *= (180./M_PI);
    theta *= (180./M_PI);
    psi *= (180./M_PI);

    //conventional: vec_after = R_m(phi)R_m(theta)R_m(psi) * vec_before (<-)
    q[0] = phi; 
    q[1] = theta;
    q[2] = psi;/**/
return q;
}

此函数接受三个值(季铵化合物的虚部)。这是正是你的传感器的回报,通过规范再披,theta和psi的计算Q0。这些都是从弧度转换为度并返回。 (是的,该功能可以进一步皱缩下来逆足改进)。
测试它像这样:

This function takes the three values (the imaginary parts of the quat.) which are exactly what your sensor returns, calculates q0 by the norm and then p theta and psi. Those are converted from radians to degree and returned. (yes, the function can be further shrunken down for perf. improvement). Test it like so:

double arr [3]; //our imag. part of the quaternion
double theta = M_PI; //angle to turn around pi = 180°
arr[0] = sin(theta/2.);
arr[1] = 0.;
arr[2] = 0.;
cout<<"quat "<< arr[0] << " "<<arr[1] <<" "<<arr[2] <<endl;
arr = quat2eulerzyx(arr);
cout<<"eul "<< arr[0] << " "<<arr[1] <<" "<<arr[2] <<endl;

结果
你会得到:


And you will get:

quat 1 0 0
eul  0 -0 180

结果问:什么角度意味着321 - 欧拉KONV。由于在code里面的评论指出:结果吃两koordinate帧A和B叠加对方(在对方所有轴),并开始通过1 = X_AXIS有角①旋转帧B. [2] ,然后2 =带角度Y_AXIS q [1] 最后3 =通过 Z_AXIS q [0] 。结果


Q: What do the angles mean for 321-euler konv. As stated in the comment inside the code:
Take two koordinate frames A and B superposing each other(all axis within each other) and start rotating frame B through 1=x_axis having angle q[2], then 2=y_axis with angle q[1] and finally 3=z_axis through q[0].

vec_after = R_m(phi)R_m(theta)R_m(psi) * vec_before (<-)

这些都是三所旋转youre去通过从A转到B.结果问:所以,如果你用X旋转首先它不应该是123那么结果
特技是初级旋转被从右到左,这对于123将意味着施加到z轴旋转,则Y轴则x轴。最终的结果是完全不同的。结果
结果问:那么如何得到转换的欧拉角从转动[0°,0°,0°]到如。 [0°,90°,0°]结果,首先对准从照片上,各自的公知的装置框架B两者帧看不见的worldframe A.您DONE重叠时的角度都得到[0°,0 °,0°]。刚刚弄清楚哪里是北,南,东,你坐在马上,并指出该设备帧B到这些方向。现在,当你周围的y轴逆时针旋转90°,你将拥有所需的[0°,90°,0°。
结果很乐意帮忙,朱利安结果
运动学来源:<一个href=\"https://scholar.google.de/scholar?cluster=3204262265835591787&hl=en&as_sdt=0,5&sciodt=0,5\"相对=nofollow>来源Diebel(斯坦福大学)与力学背景固体信息的,只是matlab的内部实现

Those are the three elementary rotations youre going through to go from A to B.
Q: So if you rotate through x first shouldnt it be 123 then ?
The trick is elementary rotations are applied from right to left, which for 123 would mean, rotate through z-axis then y-axis then x-axis. The end-result is totally different.

Q: So how to get the converted euler angles turn from [0°,0°,0°] to eg. [0°,90°,0°]?
First align both frames from the pictures, respective the known device frame B to the "invisible" worldframe A. Your done superposing when the angles all get to [0°,0°,0°]. Just figure out where is north, south and east where you are sitting right now and point the devices frame B into those directions. Now when you rotate around y-axis counter-clockwise 90° you will have the desired [0°,90°,0°].
Glad to help, Julian
kinematics source: Source Diebel(Stanford) with solid info on the mechanics background and simply matlab internal implementation

这篇关于如何从旋转矢量的欧拉-角(Sensor.TYPE_ROTATION_VECTOR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆