From f8439a98429478d7f419d950de682fa7e3eb5932 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Mon, 28 Aug 2023 12:27:10 -0400 Subject: [PATCH] Improve docs for PhotonPoseEstimator In particular, document that update() ensures that new data is only used once. --- .../org/photonvision/PhotonPoseEstimator.java | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/photon-lib/src/main/java/org/photonvision/PhotonPoseEstimator.java b/photon-lib/src/main/java/org/photonvision/PhotonPoseEstimator.java index 8bbdaf5744..1b07947d0d 100644 --- a/photon-lib/src/main/java/org/photonvision/PhotonPoseEstimator.java +++ b/photon-lib/src/main/java/org/photonvision/PhotonPoseEstimator.java @@ -250,10 +250,16 @@ public void setRobotToCameraTransform(Transform3d robotToCamera) { /** * Poll data from the configured cameras and update the estimated position of the robot. Returns - * empty if there are no cameras set or no targets were found from the cameras. + * empty if: * - * @return an EstimatedRobotPose with an estimated pose, the timestamp, and targets used to create - * the estimate + * + * + * @return an {@link EstimatedRobotPose} with an estimated pose, timestamp, and targets used to + * create the estimate. */ public Optional update() { if (camera == null) { @@ -267,12 +273,17 @@ public Optional update() { } /** - * Updates the estimated position of the robot. Returns empty if there are no cameras set or no - * targets were found from the cameras. + * Updates the estimated position of the robot. Returns empty if: + * + *
    + *
  • The timestamp of the provided pipeline result is the same as in the previous call to + * {@code update()}. + *
  • No targets were found in the pipeline results. + *
* * @param cameraResult The latest pipeline result from the camera - * @return an EstimatedRobotPose with an estimated pose, and information about the camera(s) and - * pipeline results used to create the estimate + * @return an {@link EstimatedRobotPose} with an estimated pose, timestamp, and targets used to + * create the estimate. */ public Optional update(PhotonPipelineResult cameraResult) { if (camera == null) return update(cameraResult, Optional.empty(), Optional.empty()); @@ -280,21 +291,24 @@ public Optional update(PhotonPipelineResult cameraResult) { } /** - * Updates the estimated position of the robot. Returns empty if there are no cameras set or no - * targets were found from the cameras. + * Updates the estimated position of the robot. Returns empty if: + * + *
    + *
  • The timestamp of the provided pipeline result is the same as in the previous call to + * {@code update()}. + *
  • No targets were found in the pipeline results. + *
* * @param cameraResult The latest pipeline result from the camera - * @param cameraMatrixData Camera calibration data that can be used in the case of no assigned - * PhotonCamera. - * @param coeffsData Camera calibration data that can be used in the case of no assigned - * PhotonCamera - * @return an EstimatedRobotPose with an estimated pose, and information about the camera(s) and - * pipeline results used to create the estimate + * @param cameraMatrix The camera matrix. + * @param distCoeffs The distortion coefficient matrix. + * @return an {@link EstimatedRobotPose} with an estimated pose, timestamp, and targets used to + * create the estimate. */ public Optional update( PhotonPipelineResult cameraResult, - Optional> cameraMatrixData, - Optional> coeffsData) { + Optional> cameraMatrix, + Optional> distCoeffs) { // Time in the past -- give up, since the following if expects times > 0 if (cameraResult.getTimestampSeconds() < 0) { return Optional.empty(); @@ -316,13 +330,13 @@ public Optional update( return Optional.empty(); } - return update(cameraResult, cameraMatrixData, coeffsData, this.primaryStrategy); + return update(cameraResult, cameraMatrix, distCoeffs, this.primaryStrategy); } private Optional update( PhotonPipelineResult cameraResult, - Optional> cameraMatrixData, - Optional> coeffsData, + Optional> cameraMatrix, + Optional> distCoeffs, PoseStrategy strat) { Optional estimatedPose; switch (strat) { @@ -343,7 +357,7 @@ private Optional update( estimatedPose = averageBestTargetsStrategy(cameraResult); break; case MULTI_TAG_PNP: - estimatedPose = multiTagPNPStrategy(cameraResult, cameraMatrixData, coeffsData); + estimatedPose = multiTagPNPStrategy(cameraResult, cameraMatrix, distCoeffs); break; default: DriverStation.reportError(