Basic Gyro Programming


The gyro determines the direction that your robotic invention is facing. It is commonly used for navigation: the best uses for the gyro are to make accurate turns and return to its original position. In this tutorial, you'll learn about the gyro and print messages based on the detected angle.

Hardware Requirements

  • VEX IQ Brain
  • Gyro

Program

You can measure the direction the gyro is facing by printing out its current angle. Let's create a program that prints our the current angle of the gyro onto the VEX IQ brain.

Open the Modkit for VEX editor. Drag and drop a gyro and assign its port number. Make sure it matches that of the physical gyro.

Click on the 'Blocks' tab and make sure that you are editing the 'Brain'. Drag and drop code blocks to match the image below. The 'when START' block runs once each time your program runs. The 'forever' block repeatedly runs the code inside.

Download your program and run it on your physical VEX IQ brain. We've provided a graphic (see attachments at the bottom of this page) that you can use in order to test the gyro; simply print it out and place your gyro on top of the coordinate system.

While the program is running, rotate the gyro and see what values are printed on the screen of the VEX IQ brain.The angle tells you how much you have rotated it from its original position. Note: the 'original position' of the gyro is set each time you run the program on the brain. How does the angle change as you rotate the gyro?

Next, let's modify the program to perform a different action based on the measured angle. Drag and drop code blocks to match the image below. If the angle of the gyro is between 0 and 180 degrees, the message "turn right to return" will be printed on the VEX IQ brain. Otherwise, the message "turn left to return" will be displayed. Download your program and test it on your device.

While the program is running, rotate the gyro, and follow the messages printed out on the brain. Can you rotate the gyro back to its original position?‚Äč

In this tutorial, you learned about the gyro, printed out the angle it is facing, and printed messages based on the measured angle. There is so much more that you can do! Check out our other Getting Started guides.

Updated 28 months ago

What You'll Need