From 3bd243f68979501c2fe92f4bfc3e5205a9d36d94 Mon Sep 17 00:00:00 2001 From: Ray Healy Date: Tue, 10 Feb 2026 16:00:39 -0500 Subject: [PATCH] src/robolib/trajectory/ballistics/constraints: Define base class for constraints --- .../constraints/BallisticConstraint.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/ballistics/constraints/BallisticConstraint.java diff --git a/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/ballistics/constraints/BallisticConstraint.java b/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/ballistics/constraints/BallisticConstraint.java new file mode 100644 index 0000000..c473446 --- /dev/null +++ b/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/ballistics/constraints/BallisticConstraint.java @@ -0,0 +1,55 @@ +package org.fairportrobotics.frc.robolib.trajectory.ballistics.constraints; + +import org.fairportrobotics.frc.robolib.trajectory.Velocity3d; +import org.fairportrobotics.frc.robolib.trajectory.ballistics.models.BallisticModel; + +public abstract class BallisticConstraint { + protected double weight; + + /** + * Generate the constraint with weight 0.0 + */ + public BallisticConstraint() { + this(0.0); + } + + /** + * Generate the constraint with a given weight value + * @param weight The weight of this constraint's penalty + */ + public BallisticConstraint(double weight) { + this.weight = weight; + } + + /** + * Set the weight of this constraint + * @param weight The weight of the constraint + * @return this + */ + public BallisticConstraint setWeight(double weight) { + this.weight = weight; + return this; + } + + /** + * @return The weight of this constraint + */ + public double getWeight() { + return this.weight; + } + + + /** + * Evaluate a given solution's fitness against this constraint + * + * TODO: Expand this with additional parameters + * + * @param The type of BallisticModel + * @param

The parameter type of M + * @param model The model used to compute candidate + * @param candidate The candidate velocity computed by model + * @return A penalty value (from 0 to 1.0) for this match (null if candidate + * is invalid). Used with weight to determine candidate fitness + */ + public abstract , P> Double evaluate(M model, Velocity3d candidate); +}