Jaz
December 14, 2020, 8:44pm
1
Hi all just been thrown a nice curve ball.
I have been asked to use tello edu to teach python coding.
What is the bare minimum code I need for python to connect to a drone and get it to take off, then land.
I can then add bits and pieces later on into between and then talk about variables and loops.
I had a quick look at the Python code lessons but got a bit confused on what to take out and ended up spending ages trying to debug my Frankenstein code
mHasan
December 14, 2020, 10:21pm
2
Did you go through DroneBlocks curriculum yet. I was able to get started with Python coding using thr curriculum.
Jaz
December 14, 2020, 10:35pm
3
Yep I went through the programme and got drones working just want to strip out everything and just want drone to connect take off and land.
I edited the code to what I thought was right but got lots of errors, when correct others appeared and got frustrating
mHasan
December 14, 2020, 10:59pm
4
Oh ok. Can you put your code here. Let’s have a look at it.
Jaz
December 15, 2020, 12:14am
5
import socket
import threading
import time
IP and port of Tello
tello_address = (‘192.168.10.1’, 8889)
IP and port of local computer
local_address = (’’, 9000)
Create a UDP connection that we’ll send the command to
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Bind to the local address and port
sock.bind(local_address)
Send the message to Tello and allow for a delay in seconds
def send(message, delay):
Try to send the message otherwise print the exception
try:
sock.sendto(message.encode(), tello_address)
print("Sending message: " + message)
except Exception as e:
print("Error sending: " + str(e))
Delay for a user-defined period of time
time.sleep(delay)
Receive the message from Tello
def receive():
Continuously loop and listen for incoming messages
while True:
Try to receive the message otherwise print the exception
try:
response, ip_address = sock.recvfrom(128)
print("Received message: " + response.decode(encoding=‘utf-8’))
except Exception as e:
If there’s an error close the socket and break out of the loop
sock.close()
print("Error receiving: " + str(e))
break
Create and start a listening thread that runs in the background
This utilizes our receive functions and will continuously monitor for incoming messages
receiveThread = threading.Thread(target=receive)
receiveThread.daemon = True
receiveThread.start()
Put Tello into command mode
send(“command”, 3)
Send the takeoff command
send(“takeoff”, 5)
Land
send(“land”, 5)
Print message
print(“Mission completed successfully!”)
Close the socket
sock.close()
Jaz
December 16, 2020, 1:23pm
6
Dont worry I have sorted it ready to rock and roll
Would you mind sharing your final solution so that others can benefit? Interested in seeing what you came up with!
Jaz
December 17, 2020, 5:17pm
8
It was the same code as above I was messing around with spaces and tabs when not needed.
Can see it running here
https://youtu.be/urVWB3TOQs8
1 Like
Bravo! I just learned about QPython from your video. We have been using Pythonista for iOS. Thanks for sharing.
Jaz
December 18, 2020, 4:32pm
10
The power of sharing it is a great little app and for me it is a game changer and for the kids I teach. I wonder if we can get it to swarm which is my final aim
Jaz
December 18, 2020, 4:38pm
11
I went for the OL version as was aimed more at learning and the 3L was more advanced. Always use Python 3 not python 2. I was sitting on the bus coding on phone love it
We’ll call you the “Mobile Coder”
Just FYI we have some swarm sample code here:
# This example script demonstrates how to use Python to fly Tello in a box mission
# This script is part of our course on Tello drone programming
# https://learn.droneblocks.io/p/tello-drone-programming-with-python/
# Import the necessary modules
import socket
import threading
import time
# IP and port of Tello
tello1_address = ('192.168.0.100', 8889)
tello2_address = ('192.168.0.101', 8889)
# IP and port of local computer
local1_address = ('', 9010)
local2_address = ('', 9011)
# Create a UDP connection that we'll send the command to
sock1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
This file has been truncated. show original
There will be a few challenges to get this set up but happy to assist. If you’d like to chat about it please crate a new post so we keep things clean. Thanks.
Jaz
December 19, 2020, 11:37am
13
Lol thanks I will wear that badge with pride. My aim is to have mobile as my default option to teach as all can be easily transferred to PCs and Laptops.
Will tinker with my nemesis AKA swarming to get this working on mobile.
May the force be with you, always