Skip to content

Commit

Permalink
created merged obstacle data struct (#42)
Browse files Browse the repository at this point in the history
* created merged obstacle data struct

* bug fix
  • Loading branch information
ashum68 authored Aug 20, 2024
1 parent a07852d commit 5636ee0
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions modules/obstacles_and_odometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Obstacles and local odometry merged data structure.
"""

from . import drone_odometry_local
from . import obstacle


class ObstaclesAndOdometry:
"""
Contains obstacles and current local odometry.
"""

__create_key = object()

@classmethod
def create(
cls,
obstacles: "list[obstacle.Obstacle]",
local_odometry: drone_odometry_local.DroneOdometryLocal,
) -> "tuple[bool, ObstaclesAndOdometry | None]":
"""
Combines obstacles with local odometry.
"""
if local_odometry is None:
return False, None

return True, ObstaclesAndOdometry(cls.__create_key, obstacles, local_odometry)

def __init__(
self,
create_key: object,
obstacles: "list[obstacle.Obstacle]",
local_odometry: drone_odometry_local.DroneOdometryLocal,
) -> None:
"""
Private constructor, use create() method.
"""
assert create_key is ObstaclesAndOdometry.__create_key, "Use create() method"

self.obstacles = obstacles
self.odometry = local_odometry

def __str__(self) -> str:
"""
String representation.
"""
obstacles_str = ", ".join(str(obstacle) for obstacle in self.obstacles)
return f"{self.__class__.__name__}, Obstacles: ({len(self.obstacles)}): {obstacles_str}, str{self.odometry}"

0 comments on commit 5636ee0

Please sign in to comment.