Class Curve

java.lang.Object
frc.spectrumLib.util.Curve
Direct Known Subclasses:
ExpCurve

public abstract class Curve extends Object
This class and its subclasses remap controller stick inputs according to specifics provided of multiple classes of curves.

This is the superclass of several types of curves. It contains most of the code that is used for all types of curves (Linear, Exponential, Spline, and Step).

To create a Curve, do not create a Curve object directly, use a subclass of Curve such as ExpCurve instead.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract double
    calculate(double input)
    Calculates and returns a mapped value based on the curve.
    protected double
    calculateDeadzone(double input)
    Returns the value of input mapped to create a deadband of width deadzone in the center of the curve and squishes the rest of the curve to the outside proportionally.
    protected double
    calculateOffset(double input)
    Returns the value of input summed with the value of offset.
    protected double
    calculateScalar(double input)
    Returns the value of input multiplied by the value of scalar.
    double[][]
    getCurvePoints(int pointCount)
    Returns a set of points of length pointCount on the curve.
    double
    Returns the value of deadzone, the value for the width in the center of the curve where any input results in an output of 0.0
    double
    Returns the value of offset, the double value added to the final curve.
    double
    Returns the value of scalar, the double value multiplied to the curve before it is offset.
    void
    printPoints(double[][] points)
    Prints the values of a 2D double array of points.
    void
    printPoints(int pointCount)
    Prints a set of points on the curve of length pointCount.
    void
    setDeadzone(double deadzone)
    Sets the value of deadzone, the value for the width in the center of the curve where any input results in an output of 0.0.
    void
    setOffset(double offset)
    Sets the value of offset, the value added to the final curve.
    void
    setScalar(double scalar)
    Sets the value of scalar, the value multiplied to the curve before it is offset.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Curve

      public Curve()
  • Method Details

    • calculate

      public abstract double calculate(double input)
      Calculates and returns a mapped value based on the curve.
      Parameters:
      input - value to be mapped
      Returns:
      mapped value
    • calculateDeadzone

      protected double calculateDeadzone(double input)
      Returns the value of input mapped to create a deadband of width deadzone in the center of the curve and squishes the rest of the curve to the outside proportionally.
      Parameters:
      input - the input value to be mapped
      Returns:
      mapped value
    • calculateScalar

      protected double calculateScalar(double input)
      Returns the value of input multiplied by the value of scalar.
      Parameters:
      input - the input value to be mapped
      Returns:
      mapped value
    • calculateOffset

      protected double calculateOffset(double input)
      Returns the value of input summed with the value of offset.
      Parameters:
      input - the input value to be mapped
      Returns:
      mapped value
    • getCurvePoints

      public double[][] getCurvePoints(int pointCount)
      Returns a set of points of length pointCount on the curve.
      Parameters:
      pointCount - the amount of points on the curve
      Returns:
      a 2D double array of points on the curve
    • printPoints

      public void printPoints(double[][] points)
      Prints the values of a 2D double array of points. The output of this method can be pasted into https://www.desmos.com/calculator to see a visual representation of the Curve .
      Parameters:
      points - the set of points to be printed
    • printPoints

      public void printPoints(int pointCount)
      Prints a set of points on the curve of length pointCount. The output of this method can be pasted into https://www.desmos.com/calculator to see a visual representation of the Curve.
      Parameters:
      pointCount - the set of points to be printed
    • setOffset

      public void setOffset(double offset)
      Sets the value of offset, the value added to the final curve.
      Parameters:
      offset - the new value of offset
    • setScalar

      public void setScalar(double scalar)
      Sets the value of scalar, the value multiplied to the curve before it is offset.
      Parameters:
      scalar - the new value of scalar
    • setDeadzone

      public void setDeadzone(double deadzone)
      Sets the value of deadzone, the value for the width in the center of the curve where any input results in an output of 0.0.
      Parameters:
      deadzone - the new value of deadzone
    • getOffset

      public double getOffset()
      Returns the value of offset, the double value added to the final curve.
      Returns:
      the current value of offset
    • getScalar

      public double getScalar()
      Returns the value of scalar, the double value multiplied to the curve before it is offset.
      Returns:
      the current value of scalar
    • getDeadzone

      public double getDeadzone()
      Returns the value of deadzone, the value for the width in the center of the curve where any input results in an output of 0.0
      Returns:
      the current value of deadzone