|
| 1 | +package frc.robot; |
| 2 | + |
| 3 | +import edu.wpi.first.math.geometry.*; |
| 4 | +import edu.wpi.first.math.util.Units; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.List; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +/** |
| 11 | + * Contains various field dimensions and useful reference points. All units are in meters and poses |
| 12 | + * have a blue alliance origin. |
| 13 | + */ |
| 14 | +public class FieldConstants { |
| 15 | + public static final double fieldLength = Units.inchesToMeters(690.876); |
| 16 | + public static final double fieldWidth = Units.inchesToMeters(317); |
| 17 | + public static final double startingLineX = |
| 18 | + Units.inchesToMeters(299.438); // Measured from the inside of starting line |
| 19 | + |
| 20 | + public static class Processor { |
| 21 | + public static final Pose2d centerFace = |
| 22 | + new Pose2d(Units.inchesToMeters(235.726), 0, Rotation2d.fromDegrees(90)); |
| 23 | + } |
| 24 | + |
| 25 | + public static class Barge { |
| 26 | + public static final Translation2d farCage = |
| 27 | + new Translation2d(Units.inchesToMeters(345.428), Units.inchesToMeters(286.779)); |
| 28 | + public static final Translation2d middleCage = |
| 29 | + new Translation2d(Units.inchesToMeters(345.428), Units.inchesToMeters(242.855)); |
| 30 | + public static final Translation2d closeCage = |
| 31 | + new Translation2d(Units.inchesToMeters(345.428), Units.inchesToMeters(199.947)); |
| 32 | + |
| 33 | + // Measured from floor to bottom of cage |
| 34 | + public static final double deepHeight = Units.inchesToMeters(3.125); |
| 35 | + public static final double shallowHeight = Units.inchesToMeters(30.125); |
| 36 | + } |
| 37 | + |
| 38 | + public static class CoralStation { |
| 39 | + public static final Pose2d leftCenterFace = |
| 40 | + new Pose2d( |
| 41 | + Units.inchesToMeters(33.526), |
| 42 | + Units.inchesToMeters(291.176), |
| 43 | + Rotation2d.fromDegrees(90 - 144.011)); |
| 44 | + public static final Pose2d rightCenterFace = |
| 45 | + new Pose2d( |
| 46 | + Units.inchesToMeters(33.526), |
| 47 | + Units.inchesToMeters(25.824), |
| 48 | + Rotation2d.fromDegrees(144.011 - 90)); |
| 49 | + } |
| 50 | + |
| 51 | + public static class Reef { |
| 52 | + public static final Translation2d center = |
| 53 | + new Translation2d(Units.inchesToMeters(176.746), Units.inchesToMeters(158.501)); |
| 54 | + public static final double faceToZoneLine = |
| 55 | + Units.inchesToMeters(12); // Side of the reef to the inside of the reef zone line |
| 56 | + |
| 57 | + public static final Pose2d[] centerFaces = |
| 58 | + new Pose2d[6]; // Starting facing the driver station in clockwise order |
| 59 | + public static final List<Map<ReefHeight, Pose3d>> branchPositions = |
| 60 | + new ArrayList<>(); // Starting at the right branch facing the driver station in clockwise |
| 61 | + |
| 62 | + static { |
| 63 | + // Initialize faces |
| 64 | + centerFaces[0] = |
| 65 | + new Pose2d( |
| 66 | + Units.inchesToMeters(144.003), |
| 67 | + Units.inchesToMeters(158.500), |
| 68 | + Rotation2d.fromDegrees(180)); |
| 69 | + centerFaces[1] = |
| 70 | + new Pose2d( |
| 71 | + Units.inchesToMeters(160.373), |
| 72 | + Units.inchesToMeters(186.857), |
| 73 | + Rotation2d.fromDegrees(120)); |
| 74 | + centerFaces[2] = |
| 75 | + new Pose2d( |
| 76 | + Units.inchesToMeters(193.116), |
| 77 | + Units.inchesToMeters(186.858), |
| 78 | + Rotation2d.fromDegrees(60)); |
| 79 | + centerFaces[3] = |
| 80 | + new Pose2d( |
| 81 | + Units.inchesToMeters(209.489), |
| 82 | + Units.inchesToMeters(158.502), |
| 83 | + Rotation2d.fromDegrees(0)); |
| 84 | + centerFaces[4] = |
| 85 | + new Pose2d( |
| 86 | + Units.inchesToMeters(193.118), |
| 87 | + Units.inchesToMeters(130.145), |
| 88 | + Rotation2d.fromDegrees(-60)); |
| 89 | + centerFaces[5] = |
| 90 | + new Pose2d( |
| 91 | + Units.inchesToMeters(160.375), |
| 92 | + Units.inchesToMeters(130.144), |
| 93 | + Rotation2d.fromDegrees(-120)); |
| 94 | + |
| 95 | + // Initialize branch positions |
| 96 | + for (int face = 0; face < 6; face++) { |
| 97 | + Map<ReefHeight, Pose3d> fillRight = new HashMap<>(); |
| 98 | + Map<ReefHeight, Pose3d> fillLeft = new HashMap<>(); |
| 99 | + for (var level : ReefHeight.values()) { |
| 100 | + Pose2d poseDirection = new Pose2d(center, Rotation2d.fromDegrees(180 - (60 * face))); |
| 101 | + double adjustX = Units.inchesToMeters(30.738); |
| 102 | + double adjustY = Units.inchesToMeters(6.469); |
| 103 | + |
| 104 | + fillRight.put( |
| 105 | + level, |
| 106 | + new Pose3d( |
| 107 | + new Translation3d( |
| 108 | + poseDirection |
| 109 | + .transformBy(new Transform2d(adjustX, adjustY, new Rotation2d())) |
| 110 | + .getX(), |
| 111 | + poseDirection |
| 112 | + .transformBy(new Transform2d(adjustX, adjustY, new Rotation2d())) |
| 113 | + .getY(), |
| 114 | + level.height), |
| 115 | + new Rotation3d( |
| 116 | + 0, |
| 117 | + Units.degreesToRadians(level.pitch), |
| 118 | + poseDirection.getRotation().getRadians()))); |
| 119 | + fillLeft.put( |
| 120 | + level, |
| 121 | + new Pose3d( |
| 122 | + new Translation3d( |
| 123 | + poseDirection |
| 124 | + .transformBy(new Transform2d(adjustX, -adjustY, new Rotation2d())) |
| 125 | + .getX(), |
| 126 | + poseDirection |
| 127 | + .transformBy(new Transform2d(adjustX, -adjustY, new Rotation2d())) |
| 128 | + .getY(), |
| 129 | + level.height), |
| 130 | + new Rotation3d( |
| 131 | + 0, |
| 132 | + Units.degreesToRadians(level.pitch), |
| 133 | + poseDirection.getRotation().getRadians()))); |
| 134 | + } |
| 135 | + branchPositions.add((face * 2) + 1, fillRight); |
| 136 | + branchPositions.add((face * 2) + 2, fillLeft); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + public static class StagingPositions { |
| 142 | + // Measured from the center of the ice cream |
| 143 | + public static final Pose2d leftIceCream = |
| 144 | + new Pose2d(Units.inchesToMeters(48), Units.inchesToMeters(230.5), new Rotation2d()); |
| 145 | + public static final Pose2d middleIceCream = |
| 146 | + new Pose2d(Units.inchesToMeters(48), Units.inchesToMeters(158.5), new Rotation2d()); |
| 147 | + public static final Pose2d rightIceCream = |
| 148 | + new Pose2d(Units.inchesToMeters(48), Units.inchesToMeters(86.5), new Rotation2d()); |
| 149 | + } |
| 150 | + |
| 151 | + public enum ReefHeight { |
| 152 | + L4(Units.inchesToMeters(72), -90), |
| 153 | + L3(Units.inchesToMeters(47.625), -35), |
| 154 | + L2(Units.inchesToMeters(31.875), -35), |
| 155 | + L1(Units.inchesToMeters(18), 0); |
| 156 | + |
| 157 | + ReefHeight(double height, double pitch) { |
| 158 | + this.height = height; |
| 159 | + this.pitch = pitch; // in degrees |
| 160 | + } |
| 161 | + |
| 162 | + public final double height; |
| 163 | + public final double pitch; |
| 164 | + } |
| 165 | + |
| 166 | + // TODO |
| 167 | + // public static final double aprilTagWidth = Units.inchesToMeters(6.50); |
| 168 | + // public static final AprilTagLayoutType defaultAprilTagType = AprilTagLayoutType.OFFICIAL; |
| 169 | + // public static final int aprilTagCount = 22; |
| 170 | + // |
| 171 | + // @Getter |
| 172 | + // public enum AprilTagLayoutType { |
| 173 | + // OFFICIAL("2025-official"); |
| 174 | + // |
| 175 | + // AprilTagLayoutType(String name) { |
| 176 | + // if (Constants.disableHAL) { |
| 177 | + // layout = null; |
| 178 | + // } else { |
| 179 | + // try { |
| 180 | + // layout = |
| 181 | + // new AprilTagFieldLayout( |
| 182 | + // Path.of(Filesystem.getDeployDirectory().getPath(), "apriltags", name + |
| 183 | + // ".json")); |
| 184 | + // } catch (IOException e) { |
| 185 | + // throw new RuntimeException(e); |
| 186 | + // } |
| 187 | + // } |
| 188 | + // if (layout == null) { |
| 189 | + // layoutString = ""; |
| 190 | + // } else { |
| 191 | + // try { |
| 192 | + // layoutString = new ObjectMapper().writeValueAsString(layout); |
| 193 | + // } catch (JsonProcessingException e) { |
| 194 | + // throw new RuntimeException( |
| 195 | + // "Failed to serialize AprilTag layout JSON " + toString() + "for Northstar"); |
| 196 | + // } |
| 197 | + // } |
| 198 | + // } |
| 199 | + // |
| 200 | + // private final AprilTagFieldLayout layout; |
| 201 | + // private final String layoutString; |
| 202 | + // } |
| 203 | +} |
0 commit comments