Skip to content

Added check for invalid quaternions. - #1167

Merged
dhood merged 3 commits into
ros-visualization:kinetic-develfrom
StefanFabian:kinetic-devel
Dec 11, 2017
Merged

dhood merged 3 commits into
ros-visualization:kinetic-develfrom
StefanFabian:kinetic-devel

Conversation

@StefanFabian

Copy link
Copy Markdown
Contributor

Added checks for quaternions before passing them to OGRE to fix crashes due to unnormalized quaternions as described in #1142.

@wjwwood

wjwwood commented Oct 26, 2017

Copy link
Copy Markdown
Member

Thanks for pr, one of us will get to it asap.

@VictorLamoine

Copy link
Copy Markdown
Contributor

@wjwwood can this PR be merged? It's quite annoying to crash RViz because of this :)

Apparently keeping "Willow Garage, Inc" (ros-visualization#1142) was not the right thing (ros-visualization#1113).
@StefanFabian

StefanFabian commented Nov 21, 2017 •

Copy link
Copy Markdown
Contributor Author

After reading #1113, I changed the copyright statement.

@dhood dhood self-assigned this Nov 27, 2017

@dhood dhood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch, overall it looks good. Only one point of concern regarding the tolerance

Comment thread src/rviz/validate_quaternions.h Outdated

inline bool validateQuaternions( float w, float x, float y, float z )
{
return std::abs( w * w + x * x + y * y + z * z - 1.0f ) < 10e-5f;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a particular reason you switched to using 10e-5? If not, in tf2 they found the tolerance had to be relaxed it to 10e-3 (ros/geometry2@634fd0c), so please stick with 10e-3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I just felt like 10e-3 was a bit too relaxed for my preferences but if empirical evidence proves me wrong, I'll change it back to 10e-3.

@dhood

dhood commented Dec 11, 2017

Copy link
Copy Markdown
Contributor

@ros-pull-request-builder retest this please

@dhood dhood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating

@dhood
dhood merged commit b329145 into ros-visualization:kinetic-devel Dec 11, 2017
@pbeeson

pbeeson commented Dec 28, 2017

Copy link
Copy Markdown

I'm very happy that this might fix problems with IMs crashing RViz that wev'e seen. However, is there a reason why the patch couldn't just normalize the quaternion in place?

@StefanFabian

Copy link
Copy Markdown
Contributor Author

Good question.
I'd say there is a reason which is that this would just hide the symptoms of possibly flawed code.
However, just displaying a warning and normalizing would probably be more in line with the behavior before the crashes.

@pbeeson

pbeeson commented Dec 28, 2017 •

Copy link
Copy Markdown

Yes. It took me over an hour after upgrading my home desktop this morning to figure out why my Interactive Markers weren't showing up. It traced back to a bad Quaternion in an IM setup library (not written by me). The fix was trivial, but if you had enforced normalization here instead of checking, my code would have worked as "normal".

If you took this to an extreme, you could just always normalize no matter what. Then you wouldn't have to use arbitrary thresholds for the magnitude like 10e-3 (unless that's a threshold that came from OGRE). Of course the issue here would be a minor slowdown to do 4 extra divides, but that's nothing really.

@davetcoleman

Copy link
Copy Markdown
Member

This change broke my workflow today too. Note @rhaschke has proposed a fix: #1179

@pbeeson

pbeeson commented Jan 2, 2018

Copy link
Copy Markdown

@wjwwood I agree with @davetcoleman #1179 looks much more appropriate. If it’s zero then error otherwise just normalize.

@pbeeson

pbeeson commented Jan 2, 2018

Copy link
Copy Markdown

I guess it was actually @dhood that approved and merged the original PR.

@dhood

dhood commented Jan 2, 2018

Copy link
Copy Markdown
Contributor

I didn't expect this change to impact so many users since quaternions really ought to be normalised (TF will reject them and roswtf will report them). From the number of responses here I can appreciate that it's simply not a reasonable expectation to make. I agree with @rhaschke's note in #1178 (comment) that there should have been a smoother transition phase rather than rejecting them, which I will look into ASAP

@StefanFabian

Copy link
Copy Markdown
Contributor Author

First, I want to apologize that my PR caused this many issues.
If I may still have a word on solving this issue, I'd propose to also allow zeros and just set them to the identity quaternion before this leads to the next issue.
I would, however, not remove the warning because an unnormalized quaternion can indicate that there's an error in the code. It may just be a missing normalization but it could also be a more serious issue.
Hence, I would suggest to replace all returns in this commit by a call to a normalization function which sets all null quaternions to identity quaternions and simply normalizes the rest.

@rhaschke

rhaschke commented Jan 3, 2018

Copy link
Copy Markdown
Contributor

@StefanFabian This is more or less what I proposed in #1179 ;-)

rhaschke added a commit to rhaschke/rviz that referenced this pull request Jan 3, 2018
dhood added a commit that referenced this pull request Jan 4, 2018
dhood pushed a commit that referenced this pull request Jan 5, 2018
* Revert "Added checks for invalid quaternions. (#1167)"

This reverts commit b329145.

* normalize invalid quaternions instead of rejecting them

Normalization of quaternions usually is done by rviz::FrameManager::transform()
which transforms a ROS pose into an Ogre position + orientation.
Only in some rare cases, a ROS quaternion was directly used as an
Ogre::Quaternion, which then requires handling of null quaternions (as
they arise from uninitialized ROS pose msgs).

* addressed Dave's comments

* add more verbose warnings

... as suggested in #1182

* Revert "Revert "Added checks for invalid quaternions. (#1167)""

This reverts commit 42a4416.

* Minimise diff

* Warning will already be output for invalid quats when msg validated

* Return pre-normalised length from normalizeQuat

Don't mix logic for what is considered a valid quat into this function;
matches Ogre

* Use validateQuaternions for map

Logic of what makes a quaternion valid isn't in normalizeQuaternion;
also gets the invalid quaternion value logged to console

* Remove unnecessary 0 setting

* Reduce number of divisions
DLu pushed a commit to DLu/rviz that referenced this pull request Dec 11, 2025
…ization#1167)

The situation is complicated, but in versions of Ubuntu
prior to Focal and versions of Debian prior to Bookworm,
the name of the library was 'libfreetype6-dev'.  Since
Focal and Bookworm, the name of the library is 'libfreetype-dev'.
While 'libfreetype-dev' provides a "virtual package"
for 'libfreetype6-dev', we should really use the new canonical
name.

Further, there is currently a bug on ros_buildfarm where
it doesn't properly deal with "virtual packages" like this.
This is currently preventing this package from building on
Ubuntu Noble.  That bug is being worked on separately.

Finally, I'll note that we already have a libfreetype-dev
key in rosdep, so we just switch to using that here which
should work around the bug on the buildfarm, and also use
the correct canonical name going forward.

Signed-off-by: Chris Lalancette <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants