Skip to content

Commit

Permalink
combined all logging together
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlou05 committed Nov 7, 2024
1 parent 439c9b0 commit 81f06dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
53 changes: 42 additions & 11 deletions modules/communications/communications.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""
Logs data and forwards it.
"""

import time

from .. import detection_in_world
from ..common.logger.modules import logger
from ..common.mavlink.modules import drone_odometry
from modules.common.logger.modules import logger
from modules.common.mavlink.modules.drone_odometry import DronePosition
from modules.detection_in_world import DetectionInWorld
from modules.flight_interface.local_global_conversion import detection_in_world_global_from_local
from ..common.mavlink.modules import drone_odometry_local
from ..common.mavlink.modules import local_global_conversion


class Communications:
""" """
"""
Currently logs data only.
"""

__create_key = object()

Expand All @@ -19,6 +26,10 @@ def create(
) -> "tuple[bool, Communications | None]":
"""
Logs data and forwards it.
home_location: Take-off location of drone.
Returns: Success, class object.
"""

return True, Communications(cls.__create_key, home_location, local_logger)
Expand All @@ -38,19 +49,39 @@ def __init__(
self.__logger = local_logger

def run(
self, detections_in_world: list[DetectionInWorld]
) -> tuple[bool, list[DetectionInWorld] | None]:
self, detections_in_world: list[detection_in_world.DetectionInWorld]
) -> tuple[bool, list[detection_in_world.DetectionInWorld] | None]:

detections_in_world_global = []
for detection_in_world in detections_in_world:
result, detection_in_world_global = detection_in_world_global_from_local(
self.__home_location, detection_in_world
# TODO: Change this when the conversion interface is changed
north = detection_in_world.centre[0]
east = detection_in_world.centre[1]
down = 0

result, drone_position_local = drone_odometry_local.DronePositionLocal.create(
north,
east,
down,
)
if not result:
self.__logger.warning(
f"Could not convert DetectionInWorld to DronePositionLocal:\ndetection in world: {detection_in_world}"
)
return False, None

result, detection_in_world_global = (
local_global_conversion.drone_position_global_from_local(
self.__home_location, drone_position_local
)
)

if not result:
# Log nothing if at least one of the conversions failed
self.__logger.error("conversion failed")
return False, detections_in_world
self.__logger.warning(
f"drone_position_global_from_local conversion failed:\nhome_location: {self.__home_location}\ndrone_position_local: {drone_position_local}"
)
return False, None

detections_in_world_global.append(detection_in_world_global)

Expand Down
6 changes: 6 additions & 0 deletions modules/detections_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def __str__(self) -> str:
"""
return f"cls: {self.label}, conf: {self.confidence}, bounds: {self.x_1} {self.y_1} {self.x_2} {self.y_2}"

def __repr__(self) -> str:
"""
For collections (e.g. list).
"""
return str(self)

def get_centre(self) -> "tuple[float, float]":
"""
Gets the xy centre of the bounding box.
Expand Down

0 comments on commit 81f06dc

Please sign in to comment.