Snap Lesson 13: Gyro Turn
In this lesson we will learn about how to control the CoDrone’s turning better
For this program we are going to make the CoDrone turn towards 90 degrees. We are going to give it a small target range as it take a little bit to receive the gyro angle which makes it difficult to arrive at an exact angle. We will use a repeat until loop to have it turn until we get to the right angle.
Again we will save the ATTITUDE_YAW to a variable to make it so we only have to read the gyro sensor once. We will add in the code to make the CoDrone turn next inside of the repeat until loop. Once the CoDrone is between 85 and 95 degrees the CoDrone can stop turning and will exit the loop.
For making the CoDrone turn we will check the direction that it is facing and turn towards 90 degrees. By using this if statement we can make the gyro turns more efficient since if we were only a few degrees off, but our turn direction was the opposite way, the CoDrone would have to almost make a full circle to face the right direction. After the repeat until loop ends we will set the yaw to 0 so that the CoDrone will stop spinning.
Now adding in a takeoff and landing commands we have a full code. No matter which way the CoDrone faces it will turn towards 90 degrees.
Activity: Gyro Turning
The challenge is to have the CoDrone takeoff and turn towards the 4 main directions (0, 90, 180, 270)
Challenge Rules:
- The CoDrone will takeoff, turn towards the next direction
- Once it faces the proper direction have it wait 3 seconds
- Then turn to the next direction until all 4 directions have been faced