Skip to content

Commit

Permalink
Add Custom TelloException for catching.
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarZyg committed Dec 25, 2021
1 parent 5c2effd commit 539bdf6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions djitellopy/tello.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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.
Expand Down

0 comments on commit 539bdf6

Please sign in to comment.