Fly in a Square and Triangle

Overview

  • Program a Parrot drone to fly along a square and a triangular route, by turning to specific heading angles and flying.

Objectives

  • Understand heading angles (0 to 360 degrees).

  • Combine turning blocks and motion blocks to turn the drone to the proper headings for flying in a square and triangle pattern.

  • Use repeat loops to fly in the same pattern using fewer code blocks.

  • Learn about the geometry concept "exterior angles".

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 Parrot Airborne Night as an example.

Turning a Complete Circle

  • Heading angle is the angle that the drone is facing or pointing.

  • The figure below shows heading angles at 90-degree increments. To turn a full circle, a drone has to turn its heading angle for a total of 360 degrees.

Fly in a Square Route

  • Use the block in Motion category, turn right by 90 degrees, to turn the heading angle of the drone by a specified angle.

  • The following blocks move the drone in a square:

Understanding the Components of a Square

  • Notice that the drone has made a complete square by turning 4 times, turning a total of 360 degrees to return to its original heading. The degrees to turn each time is 360 degrees divided by 4, which is 90 degrees.

Fly in a Square Route using repeat Loops

  • A repeat *n* times loop is used when the number of iterations can be calculated and known in advance. In our case for flying along a square route, the same blocks (move forward for 2 secs and turn right by 90 degrees) will be performed 4 identical times. Therefore, we can use the block repeat 4 times to replace the redundant blocks, and the program would look like this:

Program the Drone to Fly in a Triangle

  • To fly in a triangle, the drone has to turn 3 times to complete a full 360° turn. The number of degrees to turn each time is then 360° divided by 3 = 120° .

  • The program should look like this:

Challenges: Fly in a Pentagon (5 sides) and a Hexagon (6 sides)

  • Calculate the degrees to turn each time by dividing 360° by the number of the sides of the geometric shape. The following in an example program for the Pentagon:

  • In geometry, an angle of a polygon is formed by two sides of the polygon that share an endpoint. An exterior angle (or external angle) is an angle formed by one side of a simple polygon and a line extended from an adjacent side. This is the turning angles that you’ve been calculating throughout this lesson.

    • The sum of all exterior angles of a polygon is 360°, and each exterior angle of a regular polygon is 360° divided by the number of sides.