Skip to content

Commit

Permalink
created detection and odometry data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ashum68 committed Jun 4, 2024
1 parent 66e67ba commit 83429f3
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions modules/detection_and_odometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@
from . import drone_odometry_local


class LidarDetection:
"""
Lidar scan
"""

__create_key = object()

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

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

def __init__(self, create_key: object, distance: float, angle: float):
"""
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"Distance: {self.distance}, Angle: {self.angle}. "


class DetectionAndOdometry:
"""
Contains LiDAR reading and current local odometry.
Expand All @@ -14,33 +46,32 @@ class DetectionAndOdometry:

@classmethod
def create(
cls, distance: float, angle: float, local_odometry: drone_odometry_local.DroneOdometryLocal
cls,
lidar_detection: LidarDetection,
local_odometry: drone_odometry_local.DroneOdometryLocal,
) -> "tuple[bool, DetectionAndOdometry | None]":
"""
Distance is in metres.
Angle is in degrees.
Combines lidar reading with local odometry
"""

return True, DetectionAndOdometry(cls.__create_key, distance, angle, local_odometry)
return True, DetectionAndOdometry(cls.__create_key, lidar_detection, local_odometry)

def __init__(
self,
create_key: object,
distance: float,
angle: float,
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.distance = distance
self.angle = angle
self.detection = lidar_detection
self.odometry = local_odometry

def __str__(self) -> str:
"""
String representation.
"""
return f"{self.__class__}, time: "
return f"{self.__class__.__name__}, {self.detection}, str{self.odometry}"

0 comments on commit 83429f3

Please sign in to comment.