Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for logging data in flight interface and data merge #215

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions modules/data_merge/data_merge_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
Merges detections and telemetry by time.
"""

import os
import pathlib
import queue

from utilities.workers import queue_proxy_wrapper
from utilities.workers import worker_controller
from .. import detections_and_time
from .. import merged_odometry_detections
from .. import odometry_and_time
from ..common.logger.modules import logger


def data_merge_worker(
Expand All @@ -28,7 +31,15 @@ def data_merge_worker(
Merge work is done in the worker process as the queues and control mechanisms
are naturally available.
"""
# TODO: Logging?

Xierumeng marked this conversation as resolved.
Show resolved Hide resolved
worker_name = pathlib.Path(__file__).stem
process_id = os.getpid()
result, local_logger = logger.Logger.create(f"{worker_name}_{process_id}", True)
if not result:
print("ERROR: Worker failed to create logger")
return

assert local_logger is not None

# Mitigate potential deadlock caused by early program exit
try:
Expand All @@ -39,7 +50,7 @@ def data_merge_worker(
timeout=timeout,
)
except queue.Empty:
print("ERROR: Queue timed out on startup")
local_logger.error("Queue timed out on startup", True)
return

while not controller.is_exit_requested():
Expand Down Expand Up @@ -72,15 +83,27 @@ def data_merge_worker(
previous_odometry.odometry_data,
detections.detections,
)

odometry_timestamp = previous_odometry.timestamp
Xierumeng marked this conversation as resolved.
Show resolved Hide resolved
else:
result, merged = merged_odometry_detections.MergedOdometryDetections.create(
current_odometry.odometry_data,
detections.detections,
)

odometry_timestamp = current_odometry.timestamp
Xierumeng marked this conversation as resolved.
Show resolved Hide resolved

local_logger.info(
f"Odometry timestamp: {odometry_timestamp}, detections timestamp: {detections.timestamp}, detections - odometry: {detections.timestamp - odometry_timestamp}",
True,
)

if not result:
local_logger.warning("Failed to create merged odometry and detections", True)
continue

local_logger.info(str(merged), True)

# Get Pylance to stop complaining
assert merged is not None

Expand Down
9 changes: 7 additions & 2 deletions modules/detections_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ def __str__(self) -> str:
To string.
"""
return (
f"{self.__class__}, time: {int(self.timestamp)}, size: {len(self)}\n"
+ f"{self.detections}"
f"{self.__class__}, time: {self.timestamp}, size: {len(self)}\n" + f"{self.detections}"
)

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

def __len__(self) -> int:
"""
Gets the number of detected objects.
Expand Down
12 changes: 11 additions & 1 deletion modules/flight_interface/flight_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ def run(self) -> "tuple[bool, odometry_and_time.OdometryAndTime | None]":

# Get Pylance to stop complaining
assert odometry_local is not None
return odometry_and_time.OdometryAndTime.create(odometry_local)

result, odometry_and_time_object = odometry_and_time.OdometryAndTime.create(odometry_local)
if not result:
return False, None

# Get Pylance to stop complaining
assert odometry_and_time_object is not None

self.__logger.info(str(odometry_and_time_object), True)

return True, odometry_and_time_object

def apply_decision(self, cmd: decision_command.DecisionCommand) -> bool:
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/odometry_and_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def __str__(self) -> str:
"""
To string.
"""
return f"{self.__class__}, time: {int(self.timestamp)}\n" + f"{self.odometry_data}"
return f"{self.__class__}, time: {self.timestamp}\n" + f"{self.odometry_data}"