Class Spline

java.lang.Object
me.wobblyyyy.pathfinder.trajectory.Spline
All Implemented Interfaces:
Segment
Direct Known Subclasses:
Arc, Linear

public class Spline
extends java.lang.Object
implements Segment
Ahh... splines. Basically gay lines. I swear I'm not homophobic, I like men too. Anyways. Straight lines are very linear and very boring. Splines, on the other hand, are basically straight lines that aren't at all straight - rather, they curve. Splines are incredibly useful in making complex movement trajectories and profiles. Unlike regular lines, splines, as you know, have an element of curvature. This element of curvature allows for your robot to continually move without ever having to come to a stop or a hard direction change. Splines themselves are representations of a concept, not fully fledged implementations of a trajectory following algorithm.

Splines, or at least these splines, make use of the Fritsch-Carlson method for computing internal spline parameters. This method isn't incredibly computationally expensive, but as a best practice, it's suggested that you do as little runtime execution of spline initialization.

Interpolation is handled by yet another rather complex algorithm that nobody quite understands - including me, probably. Anyways, if you really are quite sincerely interested in learning how spline interpolation works, you can go check out the SplineInterpolator class - that has all the cool and sexy math you might want to look at.

Since:
0.3.0
Author:
Colin Robertson
  • Field Summary

    Fields
    Modifier and Type Field Description
    private me.wobblyyyy.edt.DynamicArray<Angle> angles
    An array of all of the angles contained on the spline's path.
    private SplineInterpolator interpolator
    The internal spline interpolator.
    private boolean isInverted
    Is the spline's internal interpolator inverted?
    private me.wobblyyyy.edt.StaticArray<HeadingPoint> points
    A set of each of the points that the spline should hit.
    private double xMaximum
    The maximum X value of the spline.
    private double xMinimum
    The minimum X value of the spline.
    private double yMaximum
    The maximum Y value of the spline.
    private double yMinimum
    The minimum Y value of the spline.
  • Constructor Summary

    Constructors
    Constructor Description
    Spline​(me.wobblyyyy.edt.Arrayable<HeadingPoint> points)
    Create a new Spline that will hit each of the required points.
  • Method Summary

    Modifier and Type Method Description
    Angle angleAt​(Point point)
    Get the angle which the robot should be facing at the given trajectory.
    Point end()
    Get the point where the segment ends.
    private java.util.ArrayList<java.lang.Double> fromDynamicArray​(me.wobblyyyy.edt.DynamicArray<java.lang.Double> array)
    Convert an DynamicArray into an ArrayList.
    Point interpolateFromX​(double xValue)
    Get a point from the segment based on an X value.
    Point interpolateFromY​(double yValue)
    Get a point from the segment based on an Y value.
    Point maximum()
    Get a combination of the maximum X and Y values for the segment.
    Point minimum()
    Get a combination of the minimum X and Y values for the segment.
    private static boolean onlyIncreasing​(java.util.ArrayList<java.lang.Double> values)
    Check to see if an ArrayList only has a sequence of increasing values - used for spline inversion.
    Point start()
    Get the point where the segment starts.
    java.lang.String toString()
    Convert the spline to a string representation of the spline.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • interpolator

      private final SplineInterpolator interpolator
      The internal spline interpolator. All of the hard math behind splines is handled in a separate class as to reduce code clutter and make the Spline class a bit more readable, especially for those without much experience in building splines.
    • points

      private final me.wobblyyyy.edt.StaticArray<HeadingPoint> points
      A set of each of the points that the spline should hit. This is used mostly for metadata about the spline.
    • angles

      private final me.wobblyyyy.edt.DynamicArray<Angle> angles
      An array of all of the angles contained on the spline's path. TODO implement angles
    • xMinimum

      private double xMinimum
      The minimum X value of the spline.
    • yMinimum

      private double yMinimum
      The minimum Y value of the spline.
    • xMaximum

      private double xMaximum
      The maximum X value of the spline.
    • yMaximum

      private double yMaximum
      The maximum Y value of the spline.
    • isInverted

      private final boolean isInverted
      Is the spline's internal interpolator inverted?
  • Constructor Details

    • Spline

      public Spline​(me.wobblyyyy.edt.Arrayable<HeadingPoint> points)
      Create a new Spline that will hit each of the required points. Splines are created so that they hit each and every one of the target points, meaning that if you tell the robot to pass through (10, 10), the robot will pass through (10, 10) no matter what.
      Parameters:
      points - a container that contains each of the required points. Each and every one of these points will be passed through directly by the spline computational system, meaning that the robot will go exactly where you tell it to go.
  • Method Details

    • onlyIncreasing

      private static boolean onlyIncreasing​(java.util.ArrayList<java.lang.Double> values)
      Check to see if an ArrayList only has a sequence of increasing values - used for spline inversion.
      Parameters:
      values - the values to check.
      Returns:
      whether or not the values exclusively sequentially increase.
    • fromDynamicArray

      private java.util.ArrayList<java.lang.Double> fromDynamicArray​(me.wobblyyyy.edt.DynamicArray<java.lang.Double> array)
      Convert an DynamicArray into an ArrayList.
      Parameters:
      array - the DynamicArray to convert.
      Returns:
      the ArrayList that's been created.
    • interpolateFromX

      public Point interpolateFromX​(double xValue)
      Get a point from the segment based on an X value. This point should fit within the bounds of the segment and should be represented partially by the provided value, which provides a basis for interpolation from there.
      Specified by:
      interpolateFromX in interface Segment
      Parameters:
      xValue - the value that the segment should interpolate from. This means, in essence, that the segment should determine the nearest possible point to the requested X value.
      Returns:
      an interpolated point based on an inputted value. This point has no regard for heading - rather, it's a simple and plain point that can be used for following the trajectory or just figuring out where a certain value on the trajectory lies.
    • interpolateFromY

      public Point interpolateFromY​(double yValue)
      Get a point from the segment based on an Y value. This point should fit within the bounds of the segment and should be represented partially by the provided value, which provides a basis for interpolation from there.
      Specified by:
      interpolateFromY in interface Segment
      Parameters:
      yValue - the value that the segment should interpolate from. This means, in essence, that the segment should determine the nearest possible point to the requested Y value.
      Returns:
      an interpolated point based on an inputted value. This point has no regard for heading - rather, it's a simple and plain point that can be used for following the trajectory or just figuring out where a certain value on the trajectory lies.
    • angleAt

      public Angle angleAt​(Point point)
      Get the angle which the robot should be facing at the given trajectory. This angle is handled separately from the interpolation methods to increase the degree of flexibility the Segment interface will provide both internally and externally.
      Specified by:
      angleAt in interface Segment
      Parameters:
      point - the point that will serve as a basis for fetching the desired robot heading.
      Returns:
      the most closely interpolated heading/angle at a given point. This angle typically corresponds to how far along the segment the robot has travelled, but it's up to the implementations of the segment class to decide how exactly this is handled. Yay interfaces!
    • minimum

      public Point minimum()
      Get a combination of the minimum X and Y values for the segment. This point is used to reduce primitive clutter - instead of returning an individual X and Y double, we can return a single point that represents our requested information.
      Specified by:
      minimum in interface Segment
      Returns:
      a combination of the requested X and Y values. This is used mostly in segment interpolation, as individual segments are predicated on raw X and Y coordinates, not interpolatable coordinates.
    • maximum

      public Point maximum()
      Get a combination of the maximum X and Y values for the segment. This point is used to reduce primitive clutter - instead of returning an individual X and Y double, we can return a single point that represents our requested information.
      Specified by:
      maximum in interface Segment
      Returns:
      a combination of the requested X and Y values. This is used mostly in segment interpolation, as individual segments are predicated on raw X and Y coordinates, not interpolatable coordinates.
    • toString

      public java.lang.String toString()
      Convert the spline to a string representation of the spline.
      Overrides:
      toString in class java.lang.Object
      Returns:
      the interpolator's representation of the spline in the very readable String form.
    • start

      public Point start()
      Get the point where the segment starts. This is defined as the position that represents 0 percent of the segment's completion.
      Specified by:
      start in interface Segment
      Returns:
      the point at which the segment begins.
    • end

      public Point end()
      Get the point where the segment ends. This is defined as the position that represents 100 percent of the segment's completion.
      Specified by:
      end in interface Segment
      Returns:
      the point at which the segment ends.