Class Aiming

java.lang.Object
frc.robot.util.Aiming

public class Aiming extends Object
Utility class for calculating aiming solutions for the shooter.
  • Field Details

    • NO_TARGET

      public static final Aiming.AimingResult NO_TARGET
      A default empty result to prevent NullPointerExceptions
  • Method Details

    • computeHubAiming

      public static Aiming.AimingResult computeHubAiming(Translation2d robotCenter, Rotation2d currentRobotRotation, Translation2d fieldVelocity, Translation2d targetPosition, Translation2d shooterRobotOffset, Time estimatedTimeOfFlight, boolean log)
      Computes all aiming outputs for a direct hub shot with lead compensation.

      This method uses a two-pass approach: Pass 1 estimates the shooter's position at the current robot heading to find a rough target angle. Pass 2 re-calculates the shooter's position at that estimated heading to provide a final, precise aiming solution.

      Parameters:
      robotCenter - The current center position of the robot.
      currentRobotRotation - The current rotation of the robot.
      fieldVelocity - The robot's field-relative velocity (m/s).
      targetPosition - The blue-alliance target position.
      shooterRobotOffset - The physical offset of the shooter from the robot's center.
      estimatedTimeOfFlight - Estimated time for the projectile to travel to the target.
      log - Whether to publish outputs to AdvantageKit for visualization.
      Returns:
      The computed aiming result.
    • computeLobAiming

      public static Aiming.AimingResult computeLobAiming(Translation2d robotCenter, Rotation2d currentRobotRotation, Translation2d shooterRobotOffset, Translation2d lobTargetLeftCenter, Translation2d lobTargetRightCenter, Distance lobTargetHalfLength, boolean log)
      Computes aiming for lobbed shots targeted at specific field line segments.

      The robot will automatically select the closest of the two provided lob targets and calculate the closest point on that line segment to the shooter.

      Parameters:
      robotCenter - The current center position of the robot.
      currentRobotRotation - The current rotation of the robot.
      shooterRobotOffset - The physical offset of the shooter from the robot's center.
      lobTargetLeftCenter - Blue alliance left lobbing target center.
      lobTargetRightCenter - Blue alliance right lobbing target center.
      lobTargetHalfLength - Half length of the lobbing target line segment.
      log - Whether to publish outputs to AdvantageKit for visualization.
      Returns:
      The computed aiming result.
    • hubAimingSupplier

      public static Supplier<Aiming.AimingResult> hubAimingSupplier(Supplier<Pose2d> robotPoseSupplier, Supplier<Translation2d> fieldVelocitySupplier, Translation2d shooterRobotOffset, Time estimatedTimeOfFlight)
      Creates a supplier for central hub aiming results. Caches results based on 20ms timestamps to prevent redundant calculation within a single control loop.
      Parameters:
      robotPoseSupplier - A supplier for the robot's current Pose2d.
      fieldVelocitySupplier - A supplier for the robot's field-relative velocity.
      shooterRobotOffset - The physical offset of the shooter from the robot's center.
      estimatedTimeOfFlight - The estimated time for the projectile to reach the target.
      Returns:
      A supplier that provides the calculated Aiming.AimingResult for the hub.
    • lobAimingSupplier

      public static Supplier<Aiming.AimingResult> lobAimingSupplier(Supplier<Pose2d> robotPoseSupplier, Translation2d shooterRobotOffset)
      Creates a supplier for lobbing aiming results. Caches results based on 20ms timestamps.
      Parameters:
      robotPoseSupplier - A supplier for the robot's current Pose2d.
      shooterRobotOffset - The physical offset of the shooter from the robot's center.
      Returns:
      A supplier that provides the calculated Aiming.AimingResult for lobbing.