-
Notifications
You must be signed in to change notification settings - Fork 37
Decision Worker #187
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
Open
HermanG05
wants to merge
21
commits into
main
Choose a base branch
from
test-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Decision Worker #187
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
06e3669
Created decision worker
HermanG05 e7ce859
Fixed Formatting
HermanG05 7b0cc15
Made requested changes
HermanG05 30a8434
Changed get_nowait() to get() to avoid exception
HermanG05 2e590a7
Added an integration test for the decision worker, addressed other co…
HermanG05 0dcfb37
Made Requested Changes
HermanG05 6cc1a93
Updated.
HermanG05 c42fef0
Updated.
HermanG05 e67de0c
Updated, fixed imports.
HermanG05 f3be8e0
fixed formatting
HermanG05 5a0d5a3
fixed formatting
HermanG05 49ca9c0
Updated constructor calls, fixed formatting
HermanG05 0ec84ae
fixed formatting
HermanG05 e347895
Added TODO
HermanG05 65472f9
Rewrote simulate_cluster_estimation_worker.py
HermanG05 bb75213
reformatted
HermanG05 a53006a
removed import
HermanG05 0c2dea5
Rewrote the cluster_estimation_worker function and made changes to fl…
HermanG05 0560ff0
Updated
HermanG05 4de9ee0
Readded submodules
HermanG05 4a4b0f9
Addressed bugs in landing_pad_tracking
HermanG05 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
Retrieves list of landing pads from cluster estimation and outputs decision to the flight controller. | ||
""" | ||
|
||
from utilities.workers import queue_proxy_wrapper | ||
from utilities.workers import worker_controller | ||
from . import decision | ||
from . import landing_pad_tracking | ||
from . import search_pattern | ||
|
||
|
||
def decision_worker( | ||
distance_squared_threshold: float, | ||
tolerance: float, | ||
camera_fov_forwards: float, | ||
camera_fov_sideways: float, | ||
search_height: float, | ||
search_overlap: float, | ||
small_adjustment: float, | ||
odometry_input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
cluster_input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
controller: worker_controller.WorkerController, | ||
) -> None: | ||
""" | ||
Worker process. | ||
|
||
PARAMETERS | ||
---------- | ||
- camera_fov_forwards, camera_fov_sideways, search_height, search_overlap, distance_squared_threshold, | ||
and small_adjustment are arguments for the constructors below. | ||
- cluster_input_queue and output_queue are the data queues. | ||
- controller is how the main process communicates to this worker. | ||
""" | ||
# TODO: Need to rework how we get odometry data | ||
|
||
landing_pads = landing_pad_tracking.LandingPadTracking(distance_squared_threshold) | ||
decision_maker = decision.Decision(tolerance) | ||
search = search_pattern.SearchPattern( | ||
camera_fov_forwards, | ||
camera_fov_sideways, | ||
search_height, | ||
search_overlap, | ||
current_position_x=0.0, | ||
current_position_y=0.0, | ||
distance_squared_threshold=distance_squared_threshold, | ||
small_adjustment=small_adjustment, | ||
) | ||
|
||
while not controller.is_exit_requested(): | ||
controller.check_pause() | ||
|
||
curr_state = odometry_input_queue.queue.get() | ||
|
||
if curr_state is None: | ||
continue | ||
|
||
input_data = cluster_input_queue.queue.get() | ||
|
||
if input_data is None: | ||
continue | ||
|
||
is_found, best_landing_pads = landing_pads.run(input_data) | ||
|
||
# Runs decision only if there exists a landing pad | ||
if not is_found: | ||
result, value = search.continue_search(curr_state) | ||
else: | ||
result, value = decision_maker.run(curr_state, best_landing_pads) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# For any non-Jetson computer (i.e. all developers) | ||
--extra-index-url https://download.pytorch.org/whl/cu117 | ||
torch==1.13.1+cu117 | ||
torchvision==0.14.1+cu117 | ||
torch==2.0.1+cu117 | ||
torchvision==0.15.2+cu117 | ||
ultralytics |
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,149 @@ | ||
""" | ||
Test worker process. | ||
""" | ||
|
||
import multiprocessing as mp | ||
import time | ||
|
||
from modules import drone_odometry_local | ||
from modules import object_in_world | ||
from modules import odometry_and_time | ||
from modules.decision import decision | ||
from modules.decision import decision_worker | ||
from utilities.workers import worker_controller | ||
from utilities.workers import queue_proxy_wrapper | ||
|
||
|
||
DISTANCE_SQUARED_THRESHOLD = 25 # Distance is in meters | ||
|
||
TOLERANCE = 0.1 # meters | ||
|
||
CAMERA_FOV_FORWARDS = 90 # degrees | ||
CAMERA_FOV_SIDEWAYS = 120 # degrees | ||
|
||
SEARCH_HEIGHT = 10 # meters | ||
SEARCH_OVERLAP = 0.2 | ||
|
||
SMALL_ADJUSTMENT = 0.5 # meters | ||
|
||
WORK_COUNT = 5 | ||
|
||
Xierumeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Xierumeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def simulate_cluster_estimation_worker( | ||
input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
) -> None: | ||
""" | ||
Places list of detected landing pads into the queue. | ||
""" | ||
|
||
result, object1 = object_in_world.ObjectInWorld.create(1.0, 2.0, 0.9) | ||
assert result | ||
assert object1 is not None | ||
|
||
result, object2 = object_in_world.ObjectInWorld.create(4.5, 3.0, 2.0) | ||
assert result | ||
assert object2 is not None | ||
|
||
result, object3 = object_in_world.ObjectInWorld.create(7.2, 2.9, 4.6) | ||
assert result | ||
assert object3 is not None | ||
|
||
objects = [object1, object2, object3] | ||
|
||
input_queue.queue.put(objects) | ||
|
||
|
||
def simulate_flight_interface_worker( | ||
timestamp: float, odometry_queue: queue_proxy_wrapper.QueueProxyWrapper | ||
) -> None: | ||
""" | ||
Place odometry data into queue of size 1. | ||
""" | ||
|
||
result, drone_position = drone_odometry_local.DronePositionLocal.create(0.0, 2.0, -1.0) | ||
assert result | ||
assert drone_position is not None | ||
|
||
result, drone_orientation = drone_odometry_local.DroneOrientationLocal.create_new(0.0, 0.0, 0.0) | ||
assert result | ||
assert drone_orientation is not None | ||
|
||
result, drone_odometry = drone_odometry_local.DroneOdometryLocal.create( | ||
drone_position, drone_orientation | ||
) | ||
assert result | ||
assert drone_odometry is not None | ||
|
||
result, drone_odometry_and_time = odometry_and_time.OdometryAndTime.create(drone_odometry) | ||
assert result | ||
assert drone_odometry_and_time is not None | ||
|
||
drone_odometry_and_time.timestamp = timestamp | ||
|
||
odometry_queue.queue.put(drone_odometry_and_time) | ||
|
||
|
||
def main() -> int: | ||
""" | ||
Main function. | ||
""" | ||
controller = worker_controller.WorkerController() | ||
mp_manager = mp.Manager() | ||
|
||
cluster_input_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
odometry_input_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager, maxsize=1) | ||
decision_output_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) | ||
|
||
worker = mp.Process( | ||
target=decision_worker.decision_worker, | ||
args=( | ||
DISTANCE_SQUARED_THRESHOLD, | ||
TOLERANCE, | ||
CAMERA_FOV_FORWARDS, | ||
CAMERA_FOV_SIDEWAYS, | ||
SEARCH_HEIGHT, | ||
SEARCH_OVERLAP, | ||
SMALL_ADJUSTMENT, | ||
odometry_input_queue, | ||
cluster_input_queue, | ||
decision_output_queue, | ||
controller, | ||
), | ||
) | ||
|
||
# Starts the decision worker | ||
worker.start() | ||
|
||
# Simulate odometry data and cluster estimation | ||
for i in range(0, WORK_COUNT): | ||
simulate_flight_interface_worker(i, odometry_input_queue) | ||
simulate_cluster_estimation_worker(cluster_input_queue) | ||
|
||
time.sleep(1) | ||
|
||
for i in range(0, WORK_COUNT): | ||
simulate_flight_interface_worker(i, odometry_input_queue) | ||
simulate_cluster_estimation_worker(cluster_input_queue) | ||
|
||
controller.request_exit() | ||
|
||
# Test | ||
for i in range(0, WORK_COUNT * 2): | ||
decision_output: decision.Decision = decision_output_queue.queue.get_nowait() | ||
print(f"Decision output: {decision_output}") | ||
assert decision_output is not None | ||
|
||
# Teardown | ||
odometry_input_queue.fill_and_drain_queue() | ||
cluster_input_queue.fill_and_drain_queue() | ||
worker.join() | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
result_main = main() | ||
if result_main < 0: | ||
print(f"ERROR: Status code: {result_main}") | ||
|
||
print("Done!") |
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
Oops, something went wrong.
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.