Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

Python3 Help

DJITom

New member
Joined
May 31, 2018
Messages
1
Reaction score
0
I'm working on a python script that I want it to read a command file to execute flight commands. While the script appears to work with commands being displayed in output, it does not translate to the Tello unless the commands are typed manually. Below is a video link of the code in action and below is the actual code.

Video link:

--------------------Start--------------------------------------------
#
# Tello Control
#

import threading
import socket
import sys
import time


host = ''
port = 9000
locaddr = (host,port)


# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

tello_address = ('192.168.10.1', 8889)

sock.bind(locaddr)

def recv():
count = 0
while True:
try:
data, server = sock.recvfrom(1518)
print(data.decode(encoding="utf-8"))
except Exception:
print ('\nExit . . .\n')
break


print ('\r\n\r\nTello Flight by Python.\r\n')

print ('Tello: command takeoff land flip forward back left right \r\n up down cw ccw speed speed?\r\n')

print ('end -- quit demo.\r\n')
sys.stdout.write('command\r\n')
##print ('\nCommand')

path = 'tellofly.txt'
fly_file = open(path,'r')
fly = fly_file.read()


#new_path = 'new_fly.txt'
#new_fly = open(new_path,'w')

## title = 'fly of the Week\n'
## new_fly.write(title)
## print(title)

## new_fly.write(fly)
sys.stdout.write(fly)

fly_file.close()
#new_fly.close()

##recvThread create
recvThread = threading.Thread(target=recv)
recvThread.start()

while True:

try:
msg = input("");

if not msg:
break

if 'end' in msg:
print ('...')
sock.close()
break

# Send data
msg = msg.encode(encoding="utf-8")
sent = sock.sendto(msg, tello_address)
except KeyboardInterrupt:
print ('\n . . .\n')
sock.close()
break
-------------------------------end-----------------------------------------
 

New Posts

Members online

Forum statistics

Threads
5,690
Messages
39,934
Members
17,023
Latest member
Repiv

New Posts