Ask Your Question
0

How to get the Quaternion from Matrix with python

asked 2019-05-24 20:56:56 -0500

A_YIng gravatar image

Hello,

I found below code which is using for get the Quaternion values from Matrix. Then, I would like to do the same work with it, but it's C++ programming language. I can't find any similar python API to it.

geometry_msgs::msg::Pose  grasp_to_pose(gpd::GraspConfig & grasp)
{

  geometry_msgs::msg::Pose pose;
  tf2::Matrix3x3 orientation(
    grasp.approach.x, grasp.binormal.x, grasp.axis.x,
    grasp.approach.y, grasp.binormal.y, grasp.axis.y,
    grasp.approach.z, grasp.binormal.z, grasp.axis.z);

  tf2::Quaternion orientation_quat;
  orientation.getRotation(orientation_quat);
  orientation_quat.normalize();
  pose.orientation.x = orientation_quat.x();
  pose.orientation.y = orientation_quat.y();
  pose.orientation.z = orientation_quat.z();
  pose.orientation.w = orientation_quat.w();

  pose.position = grasp.top;

  return pose;
}

Source

Hope someone can help me to find out !

edit retag flag offensive close merge delete

Comments

Check this. Is that what you want?

kosmastsk gravatar imagekosmastsk ( 2019-06-06 04:41:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-06-08 05:21:36 -0500

dasanche gravatar image

updated 2019-06-08 13:49:42 -0500

jayess gravatar image

You can find the API you're looking for in here:

http://docs.ros.org/melodic/api/tf/ht...

The function you need is called:

tf.transformations.quaternion_from_matrix(matrix)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-05-24 20:56:56 -0500

Seen: 105 times

Last updated: Jun 08