Snakes on a Drone: Python Takes to the Sky
Snakes on a Drone: Python Takes to the Sky
When it comes to the exploding drone market, Python could be making a massive push to become an integral part of this corner of IoT.
Join the DZone community and get the full member experience.Join For Free
Drones are making a push to become a major piece of hardware for solution providers. They're currently used for mapping, search and rescue, and even surveying and managing invasive species. When you combine their commercial applications with hobbyist enthusiasm, you get some pretty impressive numbers.
The FAA recently lifted their application procedure for running a drone business, a new permission that will go into effect this month. According to the FAA, drone sales will hit 2.5 million this year — on the way to 7 million by 2020. Considering the numbers, it isn't a huge surprise to see programmers test their skills on drones. It's an exciting new segment of technology and the possibilities are only limited by their imaginations (and FAA regulations).
It's heartening to see how many companies are taking open source approaches to programming drones. Without software telling them what to do, drones are just expensive paperweights, so it's promising for the field that it's starting with an open approach that will lower the barrier to entry. Also lowering the barrier to entry is that tons of developers are using Python to program their drones.
Python is an accessible dynamic language that's frequently taught in introductory CS courses at the university level, so it's well known in addition to being intuitive and versatile. The current hiring pool is filled with programmers who know Python, and it's becoming more popular year over year. In 2014, Python finally overtook Java as the most popular language for introductory CS courses. Eight of the top 10 CS departments in the USA teach Python in intro CS courses.
Elementary school students are getting in on the action, too — Python recently overtook French (!) as the most popular language taught at primary schools in the UK. Children, by a large margin, would prefer to learn Python over French, and six out of 10 of their parents would prefer that their children learn Python instead of French. Python is a high-level language, meaning that on drones, you'll find Python mostly running on top of the flight code via APIs, but there are also applications that run on the aircraft itself to process data and control sensors.
By way of example, DroneKit from 3DR gives programmers an SDK and web API to build apps for drones. With it, you can develop apps that communicate directly with the flight controller. DroneKit for Python allows developers to run computer vision, path planning, and 3D modeling tasks. It also supports the development of ground control for laptops. The Python API communicates with drones, giving the developer programmatic access to the drone's telemetry, state, and parameter information. This access means that developers can manage the movement and operations of drones.
Python has the ability to seriously bolster the autopilot of drones by programming more intelligent vehicle behavior on top of the flight code. You can connect to a drone from a simple script, set state and telemetry information, direct it to a specific location, and automate a flight path. During development, you can run it on a laptop with a simulated vehicle reacting to your code on the same machine, but in flight, it's mostly used to communicate via the companion computer on the drone.
DIY Drones highlights some exciting Python use cases. Python is being used to control the altitude of drones. This code relays the above ground level and allows you to hold the drone, hovering in place, at a predetermined height above the ground. There's also an example of real-time object tracking with Python and OpenCV, but the most impressive result is probably the complete instrument panel that's written in Python. This instrument panel turns sensor information into graphical feedback, featuring visual components like a false horizon.
Python's famous for its abilities as a lightweight, fast, dynamic language, which makes it the ideal language for rapid testing and prototyping. Being able to test and iterate quickly is especially important for drones because the technology is still in its early stages and is pretty heavily regulated in the USA. The last thing drone operators want is a high-profile crash when the technology is still getting off the ground (excuse the pun). The FAA seems to be employing a slow-and-steady method to decreasing drone flight regulations, and any disasters would threaten to halt the progress commercial operators have made.
Solid testing procedures, then, are paramount for commercial drone developers and operators. Testing, receiving feedback, rapidly iterating and re-testing, and so on, is best done with a lightweight, interpreted language like Python that allows for easy revision. This approach to development is especially important with technologies that are driven by user interface requirements, which is a big part of drone use.
Because so much drone code is open source, and drones present a possibility of physical harm to bystanders, it might be worth taking a look at some companies that provide enterprise-grade support to open source languages. Drone programmers have a great, nascent community, but help isn't always there for the questions you have. Some companies spend their time testing, tuning, and troubleshooting across an array of hardware, configurations, and applications before they add new code to their open source subscription products, so it might be worth taking a look at the options and mitigating some of the risks you could be dealing with.
Opinions expressed by DZone contributors are their own.