Beginners Series Lesson 3: Flight Commands
Here we will learn how to get the CoDrone off the ground and into the skies

Scene_07 [1]

Summary

Now that we know how to setup and pair our drone, we can begin programming our very first flight code.  Here we will learn the basics of programming in Arduino and how code works. We will also learn how to use the TakeOff and Landing commands, as well as Arduino’s  delay()  function.

 

Making your CoDrone Move

We will begin almost all of our CoDrone programs with the setup code, so get used to seeing this:

This loads the CoDrone library, begins our connection to the bluetooth module and connects to a nearby CoDrone.

For this lesson, we will work entirely inside of void setup().

Void Setup and Void Loop

Both void setup()  and void loop()  are built-in functions within the Arduino IDE.  Any sketch that you write must include both of these functions, even if you don’t write anything inside of them.

What’s the difference?
The practical difference between setup() and loop() is that setup() will run only once while loop() will repeat infinitely.  It’s useful to put your setup code (things that only need to happen once) in your setup().  The rest of your code (things that happen a lot) will go into loop().

Learn More: Setup(), Loop(), Functions

The first thing we want to do is utilize the CoDrone library’s CoDrone.FlightEvent()   function. This is a powerful function that takes a command as in input and performs pre-coded maneuvers.

CoDrone.FlightEvent();

CoDrone.FlightEvent(event);

  • Sends the event to the CoDrone
  • Events are often short maneuvers such as TakeOff, Landing and Stop

In this case, we will use the command TakeOff:

It will startup the motors and bring the CoDrone to a hover just above the ground.

Once our CoDrone is in the air, we can use another function:

This will cause our CoDrone to land.  If we just put the two functions right after each other, our CoDrone will TakeOff and Land in a split second and we probably won’t even notice it happening.  Sending commands too quickly to the CoDrone can also result in some commands being skipped.

TakeOff Landing

To prevent this, we use the delay() function.

delay();

delay(milliseconds);

  • delays the code for the amount of milliseconds indicated
  • The code will be frozen at the current line for the entirety of the delay

In our example we use  delay(2000) , which means our code will wait for 2 seconds (2000 milliseconds) before moving on to the next line.  This gives the TakeOff maneuver 2 seconds to complete before the CoDrone lands.  We’ll put this between our TakeOff and Landing:

TakeOff Landing Delay

We are now able to make our CoDrone take off and land. Let’s put everything together:

Activity: Push-Ups

Try to make your CoDrone takeoff and land 3 times in row with one code.

Rules:

  1. The CoDrone must leave the ground completely during TakeOff
  2. The CoDrone must have all four arms on the ground during Landing
  3. There is no height requirement for how high the CoDrone flies.

See who can do the most CoDrone push-ups in 10 seconds!

In Flight Part II, we will learn how to make our CoDrone move using Throttle, Yaw, Pitch and Roll.