Skip to content

Commit

Permalink
refactor: april tag layout declared in sim io instead of constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 committed Feb 2, 2024
1 parent 79b12f5 commit 577b050
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/main/java/org/team1540/robot2024/Constants.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.team1540.robot2024;

import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.apriltag.AprilTagFields;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.util.Units;

import java.io.IOException;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
* constants. This class should not be used for any other purpose. All constants should be declared
Expand Down Expand Up @@ -84,14 +80,6 @@ public static class Vision {
public static final double MAX_ACCEPTED_AVG_TAG_DIST_METERS = 8.0;
public static final double MAX_ACCEPTED_ELEVATOR_SPEED_MPS = 0.05;

public static final AprilTagFieldLayout SIM_APRILTAG_LAYOUT;
static {
try {
SIM_APRILTAG_LAYOUT = AprilTagFieldLayout.loadFromResource(AprilTagFields.k2024Crescendo.m_resourceFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static final int SIM_RES_WIDTH = 1280;
public static final int SIM_RES_HEIGHT = 960;
public static final Rotation2d SIM_DIAGONAL_FOV = Rotation2d.fromDegrees(100);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.team1540.robot2024.subsystems.vision;

import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.apriltag.AprilTagFields;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Transform3d;
Expand All @@ -11,6 +13,7 @@
import org.photonvision.simulation.VisionSystemSim;
import org.photonvision.targeting.PhotonTrackedTarget;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
Expand All @@ -31,7 +34,14 @@ public class AprilTagVisionIOSim implements AprilTagVisionIO {
public AprilTagVisionIOSim(String name, Pose3d cameraOffsetMeters, Supplier<Pose2d> poseSupplier) {
this.visionSystemSim = new VisionSystemSim(name);
this.poseSupplier = poseSupplier;
visionSystemSim.addAprilTags(SIM_APRILTAG_LAYOUT);

AprilTagFieldLayout aprilTagLayout;
try {
aprilTagLayout = AprilTagFieldLayout.loadFromResource(AprilTagFields.k2024Crescendo.m_resourceFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
visionSystemSim.addAprilTags(aprilTagLayout);

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

photonEstimator = new PhotonPoseEstimator(
SIM_APRILTAG_LAYOUT,
aprilTagLayout,
PhotonPoseEstimator.PoseStrategy.MULTI_TAG_PNP_ON_COPROCESSOR,
camera,
cameraTransform);
Expand Down

0 comments on commit 577b050

Please sign in to comment.