Skip to content

Incorrect pose estimation vision correction java example #1634

@PGgit08

Description

@PGgit08

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);
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationAnything relating to https://docs.photonvision.org

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions