Skip to content
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

Port Single_Tello_Test to Python 3 #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

4 changes: 3 additions & 1 deletion Single_Tello_Test/command.txt
Original file line number Diff line number Diff line change
@@ -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
45 changes: 0 additions & 45 deletions Single_Tello_Test/stats.py

This file was deleted.

56 changes: 11 additions & 45 deletions Single_Tello_Test/tello.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import socket
import threading
import time
from stats import Stats

class Tello:
def __init__(self):
Expand All @@ -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)
15 changes: 2 additions & 13 deletions Single_Tello_Test/tello_test.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)