![]() |
PhotonVision C++ v2026.2.2
|
The PhotonPoseEstimator class filters or combines readings from all the fiducials visible at a given timestamp on the field to produce a single robot in field pose, using the strategy set below. More...
#include <photon/PhotonPoseEstimator.h>
Public Member Functions | |
| PhotonPoseEstimator (frc::AprilTagFieldLayout aprilTags, frc::Transform3d robotToCamera) | |
| Create a new PhotonPoseEstimator. | |
| PhotonPoseEstimator (frc::AprilTagFieldLayout aprilTags, PoseStrategy strategy, frc::Transform3d robotToCamera) | |
| Create a new PhotonPoseEstimator. | |
| frc::AprilTagFieldLayout | GetFieldLayout () const |
| Get the AprilTagFieldLayout being used by the PositionEstimator. | |
| PoseStrategy | GetPoseStrategy () const |
| Get the Position Estimation Strategy being used by the Position Estimator. | |
| void | SetPoseStrategy (PoseStrategy strat) |
| Set the Position Estimation Strategy used by the Position Estimator. | |
| void | SetMultiTagFallbackStrategy (PoseStrategy strategy) |
| Set the Position Estimation Strategy used in multi-tag mode when only one tag can be seen. | |
| frc::Pose3d | GetReferencePose () const |
| Return the reference position that is being used by the estimator. | |
| void | SetReferencePose (frc::Pose3d referencePose) |
| Update the stored reference pose for use when using the CLOSEST_TO_REFERENCE_POSE strategy. | |
| frc::Transform3d | GetRobotToCameraTransform () |
| void | SetRobotToCameraTransform (frc::Transform3d robotToCamera) |
| Useful for pan and tilt mechanisms, or cameras on turrets. | |
| void | SetLastPose (frc::Pose3d lastPose) |
| Update the stored last pose. | |
| void | AddHeadingData (units::second_t timestamp, frc::Rotation2d heading) |
| Add robot heading data to the buffer. | |
| void | AddHeadingData (units::second_t timestamp, frc::Rotation3d heading) |
| Add robot heading data to the buffer. | |
| void | ResetHeadingData (units::second_t timestamp, frc::Rotation2d heading) |
| Clears all heading data in the buffer, and adds a new seed. | |
| void | ResetHeadingData (units::second_t timestamp, frc::Rotation3d heading) |
| Clears all heading data in the buffer, and adds a new seed. | |
| std::optional< EstimatedRobotPose > | Update (const photon::PhotonPipelineResult &result, std::optional< photon::PhotonCamera::CameraMatrix > cameraMatrixData=std::nullopt, std::optional< photon::PhotonCamera::DistortionMatrix > coeffsData=std::nullopt, std::optional< ConstrainedSolvepnpParams > constrainedPnpParams=std::nullopt) |
| Update the pose estimator. | |
| std::optional< EstimatedRobotPose > | EstimateLowestAmbiguityPose (PhotonPipelineResult cameraResult) |
| Return the estimated position of the robot with the lowest position ambiguity from a List of pipeline results. | |
| std::optional< EstimatedRobotPose > | EstimateClosestToCameraHeightPose (PhotonPipelineResult cameraResult) |
| Return the estimated position of the robot using the target with the lowest delta height difference between the estimated and actual height of the camera. | |
| std::optional< EstimatedRobotPose > | EstimateClosestToReferencePose (PhotonPipelineResult cameraResult, frc::Pose3d referencePose) |
| Return the estimated position of the robot using the target with the lowest delta in the vector magnitude between it and the reference pose. | |
| std::optional< EstimatedRobotPose > | EstimateCoprocMultiTagPose (PhotonPipelineResult cameraResult) |
| Return the estimated position of the robot by using all visible tags to compute a single pose estimate on coprocessor. | |
| std::optional< EstimatedRobotPose > | EstimateRioMultiTagPose (PhotonPipelineResult cameraResult, PhotonCamera::CameraMatrix camMat, PhotonCamera::DistortionMatrix distCoeffs) |
| Return the estimated position of the robot by using all visible tags to compute a single pose estimate on the RoboRIO. | |
| std::optional< EstimatedRobotPose > | EstimatePnpDistanceTrigSolvePose (PhotonPipelineResult cameraResult) |
| Return the estimated position of the robot by using distance data from best visible tag to compute a Pose. | |
| std::optional< EstimatedRobotPose > | EstimateAverageBestTargetsPose (PhotonPipelineResult cameraResult) |
| Return the average of the best target poses using ambiguity as weight. | |
| std::optional< EstimatedRobotPose > | EstimateConstrainedSolvepnpPose (photon::PhotonPipelineResult cameraResult, photon::PhotonCamera::CameraMatrix cameraMatrix, photon::PhotonCamera::DistortionMatrix distCoeffs, frc::Pose3d seedPose, bool headingFree, double headingScaleFactor) |
| Return the estimated position of the robot by solving a constrained version of the Perspective-n-Point problem with the robot's drivebase flat on the floor. | |
The PhotonPoseEstimator class filters or combines readings from all the fiducials visible at a given timestamp on the field to produce a single robot in field pose, using the strategy set below.
Example usage can be found in our apriltagExample example project.
|
explicit |
Create a new PhotonPoseEstimator.
| aprilTags | A AprilTagFieldLayout linking AprilTag IDs to Pose3ds with respect to the FIRST field. |
| robotToCamera | Transform3d from the center of the robot to the camera mount positions (ie, robot ➔ camera). |
|
explicit |
Create a new PhotonPoseEstimator.
| aprilTags | A AprilTagFieldLayout linking AprilTag IDs to Pose3ds with respect to the FIRST field. |
| strategy | The strategy it should use to determine the best pose. |
| robotToCamera | Transform3d from the center of the robot to the camera mount positions (ie, robot ➔ camera). |
|
inline |
Add robot heading data to the buffer.
Must be called periodically for the PNP_DISTANCE_TRIG_SOLVE strategy.
| timestamp | Timestamp of the robot heading data. |
| heading | Field-relative heading at the given timestamp. Standard WPILIB field coordinates. |
|
inline |
Add robot heading data to the buffer.
Must be called periodically for the PNP_DISTANCE_TRIG_SOLVE strategy.
| timestamp | Timestamp of the robot heading data. |
| heading | Field-relative heading at the given timestamp. Standard WPILIB coordinates. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateAverageBestTargetsPose | ( | PhotonPipelineResult | cameraResult | ) |
Return the average of the best target poses using ambiguity as weight.
| cameraResult | A pipeline result from the camera. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateClosestToCameraHeightPose | ( | PhotonPipelineResult | cameraResult | ) |
Return the estimated position of the robot using the target with the lowest delta height difference between the estimated and actual height of the camera.
| cameraResult | A pipeline result from the camera. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateClosestToReferencePose | ( | PhotonPipelineResult | cameraResult, |
| frc::Pose3d | referencePose ) |
Return the estimated position of the robot using the target with the lowest delta in the vector magnitude between it and the reference pose.
| cameraResult | A pipeline result from the camera. |
| referencePose | reference pose to check vector magnitude difference against. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateConstrainedSolvepnpPose | ( | photon::PhotonPipelineResult | cameraResult, |
| photon::PhotonCamera::CameraMatrix | cameraMatrix, | ||
| photon::PhotonCamera::DistortionMatrix | distCoeffs, | ||
| frc::Pose3d | seedPose, | ||
| bool | headingFree, | ||
| double | headingScaleFactor ) |
Return the estimated position of the robot by solving a constrained version of the Perspective-n-Point problem with the robot's drivebase flat on the floor.
This computation takes place on the RoboRIO, and typically takes not more than 2ms. See photon::VisionEstimation::EstimateRobotPoseConstrainedSolvePNP for tuning handles this strategy exposes. Internally, the cost function is a sum-squared of pixel reprojection error + (optionally) heading error * heading scale factor. This strategy needs addHeadingData called every frame so heading data is up-to-date.
| cameraResult | A pipeline result from the camera. |
| cameraMatrix | Camera intrinsics from camera calibration data. |
| distCoeffs | Distortion coefficients from camera calibration data. |
| seedPose | An initial guess at robot pose, refined via optimization. Better guesses will converge faster. Can come from any pose source, but some battle-tested sources are estimateCoprocMultiTagPose, or estimateLowestAmbiguityPose if MultiTag results aren't available. |
| headingFree | If true, heading is completely free to vary. If false, heading excursions from the provided heading measurement will be penalized |
| headingScaleFactor | If headingFree is false, this weights the cost of changing our robot heading estimate against the tag corner reprojection error cost. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateCoprocMultiTagPose | ( | PhotonPipelineResult | cameraResult | ) |
Return the estimated position of the robot by using all visible tags to compute a single pose estimate on coprocessor.
This option needs to be enabled on the PhotonVision web UI as well.
| cameraResult | A pipeline result from the camera. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateLowestAmbiguityPose | ( | PhotonPipelineResult | cameraResult | ) |
Return the estimated position of the robot with the lowest position ambiguity from a List of pipeline results.
| cameraResult | A pipeline result from the camera. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimatePnpDistanceTrigSolvePose | ( | PhotonPipelineResult | cameraResult | ) |
Return the estimated position of the robot by using distance data from best visible tag to compute a Pose.
This runs on the RoboRIO in order to access the robot's yaw heading, and MUST have AddHeadingData called every frame so heading data is up-to-date.
Yields a Pose2d in estimatedRobotPose (0 for z, roll, pitch)
https://www.chiefdelphi.com/t/frc-6328-mechanical-advantage-2025-build-thread/477314/98
| cameraResult | A pipeline result from the camera. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::EstimateRioMultiTagPose | ( | PhotonPipelineResult | cameraResult, |
| PhotonCamera::CameraMatrix | camMat, | ||
| PhotonCamera::DistortionMatrix | distCoeffs ) |
Return the estimated position of the robot by using all visible tags to compute a single pose estimate on the RoboRIO.
This can take a lot of time due to the RIO's weak computing power.
| cameraResult | A pipeline result from the camera. |
| cameraMatrix | Camera intrinsics from camera calibration data. |
| distCoeffs | Distortion coefficients from camera calibration data. |
|
inline |
Get the AprilTagFieldLayout being used by the PositionEstimator.
|
inline |
Get the Position Estimation Strategy being used by the Position Estimator.
|
inline |
Return the reference position that is being used by the estimator.
|
inline |
|
inline |
Clears all heading data in the buffer, and adds a new seed.
Useful for preventing estimates from utilizing heading data provided prior to a pose or rotation reset.
| timestamp | Timestamp of the robot heading data. |
| heading | Field-relative robot heading at given timestamp. Standard WPILIB field coordinates. |
|
inline |
Clears all heading data in the buffer, and adds a new seed.
Useful for preventing estimates from utilizing heading data provided prior to a pose or rotation reset.
| timestamp | Timestamp of the robot heading data. |
| heading | Field-relative robot heading at given timestamp. Standard WPILIB field coordinates. |
|
inline |
Update the stored last pose.
Useful for setting the initial estimate when using the CLOSEST_TO_LAST_POSE strategy.
| lastPose | the lastPose to set |
| void photon::PhotonPoseEstimator::SetMultiTagFallbackStrategy | ( | PoseStrategy | strategy | ) |
Set the Position Estimation Strategy used in multi-tag mode when only one tag can be seen.
Must NOT be MULTI_TAG_PNP
| strategy | the strategy to set |
|
inline |
Set the Position Estimation Strategy used by the Position Estimator.
| strategy | the strategy to set |
|
inline |
Update the stored reference pose for use when using the CLOSEST_TO_REFERENCE_POSE strategy.
| referencePose | the referencePose to set |
|
inline |
Useful for pan and tilt mechanisms, or cameras on turrets.
| robotToCamera | The current transform from the center of the robot to the camera mount position. |
| std::optional< EstimatedRobotPose > photon::PhotonPoseEstimator::Update | ( | const photon::PhotonPipelineResult & | result, |
| std::optional< photon::PhotonCamera::CameraMatrix > | cameraMatrixData = std::nullopt, | ||
| std::optional< photon::PhotonCamera::DistortionMatrix > | coeffsData = std::nullopt, | ||
| std::optional< ConstrainedSolvepnpParams > | constrainedPnpParams = std::nullopt ) |
Update the pose estimator.
If updating multiple times per loop, you should call this exactly once per new result, in order of increasing result timestamp.
| result | The vision targeting result to process |
| cameraIntrinsics | The camera calibration pinhole coefficients matrix. Only required if doing multitag-on-rio, and may be nullopt otherwise. |
| distCoeffsData | The camera calibration distortion coefficients. Only required if doing multitag-on-rio, and may be nullopt otherwise. |
| constrainedPnpParams | Constrained SolvePNP params, if needed. |