diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index b87cfc9..0000000 --- a/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -E:\181115\Tello-Python -$ cat ./.gitattributes -*.bat -text \ No newline at end of file diff --git a/Single_Tello_Test/command.txt b/Single_Tello_Test/command.txt index 2690e65..0a01db7 100644 --- a/Single_Tello_Test/command.txt +++ b/Single_Tello_Test/command.txt @@ -1,4 +1,6 @@ command takeoff -delay 5 +curve 50 0 50 100 0 0 60 +curve -50 0 -50 -100 0 0 60 +flip f land diff --git a/Single_Tello_Test/stats.py b/Single_Tello_Test/stats.py deleted file mode 100644 index ca2ab4e..0000000 --- a/Single_Tello_Test/stats.py +++ /dev/null @@ -1,45 +0,0 @@ -from datetime import datetime - -class Stats: - def __init__(self, command, id): - self.command = command - self.response = None - self.id = id - - self.start_time = datetime.now() - self.end_time = None - self.duration = None - - def add_response(self, response): - self.response = response - self.end_time = datetime.now() - self.duration = self.get_duration() - # self.print_stats() - - def get_duration(self): - diff = self.end_time - self.start_time - return diff.total_seconds() - - def print_stats(self): - print '\nid: %s' % self.id - print 'command: %s' % self.command - print 'response: %s' % self.response - print 'start time: %s' % self.start_time - print 'end_time: %s' % self.end_time - print 'duration: %s\n' % self.duration - - def got_response(self): - if self.response is None: - return False - else: - return True - - def return_stats(self): - str = '' - str += '\nid: %s\n' % self.id - str += 'command: %s\n' % self.command - str += 'response: %s\n' % self.response - str += 'start time: %s\n' % self.start_time - str += 'end_time: %s\n' % self.end_time - str += 'duration: %s\n' % self.duration - return str \ No newline at end of file diff --git a/Single_Tello_Test/tello.py b/Single_Tello_Test/tello.py index b69563e..aeac7bd 100644 --- a/Single_Tello_Test/tello.py +++ b/Single_Tello_Test/tello.py @@ -1,7 +1,6 @@ import socket import threading import time -from stats import Stats class Tello: def __init__(self): @@ -17,58 +16,25 @@ def __init__(self): self.tello_ip = '192.168.10.1' self.tello_port = 8889 - self.tello_adderss = (self.tello_ip, self.tello_port) - self.log = [] + self.tello_address = (self.tello_ip, self.tello_port) + self.response_available = threading.Event() # flag to signal when the response has been received - self.MAX_TIME_OUT = 15.0 def send_command(self, command): - """ - Send a command to the ip address. Will be blocked until - the last command receives an 'OK'. - If the command fails (either b/c time out or error), - will try to resend the command - :param command: (str) the command to send - :param ip: (str) the ip of Tello - :return: The latest command response - """ - self.log.append(Stats(command, len(self.log))) - self.socket.sendto(command.encode('utf-8'), self.tello_adderss) - print 'sending command: %s to %s' % (command, self.tello_ip) + self.response_available.clear() # reset the flag - start = time.time() - while not self.log[-1].got_response(): - now = time.time() - diff = now - start - if diff > self.MAX_TIME_OUT: - print 'Max timeout exceeded... command %s' % command - # TODO: is timeout considered failure or next command still get executed - # now, next one got executed - return - print 'Done!!! sent command: %s to %s' % (command, self.tello_ip) + print('[%s] Sending command: %s to %s' % (time.ctime(), command, self.tello_ip)) + self.socket.sendto(command.encode('utf-8'), self.tello_address) - def _receive_thread(self): - """Listen to responses from the Tello. + self.response_available.wait() # block until the response has been received (TODO: Add a timeout for the request) - Runs as a thread, sets self.response to whatever the Tello last returned. - """ + def _receive_thread(self): while True: try: self.response, ip = self.socket.recvfrom(1024) - print('from %s: %s' % (ip, self.response)) - - self.log[-1].add_response(self.response) - except socket.error, exc: - print "Caught exception socket.error : %s" % exc - - def on_close(self): - pass - # for ip in self.tello_ip_list: - # self.socket.sendto('land'.encode('utf-8'), (ip, 8889)) - # self.socket.close() - - def get_log(self): - return self.log - + self.response_available.set() # signal that the response has been received + print('[%s] Received from %s: %s\n' % (time.ctime(), ip, self.response)) + except socket.error as exc: + print("Caught exception socket.error: %s" % exc) diff --git a/Single_Tello_Test/tello_test.py b/Single_Tello_Test/tello_test.py index 1692ccc..4a333ba 100644 --- a/Single_Tello_Test/tello_test.py +++ b/Single_Tello_Test/tello_test.py @@ -1,10 +1,7 @@ from tello import Tello import sys -from datetime import datetime import time -start_time = str(datetime.now()) - file_name = sys.argv[1] f = open(file_name, "r") @@ -17,16 +14,8 @@ if command.find('delay') != -1: sec = float(command.partition('delay')[2]) - print 'delay %s' % sec + print('delay %s' % sec) time.sleep(sec) pass else: - tello.send_command(command) - -log = tello.get_log() - -out = open('log/' + start_time + '.txt', 'w') -for stat in log: - stat.print_stats() - str = stat.return_stats() - out.write(str) + tello.send_command(command) \ No newline at end of file