From 95ae56827da7b3de0db4507a7a626f4dd86a6e1d Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Tue, 13 May 2025 17:23:13 +0200 Subject: [PATCH] refactor(cameras): width, fps and height is mandatory to have a value in robot config --- lerobot/common/robots/config.py | 11 +++++++++++ tests/cameras/test_opencv.py | 2 ++ 2 files changed, 13 insertions(+) diff --git a/lerobot/common/robots/config.py b/lerobot/common/robots/config.py index 83a13ca9..3fd2872c 100644 --- a/lerobot/common/robots/config.py +++ b/lerobot/common/robots/config.py @@ -12,6 +12,17 @@ class RobotConfig(draccus.ChoiceRegistry, abc.ABC): # Directory to store calibration file calibration_dir: Path | None = None + def __post_init__(self): + if hasattr(self, "cameras"): + cameras = self.cameras + if cameras: + for cam_name, cam_config in cameras.items(): + for attr in ["width", "height", "fps"]: + if getattr(cam_config, attr) is None: + raise ValueError( + f"Camera config for '{cam_name}' has None value for required attribute '{attr}'" + ) + @property def type(self) -> str: return self.get_choice_name(self.__class__) diff --git a/tests/cameras/test_opencv.py b/tests/cameras/test_opencv.py index 5b2ed2f6..7b244c35 100644 --- a/tests/cameras/test_opencv.py +++ b/tests/cameras/test_opencv.py @@ -28,6 +28,8 @@ from lerobot.common.cameras.configs import Cv2Rotation from lerobot.common.cameras.opencv import OpenCVCamera, OpenCVCameraConfig from lerobot.common.errors import DeviceAlreadyConnectedError, DeviceNotConnectedError +# NOTE(Steven): Consider improving the assert coverage + def test_base_class_implementation(): config = OpenCVCameraConfig(index_or_path=0)