Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit 577b050

Browse files
committed
refactor: april tag layout declared in sim io instead of constants
1 parent 79b12f5 commit 577b050

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/main/java/org/team1540/robot2024/Constants.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package org.team1540.robot2024;
22

3-
import edu.wpi.first.apriltag.AprilTagFieldLayout;
4-
import edu.wpi.first.apriltag.AprilTagFields;
53
import edu.wpi.first.math.geometry.Pose3d;
64
import edu.wpi.first.math.geometry.Rotation2d;
75
import edu.wpi.first.math.geometry.Rotation3d;
86
import edu.wpi.first.math.util.Units;
97

10-
import java.io.IOException;
11-
128
/**
139
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
1410
* constants. This class should not be used for any other purpose. All constants should be declared
@@ -84,14 +80,6 @@ public static class Vision {
8480
public static final double MAX_ACCEPTED_AVG_TAG_DIST_METERS = 8.0;
8581
public static final double MAX_ACCEPTED_ELEVATOR_SPEED_MPS = 0.05;
8682

87-
public static final AprilTagFieldLayout SIM_APRILTAG_LAYOUT;
88-
static {
89-
try {
90-
SIM_APRILTAG_LAYOUT = AprilTagFieldLayout.loadFromResource(AprilTagFields.k2024Crescendo.m_resourceFile);
91-
} catch (IOException e) {
92-
throw new RuntimeException(e);
93-
}
94-
}
9583
public static final int SIM_RES_WIDTH = 1280;
9684
public static final int SIM_RES_HEIGHT = 960;
9785
public static final Rotation2d SIM_DIAGONAL_FOV = Rotation2d.fromDegrees(100);

src/main/java/org/team1540/robot2024/subsystems/vision/AprilTagVisionIOSim.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.team1540.robot2024.subsystems.vision;
22

3+
import edu.wpi.first.apriltag.AprilTagFieldLayout;
4+
import edu.wpi.first.apriltag.AprilTagFields;
35
import edu.wpi.first.math.geometry.Pose2d;
46
import edu.wpi.first.math.geometry.Pose3d;
57
import edu.wpi.first.math.geometry.Transform3d;
@@ -11,6 +13,7 @@
1113
import org.photonvision.simulation.VisionSystemSim;
1214
import org.photonvision.targeting.PhotonTrackedTarget;
1315

16+
import java.io.IOException;
1417
import java.util.List;
1518
import java.util.Optional;
1619
import java.util.function.Supplier;
@@ -31,7 +34,14 @@ public class AprilTagVisionIOSim implements AprilTagVisionIO {
3134
public AprilTagVisionIOSim(String name, Pose3d cameraOffsetMeters, Supplier<Pose2d> poseSupplier) {
3235
this.visionSystemSim = new VisionSystemSim(name);
3336
this.poseSupplier = poseSupplier;
34-
visionSystemSim.addAprilTags(SIM_APRILTAG_LAYOUT);
37+
38+
AprilTagFieldLayout aprilTagLayout;
39+
try {
40+
aprilTagLayout = AprilTagFieldLayout.loadFromResource(AprilTagFields.k2024Crescendo.m_resourceFile);
41+
} catch (IOException e) {
42+
throw new RuntimeException(e);
43+
}
44+
visionSystemSim.addAprilTags(aprilTagLayout);
3545

3646
SimCameraProperties cameraProps = new SimCameraProperties();
3747
cameraProps.setCalibration(SIM_RES_WIDTH, SIM_RES_HEIGHT, SIM_DIAGONAL_FOV);
@@ -44,7 +54,7 @@ public AprilTagVisionIOSim(String name, Pose3d cameraOffsetMeters, Supplier<Pose
4454
visionSystemSim.addCamera(cameraSim, cameraTransform);
4555

4656
photonEstimator = new PhotonPoseEstimator(
47-
SIM_APRILTAG_LAYOUT,
57+
aprilTagLayout,
4858
PhotonPoseEstimator.PoseStrategy.MULTI_TAG_PNP_ON_COPROCESSOR,
4959
camera,
5060
cameraTransform);

0 commit comments

Comments
 (0)