Snap Lesson 3: Flight Movements
In this lesson, we learn how to control the CoDrone using the movement commands Throttle, Yaw, Pitch and Roll.

Summary

Our next step in programming our CoDrone is understanding how a drone flies. This lesson will explain throttle, pitch, yaw, and roll and how we use these to fly.  We’ll use this knowledge to improve our flight code.

Throttle, Yaw, Pitch and Roll

To keep track of movement in 3D space we use the following terms:

Throttle controls the vertical up and down motion of the drone.  Positive throttle will make the drone fly higher and negative throttle will make the drone fly lower.

Yaw is the left and right rotation of the drone.  Positive yaw will make the drone turn to the right and negative yaw will make the drone turn to the left.

Pitch is the forward and backward tilt of the drone.  positive pitch will make the drone tilt and move forward and negative pitch will make the drone tilt and move backwards.

Roll is the side to side tilt of the drone.  Positive roll will make the drone tilt to the right and negative roll will make the drone tilt to the left.

Activity: Blind Drone

Blindfold a friend and try to get him to walk around obstacles using only drone terminology.  Make sure you clear the room of anything dangerous first:

• Plus Pitch – Move Forward
• Minus Pitch – Move Backward
• Plus Yaw – Turn Right
• Minus Yaw – Turn Left
• Plus Roll – Move Left
• Minus Roll – Move Right
• Plus Throttle – Stand Taller
• Minus Throttle – Crouch

Don’t let them run into anything!

Making the CoDrone Move

There are two steps to making our CoDrone fly:

1. Movement Commands

Movement commands are the terms we just learned above: yaw, pitch, roll, and throttle.  We can use these blocks to set the values for each movement direction:

The value for these numbers can range from -100 to 100.  For example, if we wanted to set throttle to 70, we would have:

This saves the throttle as 70, but doesn’t send the movement to our CoDrone just yet.

When we want to send all our movement values to the CoDrone, we use the  block, that one sends the code to the CoDrone

Sending Command

• Send the saved yaw, pitch, roll, and throttle commands to the CoDrone.

This will send all the saved movement values to the CoDrone.

For example, if I wanted to make my CoDrone fly upwards at a speed of 70, I would use these blocks:

This will send a positive throttle (70) to the CoDrone, making it fly upwards.

You can also set multiple directions at once.  If I wanted my CoDrone to fly to the right and backwards at the same time, I would us the following blocks:

This will send a positive roll, making it fly to the right, and a negative pitch, making it fly backwards.

The last thing we need to remember is to give our movements time to execute.  To control how long it moves for we will use the wait 1 sec block, this block makes the program wait for however many seconds you tell it to. Then once the time is up we can have it go on to the next movement. So if we wanted the CoDrone to fly up for 2 seconds, then turn left for 1.5 seconds, and finally land the code would look like this:

There are a few thing to notice about this code. Firstly note that we are using the flight events from the last lesson, these allow us to take off and to land. Secondly we need to set the movement values back to 0 if we do not want to continue moving in that direction. So for the second movement we set throttle back to 0 so that we would not continue to fly upwards.

Now try making your own CoDrone code!

Activity: Move around

Try to complete all of these challenges.

Challenges:

1. Have the CoDrone fly up into the air and make a complete turn and face the same direction as it started
2. Have the CoDrone fly up into the air and move forward about a foot and then move back again to land on the same place as it took off from
3. Have the CoDrone fly up into the air and move left about a foot and then move back again to land on the same place as it took off from