How to calculate quaternion from rotation vector?

asked 2018-02-15 13:39:41 -0500

Ahmad gravatar image

I'm using ROS kinetic to control Yumi ABB robot. For the calculation of the qauternion I've implemented a code in Matlab. The inputs are the start vector and the goal vector both of them are normalized. Then I apply the dot product to get the angle between the two vectors and then the cross product to get the angle of rotation.

For example my start vector is [0 0 1] and goal vector is [0 1 0] the dot product gives me an angle of pi and cross product gives me the rotation axis [-1 0 0].

Then I rotate this axis by the given angle

rotationVector = 1.5708 *[-1,0,0]
rotationMatrix = rotationVectorToMatrix(rotationVector)
quat = rotm2quat(rotationMatrix)

quat =

0.7071    0.7071         0         0

The results of my code are correct my question is there any function in ros to convert the rotation vector to quaternions? As I'm still making the calculations in Matlab and transfer the results to the ROS code manually and I want the process to be automated.

Thank you in advance.

edit retag flag offensive close merge delete



Would Eigen::Quaternion::FromTwoVectors(..) be of any help here?

gvdhoorn gravatar image gvdhoorn  ( 2018-02-15 13:57:59 -0500 )edit