Robotics StackExchange | Archived questions

tf::Transform a covariance Matrix

Hey there,

I simply would like to transform a covariance Matrix from one coordinate frame to another one.

Now what I have is the covariance matrix of a position which simply consists out of 3 diagonal values so basically a vector for the covariance in x, y, and z direction.

                [a, 0, 0
Cov_mat =        0, b, 0
                0, 0, c]

Moreover I have the rotation matrix between the two coordinate frames I would like to transform (named R)

Now I would like to transform like this:

newCov = R*Covmat*R^T

My problem the new covariance matrix is 3x3 and can I also now simply extract the diagonal values of this matrix?

Cause as a result I also would like to just have 3 covariance values for the major axis ....

One Idea I saw was doing this:

newCov.getRPY(resultcov[0], resultcov[1], resultcov[2]);

But i do not understand in detail what this method getRPY of a matrix does ....

My full code looks like this now:

  tf::Quaternion cov_pos_quat;
  cov_pos_quat.setRPY(cov_in[0], cov_in[1], cov_in[2]);
  tf::Matrix3x3 rotation_m = tf::Matrix3x3(transform.getRotation());
  tf::Matrix3x3 cov_pos = rotation_m*tf::Matrix3x3(cov_pos_quat)*rotation_m.transpose();
  cov_pos.getRPY(cov_out[0], cov_out[1], cov_out[2]);

Asked by Markus on 2018-05-16 01:57:02 UTC

Comments

Answers

You can find the documentation of the setRPY method here: http://docs.ros.org/kinetic/api/tf/html/c++/classtf_1_1Quaternion.html#ab34dfef6a01c1ece07bea92d485b0576

The implementation can be found here: (note this is the melodic branch but it is the same since indigo) https://github.com/ros/geometry/blob/melodic-devel/tf/include/tf/LinearMath/Quaternion.h#L90-L109

This method modifies the quaternions and given the Roll Pitch Yaw convention, which is the aeronautic convention for defining angles: https://en.wikipedia.org/wiki/Aircraft_principal_axes

getRPY is the exact opposite, given a matrix you get the angles corresponding to the convention, the implementation can be found here: https://github.com/ros/geometry/blob/melodic-devel/tf/include/tf/LinearMath/Matrix3x3.h#L360-L368

Asked by VictorLamoine on 2018-05-16 07:46:20 UTC

Comments