Pilot a Drone using Motion Sensors

Overview

  • Write a program to use the motion sensors in your phone and tablet to pilot a drone. For example, program the drone to fly right when the iPad is tilted right, fly forward when tilted forward, etc. When the iPad is shaken, the drone can perform a flip in mid air!

Objectives

  • Use motion sensors in smartphones and tablets to sense motion events (tilt and shake) to pilot a drone.

  • Understand the programming concept of "event-driven programming".

Event-driven Programming and Event Blocks

  • Event-driven programming is a computer science concept in which the flow of a program is determined by events such as sensor input, user actions (like touching the screen or tilting the device), and messages from other programs.

  • It is the dominant paradigm generally used in modern application like graphical user interfaces (GUI) and web-pages that performing certain actions in response to user input.

  • A simple way to think of it is "When something happens, do something". For example, "When it rains, open your umbrella."

Steps

Create a Drone Project

  • Create a new drone project by tapping + New Project via "MY PROJECTS". Choose the template that matches the model of your Parrot drone. Here we use the drone Night as an example, but you can connect to any of the drones that Tickle supports.

Fly a Drone Forward using Motion Sensors

  • Under the Events category, add the motion sensing event block When iPad is tilted forward like the following:

  • Let's start flying by tapping the play button. You will discover that if you tilt the iPad forward, the drone will move forward for 2 seconds. Otherwise it will hover at its current position. You can land the drone by tapping the red Stop button.

Use Motion Sensors to Fly the Drone in Different Directions

  • To pilot the drone to fly in all four directions, add a When … tilted … event block for each direction. Also, add a When … Shaked … event block to flip the drone!