-
Notifications
You must be signed in to change notification settings - Fork 3
nearest trench tag stuff #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package frc.robot.util; | ||
|
|
||
| import edu.wpi.first.apriltag.AprilTagFieldLayout; | ||
| import edu.wpi.first.math.geometry.Pose2d; | ||
| import edu.wpi.first.math.geometry.Rectangle2d; | ||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import edu.wpi.first.math.geometry.Translation2d; | ||
| import edu.wpi.first.wpilibj.DriverStation; | ||
| import java.util.Objects; | ||
|
|
||
| public final class TrenchUtil { | ||
| private static final double FIELD_LENGTH = AllianceUtils.FIELD_LAYOUT.getFieldLength(); | ||
| private static final double FIELD_WIDTH = AllianceUtils.FIELD_LAYOUT.getFieldWidth(); | ||
| private static final Rectangle2d FIELD_BOUNDS = | ||
| new Rectangle2d(new Translation2d(0.0, 0.0), new Translation2d(FIELD_LENGTH, FIELD_WIDTH)); | ||
|
|
||
| private static final Pose2d BLUE_LOW_Y_TRENCH = midpointBetweenTags(17, 28); | ||
| private static final Pose2d BLUE_HIGH_Y_TRENCH = midpointBetweenTags(22, 23); | ||
| private static final Pose2d RED_LOW_Y_TRENCH = midpointBetweenTags(6, 7); | ||
| private static final Pose2d RED_HIGH_Y_TRENCH = midpointBetweenTags(1, 12); | ||
|
|
||
| private TrenchUtil() {} | ||
|
|
||
| private static Pose2d midpointBetweenTags(int tagA, int tagB) { | ||
| AprilTagFieldLayout fieldLayout = AllianceUtils.FIELD_LAYOUT; | ||
| Translation2d tagATranslation = | ||
| fieldLayout | ||
| .getTagPose(tagA) | ||
| .orElseThrow(() -> new IllegalStateException("AprilTag " + tagA + " is not present")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using References
|
||
| .getTranslation() | ||
| .toTranslation2d(); | ||
| Translation2d tagBTranslation = | ||
| fieldLayout | ||
| .getTagPose(tagB) | ||
| .orElseThrow(() -> new IllegalStateException("AprilTag " + tagB + " is not present")) | ||
| .getTranslation() | ||
| .toTranslation2d(); | ||
|
|
||
| return new Pose2d(tagATranslation.interpolate(tagBTranslation, 0.5), Rotation2d.kZero); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the midpoint of the trench AprilTag pair in the same WPILib blue-origin field | ||
| * coordinate frame used by AprilTagFieldLayout. X spans the field length from blue to red, and Y | ||
| * spans the field width from the blue alliance's right to left. | ||
| */ | ||
| public static Pose2d nearestTrenchTag(Translation2d translation) { | ||
| Objects.requireNonNull(translation, "translation"); | ||
|
|
||
| if (!FIELD_BOUNDS.contains(translation)) { | ||
| DriverStation.reportWarning( | ||
| "Translation is outside the WPILib field bounds: " + translation, false); | ||
| return Pose2d.kZero; | ||
| } | ||
|
|
||
| boolean redSide = translation.getX() >= FIELD_LENGTH / 2.0; | ||
| boolean highY = translation.getY() >= FIELD_WIDTH / 2.0; | ||
|
Comment on lines
+50
to
+57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning boolean redSide = translation.getX() >= FIELD_LENGTH / 2.0;
boolean highY = translation.getY() >= FIELD_WIDTH / 2.0; |
||
|
|
||
| if (redSide) { | ||
| return highY ? RED_HIGH_Y_TRENCH : RED_LOW_Y_TRENCH; | ||
| } | ||
|
|
||
| return highY ? BLUE_HIGH_Y_TRENCH : BLUE_LOW_Y_TRENCH; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
isUnderClimbmethod incorrectly usesTrenchUtil.nearestTrenchTag, which is designed to return the location of trench tags. This method should instead determine the nearest tag from theunderclimbTagslist (tags 15 and 31). Using trench tag midpoints here will result in incorrect proximity detection for the climb structure, potentially failing to protect the hood when the robot is actually under it.