::type);
- auto const camMat = camera.GetCameraMatrix();
- auto const distCoeffs = camera.GetDistCoeffs();
if (!camMat || !distCoeffs) {
return std::nullopt;
}
diff --git a/photon-lib/src/main/native/include/photonlib/PhotonPoseEstimator.h b/photon-lib/src/main/native/include/photonlib/PhotonPoseEstimator.h
index 5d76a851e..4ed212083 100644
--- a/photon-lib/src/main/native/include/photonlib/PhotonPoseEstimator.h
+++ b/photon-lib/src/main/native/include/photonlib/PhotonPoseEstimator.h
@@ -90,6 +90,23 @@ class PhotonPoseEstimator {
PoseStrategy strategy, PhotonCamera&& camera,
frc::Transform3d robotToCamera);
+ /**
+ * Create a new PhotonPoseEstimator.
+ *
+ * Example: {@code Map map = new HashMap<>();
+ * map.put(1, new Pose3d(1.0, 2.0, 3.0, new Rotation3d())); // Tag ID 1 is
+ * at (1.0,2.0,3.0)
}
+ *
+ * @param aprilTags A AprilTagFieldLayout linking AprilTag IDs to Pose3ds with
+ * respect to the FIRST field.
+ * @param strategy The strategy it should use to determine the best pose.
+ * @param robotToCamera Transform3d from the center of the robot to the camera
+ * mount positions (ie, robot ➔ camera).
+ */
+ explicit PhotonPoseEstimator(frc::AprilTagFieldLayout aprilTags,
+ PoseStrategy strategy,
+ frc::Transform3d robotToCamera);
+
/**
* Get the AprilTagFieldLayout being used by the PositionEstimator.
*
@@ -181,14 +198,22 @@ class PhotonPoseEstimator {
*/
std::optional Update(const PhotonPipelineResult& result);
- inline PhotonCamera& GetCamera() { return camera; }
+ /**
+ * Update the pose estimator.
+ */
+ std::optional Update(
+ const PhotonPipelineResult& result,
+ std::optional cameraMatrixData,
+ std::optional coeffsData);
+
+ inline std::shared_ptr GetCamera() { return camera; }
private:
frc::AprilTagFieldLayout aprilTags;
PoseStrategy strategy;
PoseStrategy multiTagFallbackStrategy = LOWEST_AMBIGUITY;
- PhotonCamera camera;
+ std::shared_ptr camera;
frc::Transform3d m_robotToCamera;
frc::Pose3d lastPose;
@@ -198,8 +223,9 @@ class PhotonPoseEstimator {
inline void InvalidatePoseCache() { poseCacheTimestamp = -1_s; }
- std::optional Update(PhotonPipelineResult result,
- PoseStrategy strategy);
+ std::optional Update(
+ PhotonPipelineResult result, std::optional cameraMatrixData,
+ std::optional coeffsData, PoseStrategy strategy);
/**
* Return the estimated position of the robot with the lowest position
@@ -242,7 +268,8 @@ class PhotonPoseEstimator {
timestamp of this estimation.
*/
std::optional MultiTagPnpStrategy(
- PhotonPipelineResult result);
+ PhotonPipelineResult result, std::optional camMat,
+ std::optional distCoeffs);
/**
* Return the average of the best target poses using ambiguity as weight.
diff --git a/photon-lib/src/test/native/cpp/PhotonPoseEstimatorTest.cpp b/photon-lib/src/test/native/cpp/PhotonPoseEstimatorTest.cpp
index 7c67f02d1..42a6abf7d 100644
--- a/photon-lib/src/test/native/cpp/PhotonPoseEstimatorTest.cpp
+++ b/photon-lib/src/test/native/cpp/PhotonPoseEstimatorTest.cpp
@@ -257,8 +257,8 @@ TEST(PhotonPoseEstimatorTest, ClosestToLastPose) {
frc::Rotation3d(0_rad, 0_rad, 0_rad)),
0.4, corners, detectedCorners}};
- estimator.GetCamera().testResult = {2_ms, targetsThree};
- estimator.GetCamera().testResult.SetTimestamp(units::second_t(21));
+ estimator.GetCamera()->testResult = {2_ms, targetsThree};
+ estimator.GetCamera()->testResult.SetTimestamp(units::second_t(21));
estimatedPose = estimator.Update();
ASSERT_TRUE(estimatedPose);
@@ -345,14 +345,14 @@ TEST(PhotonPoseEstimatorTest, PoseCache) {
aprilTags, photonlib::AVERAGE_BEST_TARGETS, std::move(cameraOne), {});
// empty input, expect empty out
- estimator.GetCamera().testResult = {2_ms, {}};
- estimator.GetCamera().testResult.SetTimestamp(units::second_t(1));
+ estimator.GetCamera()->testResult = {2_ms, {}};
+ estimator.GetCamera()->testResult.SetTimestamp(units::second_t(1));
auto estimatedPose = estimator.Update();
EXPECT_FALSE(estimatedPose);
// Set result, and update -- expect present and timestamp to be 15
- estimator.GetCamera().testResult = {3_ms, targets};
- estimator.GetCamera().testResult.SetTimestamp(units::second_t(15));
+ estimator.GetCamera()->testResult = {3_ms, targets};
+ estimator.GetCamera()->testResult.SetTimestamp(units::second_t(15));
estimatedPose = estimator.Update();
EXPECT_TRUE(estimatedPose);
EXPECT_NEAR(15, estimatedPose.value().timestamp.to(), 1e-6);