Package frc.spectrumLib.util
Class Curve
java.lang.Object
frc.spectrumLib.util.Curve
- Direct Known Subclasses:
ExpCurve
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 -
Method Summary
Modifier and TypeMethodDescriptionabstract double
calculate
(double input) Calculates and returns a mapped value based on the curve.protected double
calculateDeadzone
(double input) Returns the value ofinput
mapped to create a deadband of widthdeadzone
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 ofinput
summed with the value ofoffset
.protected double
calculateScalar
(double input) Returns the value ofinput
multiplied by the value ofscalar
.double[][]
getCurvePoints
(int pointCount) Returns a set of points of lengthpointCount
on the curve.double
Returns the value ofdeadzone
, the value for the width in the center of the curve where any input results in an output of0.0
double
Returns the value ofoffset
, the double value added to the final curve.double
Returns the value ofscalar
, 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 lengthpointCount
.void
setDeadzone
(double deadzone) Sets the value ofdeadzone
, the value for the width in the center of the curve where any input results in an output of0.0
.void
setOffset
(double offset) Sets the value ofoffset
, the value added to the final curve.void
setScalar
(double scalar) Sets the value ofscalar
, the value multiplied to the curve before it is offset.
-
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 ofinput
mapped to create a deadband of widthdeadzone
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 ofinput
multiplied by the value ofscalar
.- Parameters:
input
- the input value to be mapped- Returns:
- mapped value
-
calculateOffset
protected double calculateOffset(double input) Returns the value ofinput
summed with the value ofoffset
.- Parameters:
input
- the input value to be mapped- Returns:
- mapped value
-
getCurvePoints
public double[][] getCurvePoints(int pointCount) Returns a set of points of lengthpointCount
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 theCurve
.- Parameters:
points
- the set of points to be printed
-
printPoints
public void printPoints(int pointCount) Prints a set of points on the curve of lengthpointCount
. The output of this method can be pasted into https://www.desmos.com/calculator to see a visual representation of theCurve
.- Parameters:
pointCount
- the set of points to be printed
-
setOffset
public void setOffset(double offset) Sets the value ofoffset
, the value added to the final curve.- Parameters:
offset
- the new value ofoffset
-
setScalar
public void setScalar(double scalar) Sets the value ofscalar
, the value multiplied to the curve before it is offset.- Parameters:
scalar
- the new value ofscalar
-
setDeadzone
public void setDeadzone(double deadzone) Sets the value ofdeadzone
, the value for the width in the center of the curve where any input results in an output of0.0
.- Parameters:
deadzone
- the new value ofdeadzone
-
getOffset
public double getOffset()Returns the value ofoffset
, the double value added to the final curve.- Returns:
- the current value of
offset
-
getScalar
public double getScalar()Returns the value ofscalar
, the double value multiplied to the curve before it is offset.- Returns:
- the current value of
scalar
-
getDeadzone
public double getDeadzone()Returns the value ofdeadzone
, the value for the width in the center of the curve where any input results in an output of0.0
- Returns:
- the current value of
deadzone
-