program drone using Python

How to program a drone using Python

If you’re using the sticks of a remote controller to tell your drone where to go, is it really autonomous? And isn’t autonomous the real definition of a drone? To actually control your drone in its true form – that is, enabling it to fly autonomously without you telling it where to go in real-time — then you’ll have to pre-program its flight. And while that’s easier said than done, it’s not actually that hard to program a drone using Python.

DIY drone-making whiz Caleb Berquist is an engineer by day, but he has an awesome side hustle that can help everyone out. He created Drone Dojo, a site that features how-to, online drone classes ranging from free instructional videos, lengthy text guides and full, multi-hour long virtual courses.

And yes, Berquist put out this great, free guide to “How to Control a Drone with Python.” Berquist is the expert so I’ll let you click that link and read his guide, but I won’t completely leave you hanging. Before you leave for Berquist’s excellent guide, here are some basics you’ll need to know:

What you need to program a drone using Python

A computer (and in turn, a drone) needs hardware, firmware (code that commands the hardware) and software to function. If you’re programming a drone, we’ll assuming you already have the hardware ready to go (those are the propellers, motors, batteries, etc). That said, you don’t necessarily need hardware on hand if you simply want to learn how to program a drone using Python — but don’t need to put the results to the test IRL. Simply use a simulated MAVLink quadcopter to test it virtually. Or, if you do want to put it to the test IRL, you can also build your own drone (and hey, check out Berquist’s guide to how to build a Raspberry Pi drone, which can help you make that happen).

No matter what you choose, you will need the firmware and software. Here’s what you need to know:

Firmware: Ardupilot

Ardupilot is one of the best ways to command a drone’s hardware. It’s capable of sending approximately 400 commands per second to the drone’s motors.

ArduPilot is very widely supported by many of the most popular flight control boards including Pixhawk and Cube-based drones.

Check out DroneDojo’s video guide to ArduPilot here:

Software: Dronekit python

Berquist recommends you use Dronekit python, an open-source python library that provides high level functions such as commanding drone movement or checking vehicle status. Learn more about that here:

And together Dronekit Python and ArduPilot  can communicate using what’s called MAVLink (which Berquist alludes to in the video above). That’s what you’ll need to write your first Dronekit Python Script, so you can command your drone to do everything you want — takeoff, land and everything in between.

All of those videos are free snippets from Drone Dojo’s longer online course on drone programming with Python. It costs $197, but goes much deeper into what you can learn from a couple videos (this course is 3.5 hours long).

The course is designed for everyone from an entrepreneur working up an epic drone delivery project, to a student looking to learn about engineering in a fun, applicable way (you will need a basic coding background – think basic linux command line and python knowledge).

You can register for Drone Dojo’s self-paced online drone programming with Python course here.

Leave a Reply