How to control your 🚁 drone using #ChatGPT

El Bruno - Aug 2 '23 - - Dev Community

Coding4Fun Drone 🚁 posts

  1. Introduction to DJI Tello
  2. Analyzing Python samples code from the official SDK
  3. Drone Hello World ! Takeoff and land
  4. Tips to connect to Drone WiFi in Windows 10
  5. Reading data from the Drone, Get battery level
  6. Sample for real time data read, Get Accelerometer data
  7. How the drone camera video feed works, using FFMPEG to display the feed
  8. Open the drone camera video feed using OpenCV
  9. Performance and OpenCV, measuring FPS
  10. Detect faces using the drone camera
  11. Detect a banana and land!
  12. Flip when a face is detected!
  13. How to connect to Internet and to the drone at the same time
  14. Video with real time demo using the drone, Python and Visual Studio Code
  15. Using custom vision to analyze drone camera images
  16. Drawing frames for detected objects in real-time in the drone camera feed
  17. Save detected objects to local files, images and JSON results
  18. Save the Drone camera feed into a local video file
  19. Overlay images into the Drone camera feed using OpenCV
  20. Instance Segmentation from the Drone Camera using OpenCV, TensorFlow and PixelLib
  21. Create a 3×3 grid on the camera frame to detect objects and calculate positions in the grid
  22. Create an Azure IoT Central Device Template to work with drone information
  23. Create a Drone Device for Azure IoT Central
  24. Send drone information to Azure IoT Central
  25. Using GPT models to generate code to control the drone. Using ChatGPT

Hi!

I’ve been doing live demos of how to use Azure OpenAI Services or OpenAI APIs to generate code to control the drone, so I think I may write about it to have it public for future references.

So, using the base code to send and read drone information, we can create a simple prompt like this one:


Use this python code as reference 

[CODE START]
# display battery level
sendReadCommand('battery?')
print(f'Battery: {battery} %')

# take off
sendCommand("takeoff") 

# flip the drone left
sendCommand("flip l") 

# move drone up 5 cms
sendCommand("up 5") 

# move drone left 5 cms
sendCommand("left 5") 

# rotate drone clock wise 90 degrees
sendCommand("cw 90") 

# land the drone
sendCommand("land") 

[CODE END]

Generate code to takeoff the drone, flip right, move down 30 centimeters and land

Enter fullscreen mode Exit fullscreen mode

If we are working with GPT models, we can test this in ChatGPT.

GPT model completion is incredibly good. It generates the necessary commands, and it also infers new commands like flip right or move in a different direction.

If you have seen my demos, you remember me complaining about UDP. And knowing that this drone is a toy plus the UDP challenge, it may make sense to add a 5 second delay between commands.

ChatGPT updates the generated code, adding a time.sleep(5) instruction after each command.

So far, so good. We can copy the generated code and make our drone fly.

In the next post we will automate this code generation using Azure OpenAI Services or OpenAI APIs.

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player