Skip to content

Commit

Permalink
fixing code and linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ellyokes253 committed Jan 23, 2025
1 parent 38aad9b commit 1c5b247
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
27 changes: 16 additions & 11 deletions modules/auto_landing/auto_landing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
Auto-landing script.
"""

import math

from ..common.modules.logger import logger
from .. import detections_and_time


class AutoLanding:
""" "
Auto-landing script.
"""

__create_key = object()

Expand All @@ -16,20 +17,26 @@ def create(
cls,
fov_x: float,
fov_y: float,
im_h: float,
im_w: float,
local_logger: logger.Logger,
) -> "tuple [bool, AutoLanding | None ]":
"""
fov_x: The horizontal camera field of view in degrees.
fov_y: The vertical camera field of view in degrees.
im_w: Width of image.
im_h: Height of image.
"""

return True, AutoLanding(cls.__create_key, fov_x, fov_y, local_logger)
return True, AutoLanding(cls.__create_key, fov_x, fov_y, im_w, im_h, local_logger)

def __init__(
self,
class_private_create_key: object,
fov_x: float,
fov_y: float,
im_h: float,
im_w: float,
local_logger: logger.Logger,
) -> None:
"""
Expand All @@ -39,6 +46,8 @@ def __init__(

self.fov_x = fov_x
self.fov_y = fov_y
self.im_h = im_h
self.im_w = im_w
self.__logger = local_logger

def run(self, height: float) -> "tuple[float, float, float]":
Expand All @@ -49,15 +58,11 @@ def run(self, height: float) -> "tuple[float, float, float]":
Return: Tuple of the x and y angles in radians respectively and the target distance in meters.
"""
x_center, y_center = detections_and_time.Detection.get_centre()

top_left, top_right, _, bottom_right = detections_and_time.Detection.get_corners()

im_w = abs(top_right - top_left)
im_h = abs(top_right - bottom_right)
x_center, y_center = detections_and_time.Detection.get_centre()

angle_x = (x_center - im_w / 2) * (self.fov_x * (math.pi / 180)) / im_w
angle_y = (y_center - im_h / 2) * (self.fov_y * (math.pi / 180)) / im_h
angle_x = (x_center - self.im_w / 2) * (self.fov_x * (math.pi / 180)) / self.im_w
angle_y = (y_center - self.im_h / 2) * (self.fov_y * (math.pi / 180)) / self.im_h

self.__logger.info(f"X angle (rad): {angle_x}", True)
self.__logger.info(f"Y angle (rad): {angle_y}", True)
Expand Down
10 changes: 9 additions & 1 deletion modules/auto_landing/auto_landing_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
def auto_landing_worker(
fov_x: float,
fov_y: float,
im_h: float,
im_w: float,
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
) -> None:
"""
Worker process.
input_queue and output_queue are data queues.
controller is how the main process communicates to this worker process.
"""

worker_name = pathlib.Path(__file__).stem
process_id = os.getpid()
Expand All @@ -31,7 +39,7 @@ def auto_landing_worker(

local_logger.info("Logger initialized", True)

result, auto_lander = auto_landing.AutoLanding.create(fov_x, fov_y, local_logger)
result, auto_lander = auto_landing.AutoLanding.create(fov_x, fov_y, im_h, im_w, local_logger)

if not result:
local_logger.error("Worker failed to create class object", True)
Expand Down

0 comments on commit 1c5b247

Please sign in to comment.