-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created merged obstacle data struct (#42)
* created merged obstacle data struct * bug fix
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |