This repository was archived by the owner on Nov 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Autonomous Landing Module #235
Merged
Merged
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
178b772
intial commit
ellyokes253 3954351
added files
ellyokes253 b80e668
removed old module
ellyokes253 8b822e0
made class
ellyokes253 fd8241f
made changes
ellyokes253 265cae9
added worker
ellyokes253 6fd5f9e
made changes
ellyokes253 8b1c536
issues commiting, now fixed
ellyokes253 876b714
made changes
ellyokes253 0b07de1
linter issues fixed
ellyokes253 38aad9b
fixing linter issues
ellyokes253 1c5b247
fixing code and linter issues
ellyokes253 398edaa
continuation of debugging
ellyokes253 dc81d8e
fixing linter issues
ellyokes253 af13347
fixing logger initialization
ellyokes253 6f4c829
fixing last linter issues
ellyokes253 224a7dc
last few linter issues
ellyokes253 c0af0dc
last few changes
ellyokes253 fb1e009
updated changes
ellyokes253 44656ad
fixing small linter issue
ellyokes253 619f8d7
fixed run()
ellyokes253 fbfcc79
pulling new commit changes in common
ellyokes253 3bca007
fixing linter error
ellyokes253 3ff8098
using first bbox
ellyokes253 7aa2f46
added AutoLandingInformation object
ellyokes253 a6b98e6
fixing small mistakes
ellyokes253 e2428ef
redefined AutoLandingInformation class
ellyokes253 dec4a18
results of new merge
ellyokes253 1ff5d4e
added changes
ellyokes253 e882a42
rebased and fixed comments
ellyokes253 17cd52a
fixed linter issues
ellyokes253 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
Empty file.
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,110 @@ | ||
| """ | ||
| Auto-landing script that calculates the necessary parameters | ||
| for use with LANDING_TARGET MAVLink command. | ||
| """ | ||
|
|
||
| import math | ||
|
|
||
| from .. import merged_odometry_detections | ||
| from ..common.modules.logger import logger | ||
|
|
||
|
|
||
| class AutoLandingInformation: | ||
| """ | ||
| Information necessary for the LANDING_TARGET MAVLink command. | ||
| """ | ||
|
|
||
| def __init__(self, angle_x: float, angle_y: float, target_dist: float) -> None: | ||
| """ | ||
| Information necessary for the LANDING_TARGET MAVLink command. | ||
|
|
||
| angle_x: Angle of the x coordinate of the bounding box within -π to π (rads). | ||
| angle_y: Angle of the y coordinate of the bounding box within -π to π (rads). | ||
| target_dist: Horizontal distance of vehicle to target (meters). | ||
| """ | ||
|
|
||
| self.angle_x = angle_x | ||
| self.angle_y = angle_y | ||
| self.target_dist = target_dist | ||
|
|
||
|
|
||
| class AutoLanding: | ||
| """ | ||
| Auto-landing script that calculates the necessary parameters | ||
| for use with LANDING_TARGET MAVLink command. | ||
| """ | ||
|
|
||
| __create_key = object() | ||
|
|
||
| @classmethod | ||
| 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. | ||
|
|
||
| Returns an AutoLanding object. | ||
| """ | ||
|
|
||
| return True, AutoLanding(cls.__create_key, fov_x, fov_y, im_h, im_w, 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: | ||
| """ | ||
| Private constructor, use create() method. | ||
| """ | ||
| assert class_private_create_key is AutoLanding.__create_key, "Use create() method" | ||
|
|
||
| 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, odometry_detections: merged_odometry_detections.MergedOdometryDetections | ||
| ) -> "tuple[bool, AutoLandingInformation]": | ||
| """ | ||
| Calculates the x and y angles in radians of the bounding box based on its center. | ||
|
|
||
| odometry_detections: A merged odometry dectections object. | ||
|
|
||
| Returns an AutoLandingInformation object. | ||
| """ | ||
|
|
||
| # TODO: Devise better algorithm to pick which detection to land at if several are detected | ||
| x_center, y_center = odometry_detections.detections[0].get_centre() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment with TODO: come up with a better algorithm to pick which detection to land at, if many are detected in one frame. |
||
|
|
||
| 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 | ||
|
|
||
| # This is height above ground level (AGL) | ||
| # down is how many meters down you are from home position, which is on the ground | ||
| height_agl = odometry_detections.odometry_local.position.down * -1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a comment here that says height above ground level (AGL), and that down is how many meters down you are from home position, which is on the ground. Hence the * -1 |
||
|
|
||
| x_dist = math.tan(angle_x) * height_agl | ||
| y_dist = math.tan(angle_y) * height_agl | ||
| ground_hyp = (x_dist**2 + y_dist**2) ** 0.5 | ||
| target_to_vehicle_dist = (ground_hyp**2 + height_agl**2) ** 0.5 | ||
|
|
||
| self.__logger.info( | ||
| f"X angle: {angle_x} Y angle: {angle_y}\nRequired horizontal correction: {ground_hyp} Distance from vehicle to target: {target_to_vehicle_dist}", | ||
| True, | ||
| ) | ||
|
|
||
| return True, AutoLandingInformation(angle_x, angle_y, target_to_vehicle_dist) | ||
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 @@ | ||
| """ | ||
| Auto-landing worker. | ||
| """ | ||
|
|
||
| import os | ||
| import pathlib | ||
| import time | ||
|
|
||
| from . import auto_landing | ||
| from ..common.modules.logger import logger | ||
| from utilities.workers import queue_proxy_wrapper | ||
| from utilities.workers import worker_controller | ||
|
|
||
|
|
||
| def auto_landing_worker( | ||
| fov_x: float, | ||
| fov_y: float, | ||
| im_h: float, | ||
| im_w: float, | ||
| period: float, | ||
| input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| controller: worker_controller.WorkerController, | ||
| ) -> None: | ||
| """ | ||
| Worker process. | ||
|
|
||
| period: Wait time in seconds. | ||
| 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) | ||
|
|
||
| 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) | ||
| return | ||
|
|
||
| # Get Pylance to stop complaining | ||
| assert auto_lander is not None | ||
|
|
||
| while not controller.is_exit_requested(): | ||
| controller.check_pause() | ||
|
|
||
| input_data = input_queue.queue.get() | ||
| if input_data is None: | ||
| continue | ||
|
|
||
| result, value = auto_lander.run(input_data) | ||
| if not result: | ||
| continue | ||
|
|
||
| output_queue.queue.put(value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place wait(period) down here, after this |
||
| time.sleep(period) | ||
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.