Getting My Drone to Fly Autonomously with Code
I’ve built many kinds of AI agents for social media data gathering, but I’ve recently become interested in flying drones using AI. While building AI agents was rewarding, I found myself wanting to move beyond software and explore how AI could interact with the physical world. My interest sparked after reading about counter drones. What fascinated me was how these autonomous systems could navigate, identify, and intercept with minimal human intervention. As I researched further, I realized drones have countless applications, and many industries are only beginning to explore what autonomous drones can do. So I decided to try building one of my own.
I had no idea where to begin, but I figured there must be an open-source platform for writing code for autonomous drones. After a few Google searches, I identified ArduPilot and PX4 as two of the leading platforms for drone development. ArduPilot seemed easier to get started with, but its GPLv3 license requires companies distributing modified versions to make the relevant source code available. PX4, on the other hand, uses the more permissive BSD 3-Clause license, which is better suited to proprietary commercial development. I wanted to stay aligned with industry practices, so I zeroed in on PX4.
With that decision made, I started looking for a drone that would work well with PX4. After comparing many different frame options, I chose the Holybro X500 V2 ARF drone kit because it’s well documented, officially supported by PX4, and leaves plenty of room for future expansion. The next step was finding the right flight hardware (flight controller, GPS module, etc.). This was quite a tedious process, and if you want to see all the parts I considered or build a drone of your own, you can check out that post here: https://www.linkedin.com/posts/arya-aggarwal-906789283_building-my-holybro-x500-v2-every-part-share-7483796222412103680-DSZK/.
Once I had built the drone, I began figuring out how I could fly it autonomously using code. I was about to start coding when I realized I still needed a way to test it. Of course, I could have just tried it directly on the drone, but I had spent around $1,000 building it and wasn’t thrilled about risking a crash. So I started looking for ways to simulate flying the drone with code, which led me to QGroundControl. QGroundControl is a drone planning and simulation program that can run programs with realistic drone behavior and physics.
Now that I had testing covered, I wrote my first program, which simply armed the drone, took off to around 3 feet, hovered for 10 seconds, and then landed. This was just to ensure the simulator was running properly and that there would be no surprises when moving from the simulator to the actual drone.
Testing and programming this script taught me some important lessons. First, I learned how to use QGroundControl to simulate running code, how to set it up, and how to read crucial flight data like speed and altitude. I also learned how to run programs on my drone using my telemetry radio and computer, so I don’t need an onboard companion computer for development.

