Robotics StackExchange | Archived questions

How to calculate quaternion from rotation vector?

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.

Asked by Ahmad on 2018-02-15 14:39:41 UTC

Comments

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

Asked by gvdhoorn on 2018-02-15 14:57:59 UTC

Answers