Class FieldTargetSelector

java.lang.Object
frc.robot.shared.field.FieldTargetSelector

public class FieldTargetSelector extends Object
Selects the active field target for the turret based on the robot's position and alliance color.

When the robot is in its alliance zone, the turret aims at the Alliance Hub. When the robot is in the neutral zone (collecting fuel), the turret aims at whichever alliance-zone rally point is closer based on the robot's Y position. All positions are configured from the Blue alliance perspective and mirrored at runtime for Red.

  • Constructor Details

    • FieldTargetSelector

      public FieldTargetSelector(FieldTargetConfig config, Supplier<edu.wpi.first.math.geometry.Pose2d> robotPoseSupplier, Supplier<Optional<edu.wpi.first.wpilibj.DriverStation.Alliance>> allianceSupplier)
      Creates a field target selector that evaluates position and alliance each time a target is requested.
      Parameters:
      config - field target positions and zone boundaries loaded from JSON
      robotPoseSupplier - supplier for the robot's current estimated pose in meters and radians
      allianceSupplier - supplier for the current alliance color
  • Method Details

    • getActiveTargetPosition

      public edu.wpi.first.math.geometry.Translation2d getActiveTargetPosition()
      Computes the active field target position based on the robot's current zone and alliance.

      Call this each cycle to get the turret's tracking target. The returned position accounts for alliance-based coordinate mirroring so callers always receive field-relative meters.

      Returns:
      field-relative target position in meters
    • getActiveTargetName

      public String getActiveTargetName()
      Returns a human-readable name for the active field target based on the robot's current zone and alliance.

      Use this for operator telemetry so drivers can see whether the turret is aiming at the hub or a rally point.

      Returns:
      display name of the active target: "Hub", "Left Rally", or "Right Rally"