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

PILZ adjust cartesian interpolation #3330

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

MarcoMagriDev
Copy link
Contributor

@MarcoMagriDev MarcoMagriDev commented Feb 8, 2025

Description

#3292

  • Added interpolation parameters
  • Sampled the trajectory using a uniform sampling_time computed from the equivalent rectangular motion profile (see this comment)
  • Adjusted sampling_time so that all points are equally spaced, including the last one
  • Modified pilz_industrial_motion_planner::TrajectoryBlenderTransitionWindow to no longer require sampling_time to be equal and uniform across the trajectories to be blended
  • add tests

MarcoMagriDev and others added 6 commits February 5, 2025 08:43
this ensures that the new sample time will be lowered, thus not violating precomputed distance interpolation constraints

at the same time avoids the issue on the last point generating small displacement interpolation
… trajectories from `pilz_industrial_motion_planner::TrajectoryBlenderTransitionWindow`
@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (9922704) to head (b25497e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...strial_motion_planner/src/trajectory_functions.cpp 0.00% 11 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

❗ There is a different number of reports uploaded between BASE (9922704) and HEAD (b25497e). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (9922704) HEAD (b25497e)
2 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #3330       +/-   ##
==========================================
- Coverage   45.60%   0.00%   -45.59%     
==========================================
  Files         716     566      -150     
  Lines       62443   51174    -11269     
  Branches     7558    6832      -726     
==========================================
- Hits        28471       0    -28471     
- Misses      33805   51174    +17369     
+ Partials      167       0      -167     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- computes shift of the second_trajectory using average instead of max. (this shift may be exactly the sample_time of the second trajectory if uniform)
- reduces sampling_time that approximates continuous time to 0.001 increasing the minimum distance between points to 1mm
- ensures the addition of the first and the last points

Tests:
- adapts `checkBlendingJointSpaceContinuity` and `checkBlendingCartSpaceContinuity` acceleration computations to take into account different time samples among the trajectories
- fixes occurrences of `joint_velocity_tolerance` and `joint_accleration_tolerance` in `checkBlendingJointSpaceContinuity`
- adjust `checkBlendingCartSpaceContinuity` to return False in case of failed checks
Copy link
Contributor

@rr-mark rr-mark left a comment

Choose a reason for hiding this comment

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

The approach here all looks sensible. I've left a few code review comments, and I'll try and find the time to look at those trajectory blender tests at some point this week.

@MarcoMagriDev
Copy link
Contributor Author

MarcoMagriDev commented Feb 10, 2025

@rr-mark thanks for your quick review

I will answer to each review separately.


Note that I am still working (on another branch) trying to develop the non constant sampling time on the LIN trajectory. See Problem 2.
The solution is not to change how velocity and acceleration accelerations are computed instead sampling the path at non constant sample time in order to ensure that points are distant enought for the numerical IK solver.
I am also adding some new tests for this PR

EDIT: here you can find a PR that tries to address the above mentioned problem. As soon as we agree to this version I can integrate those changes here or in another PR to start the discussion

idx_after = i + 1;
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since getWayPointDurationFromStart(i) should monotonically increase with i, it should only be necessary to find the first value of i for which getWayPointDurationFromStart(i) > time.

For performance, it might also be worth passing in optional start and end indices to interpolatePose, so if we expect to call it multiple times in order we don't need to search the whole trajectory every time.

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 just pushed a new version of this method incorporating your suggestions.

Let me know if you spot any issues or areas for improvement!

Copy link
Contributor

@rr-mark rr-mark left a comment

Choose a reason for hiding this comment

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

Since this PR is large, it might also be worth splitting it up - starting with a PR for just the trajectory blender.

// SLERP interpolation for rotation
Eigen::Quaterniond quat1(pose1.rotation());
Eigen::Quaterniond quat2(pose2.rotation());
interpolated_pose.linear() = quat1.slerp(lambda, quat2).toRotationMatrix();
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth pulling out this code into a function to calculate interpolated_pose = interpolate(pose1, pose2, lambda). Looks like this function would also be useful in cartesian_interpolator.cpp.

(This function might also already exist as part of KDL).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, thanks. I'll check if KDL already provides a function for this. If not, I'll implement a utility method to handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, KDL doesn’t seem to provide a built-in way to achieve this.

Looking at cartesian_interpolator.cpp, I found that a common method could be useful here. However, I’m not sure if merging the two would be the best approach.

for (std::size_t i = 0; i < blend_sample_num; ++i)

// Define an arbitrary small sample time to sample the blending trajectory
double sampling_time = 0.001;
Copy link
Contributor

@rr-mark rr-mark Feb 11, 2025

Choose a reason for hiding this comment

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

How easy would it be to use your nice interpolation parameters here instead of this arbitrary sampling time?

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 like this approach since it also can helps ensure a minimum Cartesian distance similarly to what has been done here (which can be beneficial for numerical IK solvers).

My only concern is that adopting this would make splitting up the PR no longer a valid option.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, fair. I guess splitting the PR is nice to have but not necessary.

@@ -258,9 +319,21 @@ void pilz_industrial_motion_planner::TrajectoryBlenderTransitionWindow::blendTra
Eigen::Quaterniond end_quat(blend_sample_pose2.rotation());
blend_sample_pose.linear() = start_quat.slerp(alpha, end_quat).toRotationMatrix();
Copy link
Contributor

Choose a reason for hiding this comment

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

(The interpolate function above would also be useful here: blend_sample_pose = interpolate(blend_sample_pose1, blend_sample_pose2, alpha).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, we only need to decide which is the best place for that utility method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, I’ve placed the method in trajectory_functions.

Let’s wait for input from a maintainer to see if they prefer making this method accessible from another dependency package, such as moveit_core, so it can be used here.

MarcoMagriDev and others added 4 commits February 12, 2025 07:44
…interpolatePose` efficiency, minor refactor changes
…adds `checkInterpolationParameters` testutils, adds `interpolationParameters` unit test for LIN generator
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.

3 participants