Skip to content
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

Incorrect pose estimation vision correction java example #1634

Open
PGgit08 opened this issue Dec 15, 2024 · 4 comments
Open

Incorrect pose estimation vision correction java example #1634

PGgit08 opened this issue Dec 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@PGgit08
Copy link

PGgit08 commented Dec 15, 2024

In the PhotonLib pose estimation java example, old vision measurements are being ignored and only the most recent measurement from getAllUnreadResults() is being added to the WPILib pose estimator:

  • getEstimatedGlobalPose() method (the issue is in this method):

    /**
    * The latest estimated robot pose on the field from vision data. This may be empty. This should
    * only be called once per loop.
    *
    * <p>Also includes updates for the standard deviations, which can (optionally) be retrieved with
    * {@link getEstimationStdDevs}
    *
    * @return An {@link EstimatedRobotPose} with an estimated pose, estimate timestamp, and targets
    * used for estimation.
    */
    public Optional<EstimatedRobotPose> getEstimatedGlobalPose() {
    Optional<EstimatedRobotPose> visionEst = Optional.empty();
    for (var change : camera.getAllUnreadResults()) {
    visionEst = photonEstimator.update(change);
    updateEstimationStdDevs(visionEst, change.getTargets());
    if (Robot.isSimulation()) {
    visionEst.ifPresentOrElse(
    est ->
    getSimDebugField()
    .getObject("VisionEstimation")
    .setPose(est.estimatedPose.toPose2d()),
    () -> {
    getSimDebugField().getObject("VisionEstimation").setPoses();
    });
    }
    }
    return visionEst;
    }

  • SwerveDrivePoseEstimator vision update call using the getEstimatedGlobalPose() method:

    // Correct pose estimate with vision measurements
    var visionEst = vision.getEstimatedGlobalPose();
    visionEst.ifPresent(
    est -> {
    // Change our trust in the measurement based on the tags we can see
    var estStdDevs = vision.getEstimationStdDevs();
    drivetrain.addVisionMeasurement(
    est.estimatedPose.toPose2d(), est.timestampSeconds, estStdDevs);
    });

@PGgit08
Copy link
Author

PGgit08 commented Dec 15, 2024

i forgot to add the bug label

@mcm001
Copy link
Contributor

mcm001 commented Dec 15, 2024

Yeah agreed that that example looks like an anti pattern. Good catch!

@gerth2
Copy link
Contributor

gerth2 commented Dec 21, 2024

Yee. The example design predates getAllUnreadResults(), was just never updated.

@gerth2
Copy link
Contributor

gerth2 commented Dec 21, 2024

Fyi some overlap with #1632

@spacey-sooty spacey-sooty added the bug Something isn't working label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants