0
$\begingroup$

Rosanswers logo

Is there an equivalent function to assertQuaternionValid() in tf2? I suppose I could just re-implement the source code for the function using tf2 equivalents? http://docs.ros.org/en/diamondback/api/tf/html/c++/tf_8h_source.html#l00486


Originally posted by jn42 on ROS Answers with karma: 43 on 2021-09-18

Post score: 1


Original comments

Comment by osilva on 2021-09-19:
There is a thread that may be interesting to you:

https://github.com/ros/geometry2/pull/196

Comment by Mike Scheutzow on 2021-09-19:
I'm having trouble understanding this idea that a calculation should be refused because the quaternion is slightly un-normalized. It seems reasonable to log a warning if you think that characteristic is important, but by my thinking you should proceed with the calculation anyway.

Comment by lucasw on 2023-05-13:
Re-implementing that source code in python:

q = transform_stamped.transform.rotation
q_norm_error = abs(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w - 1.0)
text = f"quaternion norm error {q_norm_error:0.6f}, {q}".replace("\n", ", ")
if q_norm_error > 0.01:
    ...

Probably converting the quaternion to the transformations.py array representation and doing a dot with itself is better

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

In general with tf2 it's recommended to use a native linear math library which has an internal representation of the quaternion and as such should have logic for normalizing and checking the normalization of the quaternion. The API of tf2 is specifically scoped down to be specific to the buffer etc and not random linear math problem.

Re: why normalized. @Mike Scheutzow the reason to rejecting storing non-normalized quaterions into the storage is because they can effect future computations in ways that are untraceable to users. You can find more info at https://stackoverflow.com/questions/11667783/quaternion-and-normalization


Originally posted by tfoote with karma: 58457 on 2021-09-20

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by jn42 on 2021-09-20:
Ah ok the separation of concerns makes sense for why tf2 didn't port over an equivalent function. Thank you!

Comment by Mike Scheutzow on 2021-09-20:
@tfoote Thank you for the interesting link. I learned some new things about quaternions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.