diff --git a/modules/detection_and_odometry.py b/modules/detection_and_odometry.py deleted file mode 100644 index 29c6af8..0000000 --- a/modules/detection_and_odometry.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -LiDAR detection and local odometry data structure. -""" - -from . import drone_odometry_local -from . import lidar_detection - - -class DetectionAndOdometry: - """ - Contains LiDAR reading and current local odometry. - """ - - __create_key = object() - - @classmethod - def create( - cls, - detection: lidar_detection.LidarDetection, - local_odometry: drone_odometry_local.DroneOdometryLocal, - ) -> "tuple[bool, DetectionAndOdometry | None]": - """ - Combines lidar reading with local odometry - """ - - if detection is None: - return False, None - - if local_odometry is None: - return False, None - - return True, DetectionAndOdometry(cls.__create_key, detection, local_odometry) - - def __init__( - self, - create_key: object, - detection: lidar_detection.LidarDetection, - local_odometry: drone_odometry_local.DroneOdometryLocal, - ) -> None: - """ - Private constructor, use create() method. - """ - assert create_key is DetectionAndOdometry.__create_key, "Use create() method" - - self.detection = detection - self.odometry = local_odometry - - def __str__(self) -> str: - """ - String representation. - """ - return f"{self.__class__.__name__}, {self.detection}, str{self.odometry}" diff --git a/modules/detections_and_odometry.py b/modules/detections_and_odometry.py new file mode 100644 index 0000000..1ef2144 --- /dev/null +++ b/modules/detections_and_odometry.py @@ -0,0 +1,52 @@ +""" +LiDAR detection and local odometry data structure. +""" + +from . import drone_odometry_local +from . import lidar_detection + + +class DetectionsAndOdometry: + """ + Contains LiDAR readings and current local odometry. + """ + + __create_key = object() + + @classmethod + def create( + cls, + detections: "list[lidar_detection.LidarDetection]", + local_odometry: drone_odometry_local.DroneOdometryLocal, + ) -> "tuple[bool, DetectionsAndOdometry | None]": + """ + Combines lidar readings with local odometry + """ + if len(detections) == 0: + return False, None + + if local_odometry is None: + return False, None + + return True, DetectionsAndOdometry(cls.__create_key, detections, local_odometry) + + def __init__( + self, + create_key: object, + detections: "list[lidar_detection.LidarDetection]", + local_odometry: drone_odometry_local.DroneOdometryLocal, + ) -> None: + """ + Private constructor, use create() method. + """ + assert create_key is DetectionsAndOdometry.__create_key, "Use create() method" + + self.detections = detections + self.odometry = local_odometry + + def __str__(self) -> str: + """ + String representation. + """ + detections_str = ", ".join(str(detection) for detection in self.detections) + return f"{self.__class__.__name__}, Detections ({len(self.detections)}): {detections_str}, str{self.odometry}"