001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math.trajectory.constraint;
006
007import edu.wpi.first.math.geometry.Pose2d;
008
009/**
010 * An interface for defining user-defined velocity and acceleration constraints while generating
011 * trajectories.
012 */
013public interface TrajectoryConstraint {
014  /**
015   * Returns the max velocity given the current pose and curvature.
016   *
017   * @param poseMeters The pose at the current point in the trajectory.
018   * @param curvatureRadPerMeter The curvature at the current point in the trajectory.
019   * @param velocityMetersPerSecond The velocity at the current point in the trajectory before
020   *     constraints are applied.
021   * @return The absolute maximum velocity.
022   */
023  double getMaxVelocityMetersPerSecond(
024      Pose2d poseMeters, double curvatureRadPerMeter, double velocityMetersPerSecond);
025
026  /**
027   * Returns the minimum and maximum allowable acceleration for the trajectory given pose,
028   * curvature, and speed.
029   *
030   * @param poseMeters The pose at the current point in the trajectory.
031   * @param curvatureRadPerMeter The curvature at the current point in the trajectory.
032   * @param velocityMetersPerSecond The speed at the current point in the trajectory.
033   * @return The min and max acceleration bounds.
034   */
035  MinMax getMinMaxAccelerationMetersPerSecondSq(
036      Pose2d poseMeters, double curvatureRadPerMeter, double velocityMetersPerSecond);
037
038  /** Represents a minimum and maximum acceleration. */
039  class MinMax {
040    public double minAccelerationMetersPerSecondSq = -Double.MAX_VALUE;
041    public double maxAccelerationMetersPerSecondSq = Double.MAX_VALUE;
042
043    /**
044     * Constructs a MinMax.
045     *
046     * @param minAccelerationMetersPerSecondSq The minimum acceleration.
047     * @param maxAccelerationMetersPerSecondSq The maximum acceleration.
048     */
049    public MinMax(
050        double minAccelerationMetersPerSecondSq, double maxAccelerationMetersPerSecondSq) {
051      this.minAccelerationMetersPerSecondSq = minAccelerationMetersPerSecondSq;
052      this.maxAccelerationMetersPerSecondSq = maxAccelerationMetersPerSecondSq;
053    }
054
055    /** Constructs a MinMax with default values. */
056    public MinMax() {}
057  }
058}