Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created lidar detection data structure #9

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions modules/lidar_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
LiDAR detection data structure.
"""


class LidarDetection:
"""
Lidar scan
"""

__create_key = object()

__DISTANCE_LIMIT = 50
__ANGLE_LIMIT = 170

@classmethod
def create(cls, distance: float, angle: float) -> "tuple[bool, LidarDetection | None]":
"""
Distance is in meters.
Angle is in degrees.
"""
if distance < 0 or distance > cls.__DISTANCE_LIMIT:
return False, None

if abs(angle) > cls.__ANGLE_LIMIT:
return False, None

return True, LidarDetection(cls.__create_key, distance, angle)

def __init__(self, create_key: object, distance: float, angle: float) -> None:
"""
Private constructor, use create() method.
"""
assert create_key is LidarDetection.__create_key, "Use create() method"

self.distance = distance
self.angle = angle

def __str__(self) -> str:
"""
String representation
"""
return f"{self.__class__.__name__}: Distance: {self.distance}, Angle: {self.angle}. "
Loading