ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Equivalent of checking quaternion is valid in tf2

asked 2021-09-18 22:59:49 -0600

jn42 gravatar image

updated 2021-09-20 10:01:56 -0600

Mike Scheutzow gravatar image

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/ap...

edit retag flag offensive close merge delete

Comments

There is a thread that may be interesting to you:

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

osilva gravatar image osilva  ( 2021-09-19 04:51:00 -0600 )edit

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-09-19 07:55:32 -0600 )edit

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

lucasw gravatar image lucasw  ( 2023-05-13 09:54:17 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-20 00:18:06 -0600

tfoote gravatar image

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/1...

edit flag offensive delete link more

Comments

Ah ok the separation of concerns makes sense for why tf2 didn't port over an equivalent function. Thank you!

jn42 gravatar image jn42  ( 2021-09-20 08:04:44 -0600 )edit

@tfoote Thank you for the interesting link. I learned some new things about quaternions.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-09-20 09:58:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-09-18 22:59:01 -0600

Seen: 540 times

Last updated: Sep 20 '21