Skip to content
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

Merged
merged 4 commits into from
May 18, 2021

Conversation

JStech
Copy link
Contributor

@JStech JStech commented May 12, 2021

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

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

Copy link

@jliukkonen-pn jliukkonen-pn left a 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,

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.

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. 🤔

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?)

Copy link
Contributor

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?

Copy link
Contributor

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.

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.

Thumbs up for this approach.

@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #2664 (256114c) into master (01e594e) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
...bot_model/include/moveit/robot_model/robot_model.h 68.43% <0.00%> (-15.57%) ⬇️
moveit_core/robot_model/src/robot_model.cpp 78.21% <0.00%> (-0.76%) ⬇️
moveit_core/robot_state/src/robot_state.cpp 50.28% <0.00%> (-0.49%) ⬇️
...ipulation/pick_place/src/manipulation_pipeline.cpp 71.85% <0.00%> (-1.94%) ⬇️
...meterization/work_space/pose_model_state_space.cpp 82.06% <0.00%> (-0.64%) ⬇️
...eit/planning_scene_monitor/current_state_monitor.h 100.00% <0.00%> (ø)
...e/collision_detection_fcl/src/collision_common.cpp 78.61% <0.00%> (+0.26%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47af01b...256114c. Read the comment docs.

@JStech JStech mentioned this pull request May 12, 2021
6 tasks
Copy link
Contributor

@rhaschke rhaschke left a 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.

@v4hn
Copy link
Contributor

v4hn commented May 13, 2021 via email

@JStech
Copy link
Contributor Author

JStech commented May 13, 2021

Instead of repeating the same code snippet several times, I suggest providing an inline function for this sanity check.

Where do you recommend I put such a function? Maybe moveit_core/macros somewhere?

@rhaschke
Copy link
Contributor

Where do you recommend I put such a function? Maybe moveit_core/macros somewhere?

I would just put it into the same .cpp file. We don't need to expose this function, do we?

@JStech
Copy link
Contributor Author

JStech commented May 13, 2021

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 robot_state.cpp and robot_model.cpp--so define it in both? Another "local" option would be to put it in robot_model.h, which is included in both.

Also, one of the functions in robot_state.cpp then immediately calls the function in robot_model.cpp, so we don't really need the first check, although it'd probably be easier to interpret the error if it comes from the outer function.

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.

@JStech
Copy link
Contributor Author

JStech commented May 18, 2021

I defined the check in robot_model.h and it's used in both RobotState and RobotModel

Copy link
Contributor

@rhaschke rhaschke left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -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)
Copy link
Contributor

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.

@rhaschke rhaschke merged commit 5e8bd34 into moveit:master May 18, 2021
@JStech JStech deleted the pr-interpolation-warnings branch May 18, 2021 22:05
rhaschke pushed a commit to ubi-agni/moveit that referenced this pull request May 23, 2021
rhaschke pushed a commit to ubi-agni/moveit that referenced this pull request May 23, 2021
@rhaschke rhaschke mentioned this pull request May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants