Skip to content

Commit

Permalink
rebase to main for common repo refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlou05 committed Nov 7, 2024
2 parents 81f06dc + c75347e commit e934c67
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions main_2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def main() -> int:
VIDEO_INPUT_SAVE_PREFIX = str(pathlib.Path(logging_path, VIDEO_INPUT_SAVE_NAME_PREFIX))

DETECT_TARGET_WORKER_COUNT = config["detect_target"]["worker_count"]
detect_target_option_int = config["detect_target"]["option"]
DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(detect_target_option_int)
DETECT_TARGET_OPTION_INT = config["detect_target"]["option"]
DETECT_TARGET_OPTION = detect_target_factory.DetectTargetOption(DETECT_TARGET_OPTION_INT)
DETECT_TARGET_DEVICE = "cpu" if args.cpu else config["detect_target"]["device"]
DETECT_TARGET_MODEL_PATH = config["detect_target"]["model_path"]
DETECT_TARGET_OVERRIDE_FULL_PRECISION = args.full
Expand Down
23 changes: 12 additions & 11 deletions modules/communications/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import time

from .. import detection_in_world
from ..common.logger.modules import logger
from ..common.mavlink.modules import drone_odometry
from ..common.mavlink.modules import drone_odometry_local
from ..common.mavlink.modules import local_global_conversion
from ..common.modules.logger import logger
from ..common.modules import position_global
from ..common.modules import position_local
from ..common.modules.mavlink import local_global_conversion


class Communications:
Expand All @@ -21,7 +21,7 @@ class Communications:
@classmethod
def create(
cls,
home_location: drone_odometry.DronePosition,
home_position: position_global.PositionGlobal,
local_logger: logger.Logger,
) -> "tuple[bool, Communications | None]":
"""
Expand All @@ -32,20 +32,20 @@ def create(
Returns: Success, class object.
"""

return True, Communications(cls.__create_key, home_location, local_logger)
return True, Communications(cls.__create_key, home_position, local_logger)

def __init__(
self,
class_private_create_key: object,
home_location: drone_odometry.DronePosition,
home_position: position_global.PositionGlobal,
local_logger: logger.Logger,
) -> None:
"""
Private constructor, use create() method.
"""
assert class_private_create_key is Communications.__create_key, "Use create() method"

self.__home_location = home_location
self.__home_location = home_position
self.__logger = local_logger

def run(
Expand All @@ -59,19 +59,20 @@ def run(
east = detection_in_world.centre[1]
down = 0

result, drone_position_local = drone_odometry_local.DronePositionLocal.create(
result, drone_position_local = position_local.PositionLocal.create(
north,
east,
down,
)

if not result:
self.__logger.warning(
f"Could not convert DetectionInWorld to DronePositionLocal:\ndetection in world: {detection_in_world}"
f"Could not convert DetectionInWorld to PositionLocal:\ndetection in world: {detection_in_world}"
)
return False, None

result, detection_in_world_global = (
local_global_conversion.drone_position_global_from_local(
local_global_conversion.position_global_from_position_local(
self.__home_location, drone_position_local
)
)
Expand Down
10 changes: 5 additions & 5 deletions modules/communications/communications_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
from . import communications
from utilities.workers import queue_proxy_wrapper
from utilities.workers import worker_controller
from ..common.logger.modules import logger
from ..common.modules.logger import logger


def communications_worker(
home_location_queue: queue_proxy_wrapper.QueueProxyWrapper,
home_position_queue: queue_proxy_wrapper.QueueProxyWrapper,
input_queue: queue_proxy_wrapper.QueueProxyWrapper,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
) -> None:
"""
Worker process.
home_location: get home_location for init
home_position: get home_position for init
"""

worker_name = pathlib.Path(__file__).stem
Expand All @@ -36,9 +36,9 @@ def communications_worker(
local_logger.info("Logger initialized", True)

# Get home location
home_location = home_location_queue.queue.get()
home_position = home_position_queue.queue.get()

result, comm = communications.Communications.create(home_location, local_logger)
result, comm = communications.Communications.create(home_position, local_logger)
if not result:
local_logger.error("Worker failed to create class object", True)
return
Expand Down
10 changes: 5 additions & 5 deletions modules/flight_interface/flight_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def create(
return False, None

# Get Pylance to stop complaining
assert home_location is not None
assert home_position is not None

local_logger.info(f"Home location: {home_location}", True)
local_logger.info(str(home_position), True)

return True, FlightInterface(cls.__create_key, controller, home_position, local_logger)

Expand All @@ -67,11 +67,11 @@ def __init__(
self.__home_position = home_position
self.__logger = local_logger

def get_home_location(self) -> drone_odometry.DronePosition:
def get_home_position(self) -> position_global.PositionGlobal:
"""
Accessor for home location.
Accessor for home position.
"""
return self.__home_location
return self.__home_position

def run(self) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]":
"""
Expand Down
4 changes: 2 additions & 2 deletions modules/flight_interface/flight_interface_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def flight_interface_worker(
# Get Pylance to stop complaining
assert interface is not None

home_location = interface.get_home_location()
communications_output_queue.queue.put(home_location)
home_position = interface.get_home_position()
communications_output_queue.queue.put(home_position)

while not controller.is_exit_requested():
controller.check_pause()
Expand Down

0 comments on commit e934c67

Please sign in to comment.