Skip to content

Commit 2de0cff

Browse files
committed
Add overload of processAllUnreadResults() to support logging rejected poses
1 parent 574d0f6 commit 2de0cff

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

vision/src/main/java/com/team2813/lib2813/vision/MultiPhotonPoseEstimator.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import java.util.Map;
3535
import java.util.Objects;
3636
import java.util.Optional;
37+
import java.util.function.Consumer;
3738
import java.util.function.Predicate;
39+
import java.util.stream.Collectors;
3840
import org.photonvision.EstimatedRobotPose;
3941
import org.photonvision.PhotonCamera;
4042
import org.photonvision.PhotonPoseEstimator;
@@ -379,24 +381,44 @@ public void resetHeadingData(double timestampSeconds, Rotation3d heading) {
379381
}
380382

381383
/**
382-
* Sends all unread robot-pose estimations from all cameras to the provided consumer.
384+
* Sends all validated unread robot-pose estimations from all cameras to the provided consumer.
383385
*
384-
* <p>This method is supposed to be called from a routine updating drive-train pose with pose
385-
* estimates from the photon vision cameras.
386+
* <p>This method should be called from a routine updating drive-train pose with pose estimates
387+
* from the photon vision cameras.
386388
*
387-
* @param poseEstimateConsumer Functional interface for consuming computed pose estimates.
389+
* @param poseEstimateConsumer Consumer for validated pose estimates.
388390
*/
389391
public void processAllUnreadResults(PoseEstimateConsumer<C> poseEstimateConsumer) {
392+
processAllUnreadResults(poseEstimateConsumer, pose -> {});
393+
}
394+
395+
/**
396+
* Sends all unread robot-pose estimations from all cameras to the provided consumers.
397+
*
398+
* <p>This method should be called from a routine updating drive-train pose with pose estimates
399+
* from the photon vision cameras.
400+
*
401+
* @param poseEstimateConsumer Consumer for validated pose estimates.
402+
* @param rejectedPoseConsumer Consumer for rejected pose estimates.
403+
*/
404+
public void processAllUnreadResults(
405+
PoseEstimateConsumer<C> poseEstimateConsumer,
406+
Consumer<EstimatedRobotPose> rejectedPoseConsumer) {
390407
for (PhotonCameraWrapper<C> cameraWrapper : cameraWrappers) {
391-
List<EstimatedRobotPose> poses =
408+
Map<Boolean, List<EstimatedRobotPose>> poses =
392409
cameraWrapper.photonCamera.getAllUnreadResults().stream()
393410
.map(cameraWrapper.estimator::update) // PhotonPipelineResult -> EstimatedRobotPose
394411
.flatMap(Optional::stream) // Convert Stream<Optional<P>> -> Stream<P>
395-
.filter(isPoseValid)
396-
.toList();
412+
.collect(Collectors.partitioningBy(isPoseValid));
413+
414+
List<EstimatedRobotPose> validatedPoses = poses.get(Boolean.TRUE);
415+
for (EstimatedRobotPose pose : validatedPoses) {
416+
poseEstimateConsumer.addEstimatedRobotPose(pose, cameraWrapper.camera);
417+
}
418+
cameraWrapper.robotPosePublisher.publish(validatedPoses);
397419

398-
poses.forEach(pose -> poseEstimateConsumer.addEstimatedRobotPose(pose, cameraWrapper.camera));
399-
cameraWrapper.robotPosePublisher.publish(poses);
420+
List<EstimatedRobotPose> rejectedPoses = poses.get(Boolean.FALSE);
421+
rejectedPoses.forEach(rejectedPoseConsumer);
400422
}
401423
}
402424

0 commit comments

Comments
 (0)