## Gyro Turns

We will use the Request block again, this time to read the sensors and try to control the CoDrone using them. We will specifically be using the gyro sensors (labeled as ATTITUDE in the drop down menu). These sensors measure the angle of the CoDrone. We will be using the ATTITUDE YAW to find out which direction the CoDrone is facing. Straight forward will be 0, right is 90, backwards is 180, and left is 270. We will use the gyro to turn to 90 degrees. Note that the gyro does not always start facing 0 degrees, so we will not be turning by 90 degrees, but to 90 degrees. We will start by taking off. Then we will make a variable to save the angle of the CoDrone. This way we can see what the angle value is in the top right corner of the RokitBrick program and know how good of a turn it is making. Then we will use a repeat until loop to spin until we get to 90 degrees. First we will put in the insides of our loop, and then put the condition in afterwards. We need to have it turn and also update our Angle variable to the newest angle. Now we need to make the condition. We want it to turn until we are at 90 degrees. However it will be hard to get it to be at exactly 90 degrees since it takes a short amount of time for the angle to be read, meaning that we will be turning for a short time and then checking the angle. So it  will not work to see if angle is equal to 90, since it is unlikely that we will time it just right for Angle to be 90. Our next options are greater than or less than. However with both of these we have a large issue, if we use less than 90, then what happens when we start at 50. We do not turn. Same for if we started at 176 and used greater than 90. Also if we use greater than when we start at 50, we might not stop turning until we are at 115 degrees, so this is not what we want either. What we will do is set a range that it can stop in. So it must be more than x and less than y. This will have it turn until it is between 85 and 95 degrees. Then we just need to add in a landing at the end and try it out. Challenge:

You may have notice that sometimes the CoDrone will spin past the desired angle and have to loop around again to get the desired angle. One way to fix this is to have it check if it has turned past the desired angle and then change the direction to move back towards it. Reprogram it so that if it turns past the wanted angle it will spin the other direction.

Hint: If the angle is greater than 90, we want to spin the other direction.