Skip to content

Commit

Permalink
Lidar processing (#49)
Browse files Browse the repository at this point in the history
* Created classes to represent an oscillation of LiDAR Readings

* Fixed Linting, Created classes to represent lidar oscillations

* Made Changes based on PR review. added min_angle max_angle, used LidarDetection objects, adjusted _str_ to print on one line and include all relevant details

* made changes in review, fixed for linting

* changed imports, removed None checks for array of LidarDetection

* Made final review change for empty check
  • Loading branch information
Mmoyv27 authored Oct 23, 2024
1 parent 7469886 commit 52f39eb
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions modules/lidar_oscillation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Representing a LiDAR Oscillation
"""

from . import lidar_detection


class LidarOscillation:
"""
Class to represent a collection of LiDAR readings that make up an oscillation.
"""

__create_key = object()

@classmethod
def create(
cls, readings: list[lidar_detection.LidarDetection]
) -> "tuple[bool, LidarOscillation | None]":
"""
Create a new LidarOscillation object from a list of LidarReading objects.
"""
if not readings:
return False, None
return True, LidarOscillation(cls.__create_key, readings)

def __init__(
self, class_private_create_key: object, readings: list[lidar_detection.LidarDetection]
) -> None:
"""
Private constructor, use create() method to instantiate.
"""
assert class_private_create_key is LidarOscillation.__create_key, "Use the create() method"

self.readings = readings
angles = [reading.angle for reading in readings]
self.min_angle = min(angles)
self.max_angle = max(angles)

def __str__(self) -> str:
"""
Return a string representation of the LiDAR oscillation data.
"""
reading_strs = []
for reading in self.readings:
reading_strs.append(str(reading))
formatted_readings = ", ".join(reading_strs)
return f"LidarOscillation: {len(self.readings)} readings, Min angle: {self.min_angle}, Max angle: {self.max_angle}, Readings: {formatted_readings}."

0 comments on commit 52f39eb

Please sign in to comment.