From 738e3646f7de4c0204027bffca0a015f651e1a96 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 31 Aug 2024 12:30:09 -0400 Subject: [PATCH] Photonlibpy - Best Target Function #1223 (#1406) Supercedes https://github.com/PhotonVision/photonvision/pull/1223 --------- Co-authored-by: vladb --- photon-lib/py/photonlibpy/photonPipelineResult.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/photon-lib/py/photonlibpy/photonPipelineResult.py b/photon-lib/py/photonlibpy/photonPipelineResult.py index cd2fec3354..9dc68d0348 100644 --- a/photon-lib/py/photonlibpy/photonPipelineResult.py +++ b/photon-lib/py/photonlibpy/photonPipelineResult.py @@ -58,5 +58,14 @@ def getTimestampSeconds(self) -> float: def getTargets(self) -> list[PhotonTrackedTarget]: return self.targets + def getBestTarget(self) -> PhotonTrackedTarget: + """ + Returns the best target in this pipeline result. If there are no targets, this method will + return null. The best target is determined by the target sort mode in the PhotonVision UI. + """ + if not self.hasTargets(): + return None + return self.getTargets()[0] + def hasTargets(self) -> bool: return len(self.targets) > 0