I am using RobotStudio to move an end-effector from one coordinate and direction to another coordinate and direction. I understand how to move the robot to all my points, but for the direction T need four quaternian values q1, q2, q3 and q4. I know the directional vector for each point, but the question is:
How do i calculate quaternion values from two vectors?
The end-effector's rotation about its own $z$-axis can be anything and does not matter for me. I have tried to calculate the two vectors to a rotational matrix from which I can easily get the quaternions, but with every different method for calculating the rotational matrix I get different results.
Using the method given by Jur van der Berg in Calculate Rotation Matrix to align Vector A to Vector B in 3d? in MATLAB I get these calculations:
a=[-1.308199919 -2.545574849 -10.6211422]';
b=[-1.422934396 -2.595777939 -10.59420571]';
v = cross(a,b);
vx = [0 -v(3) v(2) , v(3) 0 -v(1), -v(2) v(1) 0 ];
c = dot(a,b);
I = eye(3);
R1=I+vx+vx^2*(1/(1+c))
This my result:
R1 =
0.9867 0.2202 1.2550
-0.2326 0.9966 0.5995
-1.2527 -0.6041 0.9841
However, using Shiyu's method in same thread, I get what I believe is the correct answer:
R2 =
0.9999 0.0018 0.0104
-0.0019 1.0000 0.0050
-0.0104 -0.0050 0.9999
Do you know what is the problem with my calculations or whether there is a better way to do it?
I know I ask two questions, I would prefer a good method to calculate the quaternions directly from two vectors, but if you can fix my calculations it would be really appreciated.
Thanks a lot, I hope you can help.