tesseract icon indicating copy to clipboard operation
tesseract copied to clipboard

Add spline interpolator to tesseract_common

Open mpowelson opened this issue 5 years ago • 15 comments

This function uses Eigen to interpolate each column of a TrajArray using a cubic spline.

mpowelson avatar Jan 08 '20 18:01 mpowelson

@mpowelson you should also add a few checks in the class itself to validate that your spline actually approximates the data correctly. I ran into some issues recently using this library where my input points generated bad splines (mostly due to duplicate or almost duplicate input points)

  1. Check that the knots are equal to the input points within some small threshold
  Eigen::Matrix3Xd pts; // input points
  Eigen::Spline3d::KnotVectorType chord_lengths;
  Eigen::ChordLengths(pts, chord_lengths);
  for (Eigen::Index i = 0; i < pts.cols(); ++i)
  {
    const Eigen::Vector3d& pt = spline(chord_lengths(i));
    const Eigen::Vector3d& ref = pts.col(i);
    if (!ref.isApprox(pt))
    {
      return false;
    }
  }
  1. Check that the piecewise, linearly interpolated "length" of the input points is equal (within some percentage tolerance) to the length of an arbitrary (large) number of points sampled evenly on the spline from [0:1]. In my case where I accidentally had duplicate input points, the length of my spline was about 2x as long as the piecewise interpolated length of my input points, which caused some serious problems. This is the function I used to estimate the length
double estimateSplineLength(const Eigen::Matrix3Xd& points)
{
  double length = 0;
  for (Eigen::Index i = 0; i < points.cols() - 1; ++i)
  {
    const Eigen::VectorXd& first = points.col(i);
    const Eigen::VectorXd& second = points.col(i + 1);
    length += (second - first).norm();
  }
  return length;
}

marip8 avatar Jan 08 '20 21:01 marip8

Is this designed to retime trajectories for vel/accel/jerk limits?

johnwason avatar Jan 17 '20 19:01 johnwason

Is there any movement on this? We need trapezoidal trajectory profiles for use with robots that have direct position control.

johnwason avatar Feb 06 '20 20:02 johnwason

You could take a look at hungpham2511/toppra.

It's only acceleration-limited, but generates pretty smooth trajectories.

@johnwason: what brand of robots are you using? Afaik most robots that have "direct position control" also come with adequate filtering.

gavanderhoorn avatar Feb 06 '20 20:02 gavanderhoorn

Thanks @gavanderhoorn, that link is really useful!

Most robots we are working with will dynamic overload of the command impulse is too large (ABB EGM), or will overshoot (Sawyer). The control provided is very low level.

johnwason avatar Feb 06 '20 20:02 johnwason

Are you using EGM for those ABBs? Because there are quite some knobs to tune with EGM. IIRC, gains on position setpoints and low-pass filter cutoffs.

gavanderhoorn avatar Feb 06 '20 20:02 gavanderhoorn

@gavanderhoorn yes, we have been working with the ABB EGM for quite a while. The issue is that if we lower the gains sufficiently to avoid dynamic overload, the performance becomes unusable. The ABB EGM and other similar inputs expect the input profile to pre-filtered for dynamics.

johnwason avatar Feb 06 '20 20:02 johnwason

I'm aware of the context in which non-smooth trajectories can become problematic. I just wanted to make sure we're not overcomplicating things.

gavanderhoorn avatar Feb 07 '20 09:02 gavanderhoorn

@mpowelson What do you think we should do with this PR?

Levi-Armstrong avatar Feb 26 '21 14:02 Levi-Armstrong

@mpowelson What do you think we should do with this PR?

I guess close it. I opened this when I was playing around with the idea of adding spline paths to trajopt (rather than assuming joint interpolated like we do now). I don't see me working on that any time soon.

That said, this code should still work if someone needed it - with the caveats explained in the comments about some features being broken in the system version of Eigen.

mpowelson avatar Feb 26 '21 15:02 mpowelson

@Levi-Armstrong I rebased it for completeness. I still won't be upset if we close this.

mpowelson avatar Feb 26 '21 16:02 mpowelson

I think this can be closed.

rjoomen avatar Jul 21 '23 18:07 rjoomen

I have been leaving this open, because I would like to get this merged but not sure if the feature are fixed in the Eigen version on 20.04.

Levi-Armstrong avatar Jul 21 '23 20:07 Levi-Armstrong

I checked, only from Eigen 3.4.0 @mpowelson's PR has been included. Ubuntu 20.04 still is on 3.3.7, unfortunately. You could add a check to either the CMakeLists.txt or the code to either not include this code or throw an error when Eigen version < 3.4.0. Then this PR could be merged. Because I don't think the official Ubuntu 20.04 repos will ever get Eigen 3.4.

rjoomen avatar Jul 22 '23 08:07 rjoomen