Skip to content

Iterative cubic spline - #441

Merged
davetcoleman merged 27 commits into
moveit:kinetic-develfrom
kennethanderson:kinetic-iterative-cubic-spline
Jan 27, 2018
Merged

davetcoleman merged 27 commits into
moveit:kinetic-develfrom
kennethanderson:kinetic-iterative-cubic-spline

Conversation

@kennethanderson

@kennethanderson kennethanderson commented Feb 11, 2017 •

Copy link
Copy Markdown
Contributor

Description

Ruben's idea of fitting a cubic spline to a trajectory is a very good one: #382 . Forcing the trajectory to a cubic should prevent the controller from overfitting the data, the problem presented here: #160 .

I've taken the concept a little further by repeatedly fitting the spline and adjusting timestamps until all constraints are satisfied. This is similar to the way IPTP works, but instead of using local averages, the instantaneous values are used instead.

This technique is presented as another trajectory time parameterization class that can be used instead of IPTP. It also adds some simple unit tests. Initial/final velocity and acceleration can be specified. The constraints imposed are velocity, acceleration, and jerk. Here is a straight-line trajectory of 11 points:

spline

Ruben graciously provided some sample trajectories using RRT-Connect with a Kuka IIWA in a fairly cluttered scene. The trajectories have between 25 and 70 waypoints. These are the resulting spline trajectories (this is the calculated/interpolated spline curves, it is not data from an executing robot or simulation).

trajectory_1

trajectory_2

trajectory_3

Checklist

  • Required: Code is auto formatted using clang-format
  • Extended the tutorials / documentation, if necessary reference
  • Include a screenshot if changing a GUI
  • Optional: Created tests, which fail without this PR reference
  • Optional: Decide if this should be cherry-picked to other current ROS branches (Indigo, Jade, Kinetic)

Thank you!

@kennethanderson

kennethanderson commented Feb 11, 2017 •

Copy link
Copy Markdown
Contributor Author

@rbbg, if you could please help with testing, I'd be much obliged. I haven't worked with robots/ros/moveit in years.

If you plan to compare against 'optimal' methods such as TOPP, just disable jerk.

@kennethanderson kennethanderson changed the title Kinetic iterative cubic spline Iterative cubic spline Feb 11, 2017
@gavanderhoorn

Copy link
Copy Markdown
Member

I've been following this development and this is impressive. The 'staircases' in the jerk plots are very nice to see.

One comment / question: should compile time switches like (en|dis)abling jerk limits (4b69254) and the default limits (1810abd) all be made configurable / runtime changeable (ultimately through ROS params / dyn reconfig)?

I don't think we can choose a configuration / set of parameters that will suite every usecase or (robotic) setup, so it's probably worth it to make them user configurable.

@davetcoleman davetcoleman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great code, fantastic contribution, small changes requested, thanks!


#define VLIMIT 1.0 // default
#define ALIMIT 3.0 // default
#define JLIMIT 9.0 // default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These compiler flags are generally discouraged, could we use static const double VLIMIT = 1.0; instead?

Increasing the jerk limits will reduce oscilation and speed up execution.
By default, this should be ENABLED.
*/
#define ENABLE_JERK

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd rather see this run-time configurable.

The downside is that if the limits are low, you will notice visible oscilation
around what you may expect as the 'optimal' velocity curve.
Increasing the jerk limits will reduce oscilation and speed up execution.
By default, this should be ENABLED.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Really great comments, thanks!

double final_acceleration;
double max_velocity;
double max_acceleration;
double max_jerk;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Out of curiosity, is it possible to handle different min/max values for these limits? Its never been fully clear to me the use case for having this distinction, but parts of MoveIt! do support it

@kennethanderson kennethanderson Feb 12, 2017 •

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.

Ok, I've added support for it. But if a min value is zero, I assume it is unset and set it to the negative of the max value.

};

IterativeSplineParameterization::IterativeSplineParameterization(double max_time_change_per_it, bool add_points)
: max_time_change_per_it_(1.0 + max_time_change_per_it), add_points_(add_points)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do you add 1.0?

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.

to make it a multiplicative factor. I changed the member variable name to reflect this.


p0 = trajectory.getWayPointPtr(num_points - 2);
p1 = trajectory.getWayPointPtr(num_points - 1);
for (unsigned j = 0; j < num_joints; j++)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same int

}
}

// Initiialize times

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spelling of Initiialize

init_times(num_points, &time_diff[0], &t2[j].positions[0], t2[j].max_velocity);

// Fit initial spline (satisfies initial/final velocity)
int loop = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

bool would be a better datatype for clarity. i double checked performance indications and it seems they are the same

* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Ken Anderson, based off add_iterative_spline_parameterization.cpp by Ioan Sucan */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add_iterative_spline_parameterization should be add_time_parameterization


namespace default_planner_request_adapters
{
class AddSplineParameterization : public planning_request_adapter::PlanningRequestAdapter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The name of this class conflicts with the other version that was recently added by @rbbg to the indigo-devel branch of moveit. A PR exists to cherry-pick it to kinetic-devel, but it has not been merged in.

Since yours is clearly an improvement, I think we should replace his with yours entirely. @rbbg is that ok with you? To make the code history make sense, I think we should still merge #428 then have this PR replace it?

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.

That's absolutely fine with me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On further thought, merging in #428 and #429 in Jade/Kinetic then syncing with this PR is more trouble than its worth because of slightly different file names. I'd rather just revert @rbbg's PR in Indigo since it was only merged in (prematurely by me) 18 days ago and never announced/documented.

@kennethanderson

kennethanderson commented Feb 11, 2017 •

Copy link
Copy Markdown
Contributor Author

@gavanderhoorn Yes, you are correct. I wasn't initially sure if disabling jerk would play nice with the controller problem in #160, but I believe it will. We just lose initial/final acceleration matching.

So to that end, I've added arguments to the constructor for jerk enabling and setting the jerk limit. And I've added a jerk scaling factor similar to the velocity and acceleration scaling factors in computeTimeStamps(). This will allow reducing limit during operation without reconstructing the object.

As for the default limits-- they are really just a fallback if the model doesn't provide them. This is the same behaviour as IPTP, so I'd prefer to leave that out of this pull request.

@kennethanderson

Copy link
Copy Markdown
Contributor Author

@davetcoleman Your requested changes should be complete. Thanks for reviewing.

@rbbg

rbbg commented Feb 13, 2017

Copy link
Copy Markdown
Contributor

This is great! I'll definitely try to test the performance as soon as I can. A decent comparison between this and the other available options will be a little more work, but I'd be happy to merge this as soon as it is confirmed that the controller won't do anything weird with this parameterization (which I really doubt).

Seems like moveit::core::VariableBounds (and moveit_msgs/JointLimits) will also need to be extended in order to fully use and configure jerk limits from the kinematics.yaml :)

#include <vector>

static const double VLIMIT = 1.0; // default if not specified in model
static const double ALIMIT = 3.0; // default if not specified in model

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.

Just wondering: the defaults are currently both set to 1.0, I don't mind changing that but just wanted to point it out, especially since I've seen quite a number of moveit_configs that don't have the acceleration limit set.

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.

Good point. I agree. Done.

@davetcoleman

Copy link
Copy Markdown
Member

Waiting on @rbbg's testing

</description>
</class>

<class name="default_planner_request_adapters/AddIterativeSplineParameterization" type="default_planner_request_adapters::AddIterativeSplineParameterization" base_class_type="planning_request_adapter::PlanningRequestAdapter">

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this should be:

<class name="default_planner_request_adapters/AddSplineParameterization" type="default_planner_request_adapters::AddSplineParameterization" base_class_type="planning_request_adapter::PlanningRequestAdapter">
    <description>
    </description>
  </class>

To match the names in add_iterative_spline_parameterization.cpp

@kennethanderson kennethanderson Feb 17, 2017 •

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.

Good catch. I've changed the cpp class to match instead to avoid colliding with #382 . It also matches the cpp filename.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm in favor or reverting #382 (this PR) so you shouldn't need to worry about colliding with it. Still, I like your more detailed naming of using "iterative"

@v4hn

v4hn commented Aug 16, 2017

Copy link
Copy Markdown
Contributor

@mmoerdijk , @rbbg , @kennethanderson , @BrettHemes

What is your current view on this issue?
Has there been any progress here that is not documented in the issue?

I assume there is no optimal solution to the acceleration spikes available in the near future.
What do you think is the best way to handle this issue for now (also w.r.t. #443)?

@rbbg

rbbg commented Aug 17, 2017

Copy link
Copy Markdown
Contributor

I haven't looked at this in a while. I'd probably hold off on #443 until there is actually something better available. It's not perfect the way it is, but at least it is an improvement from what was there before.

@kennethanderson

kennethanderson commented Aug 17, 2017 •

Copy link
Copy Markdown
Contributor Author

Sorry guys, the only way I have been able to resolve to oscillations problem is to ignore the jerk constraints. Smoothing is a promising option, but I've run out of free time to continue working on this.

So I've removed the jerk constraints from this trajectory fitter. This improves on IPTP in the ways you were expecting (it's velocity&acceleration-constrained at waypoints, it's 1st/2nd derivative are continuous, calculation time and trajectory length are on par with IPTP). I've tested on 3 sets of test trajectories provided by you. But could If I could get some more help testing, I'd be much obliged.

@kennethanderson

Copy link
Copy Markdown
Contributor Author

Ping. This code should be ready for merging.

@kennethanderson

Copy link
Copy Markdown
Contributor Author

@v4hn the code is ready, if you'd like to use it. It should solve the acceleration spikes issue. However, it looks like this PR has fallen off everyone's radar.

@kennethanderson

Copy link
Copy Markdown
Contributor Author

Ping.

@v4hn

v4hn commented Oct 10, 2017

Copy link
Copy Markdown
Contributor

@kennethanderson sorry, this is on my list and I'm interested to see this merged soon.
Sadly I didn't manage to merge before ROSCon...

@davetcoleman

Copy link
Copy Markdown
Member

I would like to merge this PR today. I have just reviewed all the previous comments as well as the previous spline approach graciously contributed by @rbbg that I merged in a month prior to @kennethanderson improved version in this PR. Here's what I think we should do and the rational:

Revert @rbbg's temporary AddSplineParameterization

  • It does the same thing as @kennethanderson's newer AddIterativeSplineParameterization except that "the acceleration limits are still not satisfied completely"
  • Also from the original PR "One problem remains, with the current starting timestamps, the first waypoint often gets dropped by the controller because it occurs in the past, when this happens, the controller will again apply the quintic interpolation and you get the 'wave' as seen in the figure above."
  • Having two plugins do the same thing will just confuse people and require more maintenance

Merge this PR

  • It has unit tests, has been tested with three different example trajectories, and by many users in this thread
  • It obeys the acceleration constraints
  • It is written by the same author who wrote our original time parameterizer that has been used for 5 years in all of moveit
  • It still will not be the default time paramaterization approach in moveit but rather a better alternative that we can upgrade to in ROS-L or ROS-M

Thanks @rbbg for starting this whole spline effort and @kennethanderson for putting in so much testing and research into a far superior approach for moveit!

@v4hn

v4hn commented Oct 18, 2017

Copy link
Copy Markdown
Contributor

@davetcoleman I won't have the time to look over this today. Looking forward to see this improved!

@gavanderhoorn

Copy link
Copy Markdown
Member

@davetcoleman wrote (#441 (comment)):

[..]

I think I can agree with your rationale, and I'm pretty sure @rbbg will agree as well.

@kennethanderson's work is indeed very nice. Not perfect (as he wrote himself), but neither is the current IPTP.

@hartmanndennis

Copy link
Copy Markdown
Contributor

Can this be merged soon?

@v4hn

v4hn commented Jan 26, 2018

Copy link
Copy Markdown
Contributor

I am waiting for @davetcoleman to look at this again and merge it.

@davetcoleman
davetcoleman merged commit f50f9fc into moveit:kinetic-devel Jan 27, 2018
@davetcoleman

Copy link
Copy Markdown
Member

hurray!

@gavanderhoorn

Copy link
Copy Markdown
Member

Should this be considered for backport to Indigo?

The PR doesn't replace anything, so the current behaviour could be maintained.

@v4hn

v4hn commented Jan 30, 2018

Copy link
Copy Markdown
Contributor

Should this be considered for backport to Indigo?

Feel free to file a pull-request. Sounds good to me.

@RhysMcK

RhysMcK commented Apr 20, 2018 •

Copy link
Copy Markdown

I have recently been having issues commanding a 6-DOF Kuka robot using the paths generated by moveit's motion planning pipeline. However, every now and again i will receive a slight jerk which will exceed the acceleration and torque limits of the physical robot. I was hoping that this new spline fitting method might help, however the trajectories outputs i obtained weren't great. This can be seen in below velocities plots.

[blue-Planned= motion planning pipeline output , green-Desired= controller output, red-Actual = IGNORE]

  • Moveit!'s Default time Parametrization
    time_param

  • Spline Parametrization
    spline_param

Please note that i didn't capture the exact same trajectory for the two cases above... but regardless the oscillation in the latter method is constant across all trajectories i tried. Any ideas on why this spline-fitting method is producing particular 'non-ideal' trajectories?

Cheers!

@hartmanndennis

Copy link
Copy Markdown
Contributor

@RhysMcK can you try #809?

@gavanderhoorn

Copy link
Copy Markdown
Member

#809 (or: TOTG) is nice, but iirc, totg is also not jerk limited.

gavanderhoorn pushed a commit to gavanderhoorn/moveit that referenced this pull request Apr 20, 2018
* adding iterative spline time parameterization

* add 2nd and 2nd-last points

* move added points near endpoints, but not exactly the same.  Fix math error.

* add jerk comment

* clang-formatting

* prevent divide-by-zero. Fix out-of-bounds array write

* fix variables

* off by one error.  change default limits

* comments

* fix for setting waypoint durations

* comments

* add time parameterization unit test

* styling

* add compile-time option to disable jerk

* allow jerk to be enabled/disabled at runtime

* make requested changes, the biggest of which is allowing for min and max constraints

* add duration check to unit test

* set default acceleration to 1.0

* fix class name

* add migration notes

* whitespace styling

* set waypoint velocities/accelerations when unset.  Increase default jerk limit.  Modify test case to catch this.

* improved handling of unspecified initial/final velocities/accelerations

* change 0.01 constant to epsilon()

* simplify tests

* styling

* Remove jerk, as it causes oscillations
gavanderhoorn pushed a commit to gavanderhoorn/moveit that referenced this pull request May 27, 2018
* adding iterative spline time parameterization

* add 2nd and 2nd-last points

* move added points near endpoints, but not exactly the same.  Fix math error.

* add jerk comment

* clang-formatting

* prevent divide-by-zero. Fix out-of-bounds array write

* fix variables

* off by one error.  change default limits

* comments

* fix for setting waypoint durations

* comments

* add time parameterization unit test

* styling

* add compile-time option to disable jerk

* allow jerk to be enabled/disabled at runtime

* make requested changes, the biggest of which is allowing for min and max constraints

* add duration check to unit test

* set default acceleration to 1.0

* fix class name

* add migration notes

* whitespace styling

* set waypoint velocities/accelerations when unset.  Increase default jerk limit.  Modify test case to catch this.

* improved handling of unspecified initial/final velocities/accelerations

* change 0.01 constant to epsilon()

* simplify tests

* styling

* Remove jerk, as it causes oscillations
@davetcoleman davetcoleman mentioned this pull request Aug 1, 2018
6 tasks done
@skaruparthi

Copy link
Copy Markdown

Hi I am trying to use Iterative Spline parameterization for trajectory smoothing with Trajectory Optimization (TrajOpt) algorithm. As moveit do not support trajopt, I originally created a seperate robot model for moveit and used trajectory_processing::IterativeParabolicTimeParameterization to compute timestamps. But, now I want to clean my code and bypass moveit. Can someone suggest how I can use TOTP plugin without moveit.

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.