Drone Programming

Drone Programming

Cybersecurity First Principles in this lesson

Introduction

It seems like unmanned aircraft systems, more commonly called drones, are everywhere. You see them at sporting events, entertainment venues, they are used for search and rescue, to survey disaster damage, even by farmers and ranchers to check on crops and herds. We may even see them soon for package delivery. We also hear a lot about safety flying drones, we don’t want anyone to get hurt. But what about cybersecurity? Is that important with drones? Could someone get hurt from a hacked drone?

drone_title

Goals

Materials Required

Prerequisite lessons

Table of Contents

Before we begin - Safety First

The FAA has several rules for the operation of drones. The below rules apply to flying for fun or educational purposes, if you are flying the drone for work (to make money) then there are more stringent rules which must be followed

The drones we are using today are under .55 lbs and since we are flying indoors we do not have to worry about notifying airport authorities. If you use a different drone or fly outdoors you should check the FAA web site for any additional rules you should follow.

In addition to the above the below safety rules apply no matter what type of drone you are flying:

Step 1: Prepare drone for flight

Using the provided battery you will get about 7 or 8 minutes flight time on a charge. Having several batteries available will lengthen your operational time.

Battery

switch

Step 2: Start Swift Playgrounds on your iPad

Swift Playground

We will go through an abbreviated introduction to the commands in this lesson. The Parrot Education playground is a great resource for additional practice or as a stand-alone lesson.

Step 3: Create your first program

It’s time to create your first program. Select the Parrot Template playground. You will see your programming environment similar to the below.

template_playground

You will see the screen divided into two sections. The left or top half the screen (depending on the iPad orientation) is where you will write your code. At the top of this section you will see a name for the program you are working on as well as arrows to the left and right. This allows you to cycle through programs on this template. The right or bottom half is where you will see a simulation of the drone’s activity. The simulation is an example of the application of the First Principle of Abstraction. It’s a representation of the more complex drone’s actions.

You can enter code by using a keyboard or by selecting the various commands at the bottom of the screen and providing the proper parameters.

Let’s start with something simple, takeoff and land. Enter the commands into the code window using the keyboard or by selecting the commands from the bottom of the screen. Note that the commands are case sensitive.

takeOff()
wait(4)
Land

The commands are pretty self-explanatory.

Before we go farther let’s talk for a moment about some Cybersecurity First Principles which apply here. It requires many lines of code to make your drone take off and hover, maintaining stable flight. It’s checking multiple sensors and motor rotation. Those inputs change how power is applied to the motors. But all you did was issue the command takeOff(). This is an example of data hiding. As a programmer you are limited from accessing directly all the data and commands that are needed for the command takeOff() to work.

In general, the commands you use to control the drone, provide an example of resource encapsulation. The drone is an object, and there are only certain applicable operations, for example take off and land, which make sense for a drone. There are many actions which make up those commands but by hiding those from the user your make the drone operations safer. If you had direct access to the all the commands which made the drone operate there is a good chance you could cause some harm, either on purpose or by mistake. By encapsulating the resources, in this case the commands which comprise, takeOff() and land(), the user only has access to those commands which are applicable to the authorized operations. If a user weren’t limited by the resource encapsulation of the command takeOff() they could send commands to make half the drone take off and the other half land. This could cause damage to the drone. There are also some commands which won’t work under all conditions. For example you can’t do flips if the claw is attached as the drone’s flight could become unstable. You are also not allowed to take off if the battery is too low. Resource encapsulation ensures that only those operations of the object which are appropriate at the time are allowed. This is also a good example of the principle of simplicity. A user doesn’t need to know all the commands necessary to hover, they just tell the drone to take off.

Are there examples of how the principal of least privilege could be applied to drone operations?

Step 4: Connect your drone with your iPad

You will only need to do this step when first using your drone, or changing drones.

Connect_Drone

Select_Drone

Step 5: Run your code

We are finally ready to fly your drone with your first program.

Hopefully you have been treated to a brief aerial demonstration by your drone. If not check the code against the list above, pay attention to spelling and case.

Step 6: Expand your capabilities

Believe it or not you already know most of what you need to write longer and more complex programs for drone operations. There are several other commands you can use to perform different maneuvers. Use the below as a references and add them as needed to your drone program.

You can also create functions to group several commands and call them where needed. This is an example of the cybersecurity first principle of Modularity. Functions are the building blocks of larger programs and you can add, remove, and move around functions to change operations as needed.

You now have all the basics you need to program some complex drone operations. Good luck and have fun!

Postal Challenge

drone_challenge

Evaluation

Use kahoot to ask the following questions. Discuss any wrong answers to ensure all understant the material.

Additional Resources

For more information, investigate the following.

Acknowledgements

License

Nebraska GenCyber Creative Commons License
is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Overall content: Copyright (C) 2017-2018 Dr. Matthew L. Hale, Dr. Robin Gandhi, and Doug Rausch.

Lesson content: Copyright (C) Robin Gandhi 2017-2018. Creative Commons License
This lesson is licensed by the author under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.