-
Notifications
You must be signed in to change notification settings - Fork 938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add warning if interpolation parameter is out of range [0, 1] #2664
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice improvement!
@@ -1290,6 +1290,8 @@ double RobotModel::distance(const double* state1, const double* state2) const | |||
|
|||
void RobotModel::interpolate(const double* from, const double* to, double t, double* state) const | |||
{ | |||
ROS_WARN_STREAM_COND_NAMED(std::isnan(t) || t < 0. || t > 1., LOGNAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add std::isinf
check too? Also, typo in word parameter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, should this whole function just fail if the fraction t
is not reasonable? Print error and return instead of giving a warning? After all, there was a crash when t
was NaN
. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe infinite values will be caught by t < 0. || t > 1.
. Actually, I think a NaN would also, but I'm not sure that's true across all platforms, etc. Thanks for the spelling catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was on the fence about how strongly it should react to an incorrect value. Since it's a void
return type, failure isn't really an option, just complaining and doing nothing. (Or, maybe, throwing an exception?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should probably throw an exception. Interpolating from NaNs and infs sounds dangerous. What about an assert
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Values smaller than 0 and larger than 1 are perfectly fine: You just extrapolate beyond the point. However, a warning in this case is probably useful. nan
and inf
could throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Values smaller than 0 and larger than 1 are perfectly fine: You just extrapolate beyond the point. However, a warning in this case is probably useful.
nan
andinf
could throw.
Thumbs up for this approach.
Codecov Report
@@ Coverage Diff @@
## master #2664 +/- ##
==========================================
- Coverage 60.49% 60.48% -0.00%
==========================================
Files 402 402
Lines 29637 28983 -654
==========================================
- Hits 17925 17528 -397
+ Misses 11712 11455 -257
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of repeating the same code snippet several times, I suggest providing an inline function for this sanity check.
Funny and frustrating how many comments such a minor patch can generate...
I support throwing an exception for `nan` and `inf` values,
though one could argue that the valid range is documented in doxygen and thus valid by contract.
(We are not writing Ada though, so there's no way to check contracts :)).
Printing a warning in this case and still running invalid computations is not an option for me.
I'm actually a fan of extrapolation-support here because it is supported for free and thus would allow all valid double values here,
but we also provide `RobotState::integrateVariableVelocity` for related use-cases.
So if you insist on restricting the use of the method to its documented specification it should throw for values outside [0;1] as well.
|
Where do you recommend I put such a function? Maybe |
I would just put it into the same .cpp file. We don't need to expose this function, do we? |
But I'm checking in both Also, one of the functions in I feel like all of this is a matter of style, and I don't see a strong reason to do it one way or another. Just tell me what will get approved :-P. |
I defined the check in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more nitpick. Otherwise, I approve.
@@ -61,6 +61,15 @@ namespace core | |||
{ | |||
MOVEIT_CLASS_FORWARD(RobotModel); // Defines RobotModelPtr, ConstPtr, WeakPtr... etc | |||
|
|||
static inline void checkInterpolationParamBounds(const char LOGNAME[], const double& t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't pass simple data types as double by reference:
https://stackoverflow.com/questions/7561690/why-do-we-not-pass-pod-by-reference-in-functions
@@ -61,7 +61,7 @@ namespace core | |||
{ | |||
MOVEIT_CLASS_FORWARD(RobotModel); // Defines RobotModelPtr, ConstPtr, WeakPtr... etc | |||
|
|||
static inline void checkInterpolationParamBounds(const char LOGNAME[], const double& t) | |||
static inline void checkInterpolationParamBounds(const char LOGNAME[], double t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have kept const
. But fine now, anyway.
Description
Added warnings if the interpolation parameter
t
is outside the range [0, 1] or NaN. Would have helped in debugging something recently.Maybe it would be good to also clamp the value to [0, 1] (and make a NaN a 0 or something)?
Checklist