From 539bdf6301e246d1a97e0eaacbd72a9df7e15789 Mon Sep 17 00:00:00 2001 From: Oskar <56176746+OskarZyg@users.noreply.github.com> Date: Sat, 25 Dec 2021 21:10:14 +0000 Subject: [PATCH] Add Custom TelloException for catching. --- djitellopy/tello.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/djitellopy/tello.py b/djitellopy/tello.py index c313f1c..a9b9412 100644 --- a/djitellopy/tello.py +++ b/djitellopy/tello.py @@ -19,6 +19,10 @@ client_socket: socket.socket +class TelloException(Exception): + pass + + @enforce_types class Tello: """Python wrapper to interact with the Ryze Tello drone using the official Tello api. @@ -231,7 +235,7 @@ def get_state_field(self, key: str): if key in state: return state[key] else: - raise Exception('Could not get state property: {}'.format(key)) + raise TelloException('Could not get state property: {}'.format(key)) def get_mission_pad_id(self) -> int: """Mission pad ID of the currently detected mission pad @@ -511,7 +515,7 @@ def raise_result_error(self, command: str, response: str) -> bool: Internal method, you normally wouldn't call this yourself. """ tries = 1 + self.retry_count - raise Exception("Command '{}' was unsuccessful for {} tries. Latest response:\t'{}'" + raise TelloException("Command '{}' was unsuccessful for {} tries. Latest response:\t'{}'" .format(command, tries, response)) def connect(self, wait_for_state=True): @@ -529,7 +533,7 @@ def connect(self, wait_for_state=True): time.sleep(1 / REPS) if not self.get_current_state(): - raise Exception('Did not receive a state packet from the Tello') + raise TelloException('Did not receive a state packet from the Tello') def send_keepalive(self): """Send a keepalive packet to prevent the drone from landing after 15s @@ -1020,8 +1024,8 @@ def __init__(self, tello, address): Tello.LOGGER.debug('trying to grab video frames...') self.container = av.open(self.address, timeout=(Tello.FRAME_GRAB_TIMEOUT, None)) except av.error.ExitError: - raise Exception('Failed to grab video frames from video stream') - + raise TelloException('Failed to grab video frames from video stream') + self.stopped = False self.worker = Thread(target=self.update_frame, args=(), daemon=True) @@ -1042,8 +1046,8 @@ def update_frame(self): self.container.close() break except av.error.ExitError: - raise Exception('Do not have enough frames for decoding, please try again or increase video fps before get_frame_read()') - + raise TelloException('Do not have enough frames for decoding, please try again or increase video fps before get_frame_read()') + def stop(self): """Stop the frame update worker Internal method, you normally wouldn't call this yourself.