From c536a1c312758220dd855a856359cce1129baea8 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Thu, 21 Nov 2024 14:01:08 +1100 Subject: [PATCH] add missing log and use logger over print (#1596) This is closer to a port of the Java/C++ stuff and will mean we get a more standard print output with the rest of the logging in the lib --- photon-lib/py/photonlibpy/estimation/openCVHelp.py | 6 +++++- photon-lib/py/photonlibpy/simulation/simCameraProperties.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/photon-lib/py/photonlibpy/estimation/openCVHelp.py b/photon-lib/py/photonlibpy/estimation/openCVHelp.py index 2f687c189..7b1de9e23 100644 --- a/photon-lib/py/photonlibpy/estimation/openCVHelp.py +++ b/photon-lib/py/photonlibpy/estimation/openCVHelp.py @@ -1,3 +1,4 @@ +import logging import math from typing import Any @@ -11,6 +12,8 @@ from .rotTrlTransform3d import RotTrlTransform3d NWU_TO_EDN = Rotation3d(np.array([[0, -1, 0], [0, 0, -1], [1, 0, 0]])) EDN_TO_NWU = Rotation3d(np.array([[0, 0, 1], [-1, 0, 0], [0, -1, 0]])) +logger = logging.getLogger(__name__) + class OpenCVHelp: @staticmethod @@ -243,7 +246,7 @@ class OpenCVHelp: # solvePnP failed if reprojectionError is None or math.isnan(reprojectionError[0, 0]): - print("SolvePNP_Square failed!") + logger.error("SolvePNP_Square failed!") return None if alt: @@ -303,6 +306,7 @@ class OpenCVHelp: ) if math.isnan(error): + logger.error("SolvePNP_SQPNP failed!") return None # We have no alternative so set it to best as well diff --git a/photon-lib/py/photonlibpy/simulation/simCameraProperties.py b/photon-lib/py/photonlibpy/simulation/simCameraProperties.py index 4cefc944a..41de51ccc 100644 --- a/photon-lib/py/photonlibpy/simulation/simCameraProperties.py +++ b/photon-lib/py/photonlibpy/simulation/simCameraProperties.py @@ -9,6 +9,8 @@ from wpimath.units import hertz, seconds from ..estimation import RotTrlTransform3d +logger = logging.getLogger(__name__) + class SimCameraProperties: """Calibration and performance values for this camera. @@ -46,7 +48,7 @@ class SimCameraProperties: ) -> None: if fovDiag.degrees() < 1.0 or fovDiag.degrees() > 179.0: fovDiag = Rotation2d.fromDegrees(max(min(fovDiag.degrees(), 179.0), 1.0)) - logging.error("Requested invalid FOV! Clamping between (1, 179) degrees...") + logger.error("Requested invalid FOV! Clamping between (1, 179) degrees...") resDiag = math.sqrt(width * width + height * height) diagRatio = math.tan(fovDiag.radians() / 2.0)