Drone programming with GPT for dummies — episode 1
Now, in the AI era, it’s time to start again — GPT will be my programmer buddy. But will it work? Let’s try!
I am not a programmer.
Two years ago, I bought a Tello drone to learn how to code in Python and have fun at the same time. Just as you probably suspect, after two weeks, the drone goes to the basement.
Now, in the AI era, it’s time to start again — GPT will be my programmer buddy. But will it work? Let’s try!
First — why DJI Tello drone?
Because this drone has an open SDK — we can download the appropriate library and write commands in Python to control the drone by WI-FI. And this machine isn’t expensive — something around 100$
This was pros, now cons:
The battery works max 15 minutes, and the charging needs 30 minutes. You can buy an additional battery, but it costs 1/4 of the drone price.
The camera has poor quality.
Very short range.
Very short WIFI connection time on standby
So, it’s good for learning but not for nice video shooting on trips
Part 1 — Create my AI buddy
I assumed that I would need constant access to the direct Tello code file for efficient work on the Tello code. Of course, I could create an online GPT assistant on the Open AI website, but I won’t upload the code files again and again. At the same time, I wanted to use tools like GitHub Copilot; my ambition was to create my personal GPT agent.
I assumed that my first structure would be:
GPT agent in Python using API to connect with model
GPT agent in the same location as Tello code
GPT agent in the same location as the basic instruction file
GPT agent automatically retrieves information from the instruction file and Tello code file to generate an answer
Whole communication works only in PyCharm output for now
But after that, I needed to program in Python my GPT agent, so I used online GPT for this task. I get short code, and this code was short and looks easy — but it didn’t work.
I spent a lot of time trying to resolve the problem. I followed GPT instructions, reinstalled Python on my Mac, and updated Open AI libraries in PyCharm for nothing.
In the first step of my work, where GPT was supposed to be my programer agent, I found his limitations.
Open AI changes of the way API connection with GPT was made in November, but GTP was trained on data until July 2023. So, GPT didn’t know how to connect by API in the new way. And he didn’t know about his should know.
So, 1:0 for human
I found the actual script online, but I needed to make some changes to it: I needed to retrieve information from other files to provide precise GPT agent answers. Surprisingly, when I asked to chat about modifying the new script, which he didn’t know, he did it properly:
import os
from openai import OpenAI
def load_file_content(file_path):
with open(file_path, 'r') as file:
return file.read().strip()
api_key_file = "openaiapikey.txt"
context_file = "context.txt"
additional_files = ["tello_code.py"]
api_key = load_file_content(api_key_file)
context = load_file_content(context_file)
additional_contents = [load_file_content(file) for file in additional_files]
client = OpenAI(api_key=api_key)
while True:
question = input("Ask me anything (or type 'exit' to end the conversation): ")
if question.lower() == 'exit':
break
full_context = f"{context}\\n{additional_contents}\\n"
full_prompt = f"{full_context}\\n{question}"
response = client.chat.completions.create(
messages=[
{"role": "system", "content": "You are a helpful assistant that provides information."},
{"role": "user", "content": full_prompt}
],
model="gpt-3.5-turbo",
temperature=0,
max_tokens=1024,
n=1,
stop=None
)
if response.choices:
assistant_response = response.choices[0].message.content
print("Assistant:", assistant_response)
else:
print("No response.")
The next step was to create a list of instructions for my GPT agent to save in an instruction text file. I used GPT online for this task, too — my requirement was my model should be a Python programmer with knowledge of Tello SDK. ChatGPT clarified this expectation like that:
Project Name:
Programming the Tello Drone in PythonProject Goal:
Develop software to control the Tello drone using Python. Utilize Tello SDK and relevant Python libraries for controlling and interacting with the drone. Integrate with the OpenAI API to enhance drone functionalities and intelligence.GPT Assistant Responsibilities:
Python Programming Support:
Assisting in writing, debugging, and optimizing Python code. Advising on best programming practices and efficient use of resources.Knowledge of Tello SDK:
Understanding the functions and capabilities of the Tello SDK. Advising on the use of SDK for controlling and monitoring the drone.Python Libraries for Drone Control:
Knowledge and recommendation of suitable Python libraries for drone programming. Assisting in integrating these libraries with the existing code.Integration with OpenAI API:
Supporting the integration of Python code with the OpenAI API. Advising on using AI capabilities to expand the drone’s functionalities.Expected Skills of the GPT Assistant:
Advanced knowledge of Python and programming experience. Understanding of drone control specifics and knowledge of Tello SDK. Experience with API work, especially with OpenAI. Ability to solve problems quickly and think creatively.
And it works!
My new GPT agent connected by API and generated the first code to connect with the Tello drone.
Without programming knowledge (maybe 2%), just by talking with chatGPT (with one general problem at the start ;) )
Full time spent for part 1–2h But without actualization problem, it should be 30 minutes
Sounds interesting? Are you waiting for the next parts?
❤️ Like
💬 Comment
🔔 Subscribe
#GPT #python #drone #programming #GPT assistant #DJI #Tello #openAI #openAI API #AI #AI programming


