-
Notifications
You must be signed in to change notification settings - Fork 37
Added a communication worker for logging cluster estimation #227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
4ef1755
initial commit
davisliu2006 99f2d28
Made fixes
AshishA26 b50d714
Modify home location to be part of create for flight interface and co…
maxlou05 39c55f0
combined all logging together
maxlou05 1bd2cb6
Add log_to_kml.py
Evang264 89a7221
Refactor for common changes
wdan31 0e8263d
Fixed communications module imports and implemented object position l…
wdan31 de18002
Added communications logger for logging cluster estimation
wdan31 a0b0560
Formatted python
wdan31 1173347
Added communcations worker manager
wdan31 7cf4667
Cluster estimations takes from communication to main queue
wdan31 16cc619
Fixed communications worker
wdan31 8ff6035
Reformatted kml conversion
wdan31 7562a88
initial commit
davisliu2006 5599ccc
Made fixes
AshishA26 9d3b588
Modify home location to be part of create for flight interface and co…
maxlou05 2501414
combined all logging together
maxlou05 e4029e7
Add log_to_kml.py
Evang264 9ede6b4
Refactor for common changes
wdan31 2be3b1d
Fixed communications module imports and implemented object position l…
wdan31 dea2413
Added communications logger for logging cluster estimation
wdan31 76ab64f
Formatted python
wdan31 194f0d8
Added communcations worker manager
wdan31 df2d4de
Cluster estimations takes from communication to main queue
wdan31 e214595
Fixed communications worker
wdan31 92c3299
Reformatted kml conversion
wdan31 c7ca9c7
Fixed logging and types in communications modules
wdan31 ce99100
Added timeout to communications worker
wdan31 4ebfdae
Merge branch 'comm-worker-logs-cluster' of https://github.com/UWARG/c…
wdan31 55755ca
Reworded logs from communications
wdan31 affadfb
Reworded logs from communications
wdan31 9e8df82
Updated cluster estimation logging
wdan31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Submodule common
updated
7 files
This file contains hidden or 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,90 @@ | ||
""" | ||
Logs data and forwards it. | ||
""" | ||
|
||
import time | ||
|
||
from .. import object_in_world | ||
from ..common.modules import position_global | ||
from ..common.modules import position_local | ||
from ..common.modules.logger import logger | ||
from ..common.modules.mavlink import local_global_conversion | ||
|
||
|
||
class Communications: | ||
""" | ||
Currently logs data only. | ||
""" | ||
|
||
__create_key = object() | ||
|
||
@classmethod | ||
def create( | ||
cls, | ||
home_position: position_global.PositionGlobal, | ||
local_logger: logger.Logger, | ||
) -> "tuple[True, Communications] | tuple[False, None]": | ||
""" | ||
Logs data and forwards it. | ||
|
||
home_position: Take-off position of drone. | ||
|
||
Returns: Success, class object. | ||
""" | ||
|
||
return True, Communications(cls.__create_key, home_position, local_logger) | ||
|
||
def __init__( | ||
self, | ||
class_private_create_key: object, | ||
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_position = home_position | ||
self.__logger = local_logger | ||
|
||
def run( | ||
self, | ||
objects_in_world: list[object_in_world.ObjectInWorld], | ||
) -> tuple[True, list[object_in_world.ObjectInWorld]] | tuple[False, None]: | ||
|
||
objects_in_world_global = [] | ||
for object_in_world in objects_in_world: | ||
# We assume detected objects are on the ground | ||
north = object_in_world.location_x | ||
east = object_in_world.location_y | ||
down = 0.0 | ||
maxlou05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result, object_position_local = position_local.PositionLocal.create( | ||
north, | ||
east, | ||
down, | ||
) | ||
if not result: | ||
self.__logger.warning( | ||
f"Could not convert ObjectInWorld to PositionLocal:\nobject in world: {object_in_world}" | ||
) | ||
return False, None | ||
|
||
result, object_in_world_global = ( | ||
local_global_conversion.position_global_from_position_local( | ||
self.__home_position, object_position_local | ||
) | ||
) | ||
if not result: | ||
# Log nothing if at least one of the conversions failed | ||
self.__logger.warning( | ||
f"position_global_from_position_local conversion failed:\nhome_position: {self.__home_position}\nobject_position_local: {object_position_local}" | ||
) | ||
return False, None | ||
|
||
objects_in_world_global.append(object_in_world_global) | ||
|
||
self.__logger.info(f"{time.time()}: {objects_in_world_global}") | ||
|
||
return True, objects_in_world |
This file contains hidden or 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,66 @@ | ||
""" | ||
Logs data and forwards it. | ||
""" | ||
|
||
import os | ||
import pathlib | ||
import queue | ||
|
||
from . import communications | ||
from utilities.workers import queue_proxy_wrapper | ||
from utilities.workers import worker_controller | ||
from ..common.modules.logger import logger | ||
|
||
|
||
def communications_worker( | ||
timeout: float, | ||
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_position_queue contains home positions for creating communications object. | ||
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() | ||
result, local_logger = logger.Logger.create(f"{worker_name}_{process_id}", True) | ||
if not result: | ||
print("ERROR: Worker failed to create logger") | ||
return | ||
|
||
# Get Pylance to stop complaining | ||
assert local_logger is not None | ||
|
||
local_logger.info("Logger initialized", True) | ||
|
||
# Get home position | ||
try: | ||
home_position = home_position_queue.queue.get(timeout=timeout) | ||
except queue.Empty: | ||
maxlou05 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local_logger.error("Home position queue timed out on startup", True) | ||
return | ||
|
||
local_logger.info(f"Home position received: {home_position}", True) | ||
|
||
result, comm = communications.Communications.create(home_position, local_logger) | ||
if not result: | ||
local_logger.error("Worker failed to create class object", True) | ||
return | ||
|
||
# Get Pylance to stop complaining | ||
assert comm is not None | ||
|
||
while not controller.is_exit_requested(): | ||
controller.check_pause() | ||
|
||
result, value = comm.run(input_queue.queue.get()) | ||
if not result: | ||
continue | ||
|
||
output_queue.queue.put(value) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.