This is mostly a math/opencv question, the translation and angle in the ros message could be a translation and angle for anything- but there are some ros tf classes and methods that can help (I can update this with more details later, or maybe someone else can help out).
It looks like the affine matrix is of the form
a b tx
c d ty
I think you can convert the 2x2 part of the 2x3 affine matrix into a 3x3 rotation matrix then extract a quaternion which should plug into your goal message (MoveBaseGoal
or PoseStamped
? It's not super important which it is because they both use quaternions).
a b 0
c d 0
0 0 1
But the affine matrix isn't necessarily a good rotation matrix? So the underlying rotation matrix code may force it to conform or blindly try to use it without checking and bad results will come out later in the process?
transformations.py can help if using python, for C++ look at tf2::LinearMath::Matrix3x3
http://docs.ros.org/en/noetic/api/tf2...
You could create a Matrix3x3 with the row major formatting constructor using those abcd components above, then call getRotation
to get a Quaternion
out, then put the quaternion elements into your message:
tf2::Matrix3x3 rot(
a, b, 0,
c, d, 0,
0, 0, 1);
tf2::Quaternion quat;
rot.getRotation(quat);
my_transform.rotation.x = quat.getX();
my_transform.rotation.y = quat.getY();
my_transform.rotation.z = quat.getZ();
my_transform.rotation.w = quat.getW();
The translation is the last column of the affine matrix, just leave z 0.0 since you only have x and y.
https://math.stackexchange.com/questi... looks helpful.
You may also need to look into how to pull values out of an opencv matrix elsewhere if you know nothing at all about the cv Mat datatype and are using C++. #q358188 has an example of this and shows includes for the tf2 data types.