Snap Lesson 12: Gyro
In this lesson we will learn about how to receive the gyro angle from the CoDrone

Request Attitude Yaw

  • Requests the CoDrone to send back the direction the CoDrone is facing
  • Gives an angle from 0-359
The Request Attitude Yaw block will return the direction that the CoDrone is facing by using a gyro. Think of it as a compass, it tells you which way you are going. 0 is straight forward, 90 is to the right, 180 is backwards, and 270 is to the left.

 

We can use if statements to set the LED color according to the angle the CoDrone is facing. If it is between 0 and 90 degrees, we will set the LEDs to blue. Then if it is between 90 and 180 degrees, we will set them to Red. If it is between 180 and 270 degree, we will set the LEDs to yellow. Finally if the gyro is larger than 270 we will set the LEDs to green.

 

 

Try this out. You can either manually move your CoDrone to see the colors change, or add this to an existing code and see it change as the CoDrone flies.

Note how we used the variable gyro to store the CoDrone’s ATTITUDE_YAW value. We did this so that every time you check to see which way the CoDrone is flying we do not need to ask the CoDrone again for the value. This saves time as we are not able to instantly get this value from the CoDrone.

 

Activity: Gyro

The challenge is to have the CoDrone takeoff and travel in the same direction no matter where it starts from.

Challenge Rules:

  1. The CoDrone will takeoff, turn towards the proper direction, and then fly forward.
  2. You may simply divide it into 4 sections (for example, 0 to 90, 90 to 180, 180 to 270, 270 to 360), have one of them be a direction where you do not turn, and the other three turn.
  3. It does not need to face a perfect direction, but try to make it face the section that does not turn.

Hint:

The code we just made already divides the angles into 4 sections and does something different in each one.