diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java index e4d1efb99..165bd304f 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java @@ -19,6 +19,7 @@ package org.photonvision.vision.pipeline; import edu.wpi.first.apriltag.AprilTagDetection; import edu.wpi.first.apriltag.AprilTagDetector; +import edu.wpi.first.apriltag.AprilTagPoseEstimate; import edu.wpi.first.apriltag.AprilTagPoseEstimator.Config; import edu.wpi.first.math.geometry.Transform3d; import edu.wpi.first.math.util.Units; @@ -146,17 +147,19 @@ public class AprilTagPipeline extends CVPipeline settings.hammingDist) continue; - // Do pose estimation for all the tags that make it thru - // TODO - var poseResult = poseEstimatorPipe.run(detection); - sumPipeNanosElapsed += poseResult.nanosElapsed; + AprilTagPoseEstimate tagPoseEstimate = null; + if (settings.solvePNPEnabled) { + var poseResult = poseEstimatorPipe.run(detection); + sumPipeNanosElapsed += poseResult.nanosElapsed; + tagPoseEstimate = poseResult.output; + } // populate the target list // Challenge here is that TrackedTarget functions with OpenCV Contour TrackedTarget target = new TrackedTarget( detection, - poseResult.output, + tagPoseEstimate, new TargetCalculationParameters( false, null, null, null, null, frameStaticProperties)); diff --git a/photon-core/src/main/java/org/photonvision/vision/target/TrackedTarget.java b/photon-core/src/main/java/org/photonvision/vision/target/TrackedTarget.java index 1ffe37538..01309b897 100644 --- a/photon-core/src/main/java/org/photonvision/vision/target/TrackedTarget.java +++ b/photon-core/src/main/java/org/photonvision/vision/target/TrackedTarget.java @@ -80,20 +80,25 @@ public class TrackedTarget implements Releasable { tagDetection.getCenterX(), params.cameraCenterPoint.x, params.horizontalFocalLength); var bestPose = new Transform3d(); var altPose = new Transform3d(); - if (tagPose.error1 <= tagPose.error2) { - bestPose = tagPose.pose1; - altPose = tagPose.pose2; - } else { - bestPose = tagPose.pose2; - altPose = tagPose.pose1; + + if (tagPose != null) { + if (tagPose.error1 <= tagPose.error2) { + bestPose = tagPose.pose1; + altPose = tagPose.pose2; + } else { + bestPose = tagPose.pose2; + altPose = tagPose.pose1; + } + + bestPose = MathUtils.convertApriltagtoOpenCV(bestPose); + altPose = MathUtils.convertApriltagtoOpenCV(altPose); + + m_bestCameraToTarget3d = bestPose; + m_altCameraToTarget3d = altPose; + + m_poseAmbiguity = tagPose.getAmbiguity(); } - bestPose = MathUtils.convertApriltagtoOpenCV(bestPose); - altPose = MathUtils.convertApriltagtoOpenCV(altPose); - - m_bestCameraToTarget3d = bestPose; - m_altCameraToTarget3d = altPose; - double[] corners = tagDetection.getCorners(); Point[] cornerPoints = new Point[] { @@ -128,8 +133,6 @@ public class TrackedTarget implements Releasable { var rvec = new Mat(3, 1, CvType.CV_64FC1); MathUtils.rotationToOpencvRvec(bestPose.getRotation(), rvec); setCameraRelativeRvec(rvec); - - m_poseAmbiguity = tagPose.getAmbiguity(); } public void setFiducialId(int id) {