Yes, yes, I keep promising to write about Integrated Motor Encoders. However, one of the other coaches on the VEX World Coaches Association Facebook group and I got started chatting about the VEX gyro sensor, and it had me collate all of the information I have about the gyro in one place. So I thought I’d dump it all here now. (Original post written March 2017; updated Oct. 2017, Feb. 2018, July 2018).

This post is aimed at a person who wants some practical advice on understanding how to install it, what the output means, and the testing needed to make it of any use to your robot. It does not address the specifics of how things inside the component work in order to produce the output read by the cortex.

I will interrupt myself here to address readers who are using easyC. You may want to skip this sensor. easyC and VEX would like you to believe that it works in easyC, and technically it does, but we found it unusable, and probably spent ~20 hours coming to that conclusion. The communication of information from the sensor to the cortex was so laughably slow as to be really unbelievable. And since there is no documentation or support for this component, you’re basically on your own. I tried to ask users on the VEX forum, but there were no other easyC users to be found; the RobotC users were able to use it effectively, however. We are switching to RobotC for the coming year, for a variety of reasons.

Gyro sensorThe Component

This sensor is not like the other VEX sensors, which are all color-coordinated in red plastic, and friendly-looking. Think of this as a bare component that VEX commandeered and is making use of. The official name for this sensor is the VEX Yaw Rate Gyroscope Sensor. It also differs from other VEX sensors in that there is no PDF instruction sheet—or any instructions on how to use it—on the product page at all. What is linked on the product page is the STM Microelectronics LY3100ALH Datasheet, which is, seriously, only useful if you were taking one of these apart or soldering it on to something else. Otherwise it, is 99.99% useless; gotta say I’m pretty disappointed in VEX on this one. They’ve had plenty of time to put together a VEX instruction sheet, at least on how to install it.

Yaw is one of 3 movement axes in aviation: pitch (airplane’s nose going up & down), roll (airplane tipping its wings side-to-side), and yaw (airplane’s nose moving left or right/changing heading). If you’re looking for a sensor that measures something other than “yaw”, this is probably not the device for you.

This is a long post, so here’s a table of contents:

Installation

First, the top of the gyro is the side with the pins sticking out of it, and the 2 big holes are for screwing it onto your robot somewhere (more on that below). Connect this sensor to one of your analog ports with the usual 3-wire extension cable; the black wire of the cable gets plugged into the pin on the gyro that has a small “B” printed next to it. If you plug this in backward, nothing will happen—no data will be returned from the sensor. There is a teeny light on the component that lets you know if it is getting power (labeled “PWR”, as you can see in the photo above).

From here, in the most basic sense, it’s like any other sensor you have; you initialize the sensor, read information from the analog port, assign it to a variable, and then do something based on what the reading is.

Mounting / Vibration

The gyro is sensitive to vibration, a lot. So lots of vibration will cause the gyro to start “drifting” in its returned value; a lot of vibration will cause a lot of drift. And so will a little vibration over a long period of time driving the robot.

The super-awesome jpearman from the VEX forum did a series of tests on the sensor, mounting it in different places and noting the effects. First it was mounted on standoffs attached to the robot’s frame, then he put some rubber couplers between the gyro and standoffs (acting as a cushion), which showed minor improvement. For the next test, he mounted the gyro on the highest part of the robot, away from the drive motors, and that showed significant improvement. See the full set of tests on the VEX forum post.

JPearman's Gyro Sensor Tests

jpearman’s gyro sensor test; you can see the gyro mounted on green rubber stoppers an standoffs. See all of his photos and tests on his gyro VEX Forum post.

The caveat is that his tests were run with his robot propped on a box, so that the gyro would not change its value as a result of driving it around, but would only vary from the effects of the vibration. However, he said, this could not be exactly extrapolated to a robot driving around and he could not speculate as to those effects. A coach replied to his post and reported that his team’s kids had a chassis-mounted gyro + mecanum wheels, and withoutspecial mounting, the drift was 20-50 degrees in 5 or 6 feet! They only added the rubber couplers under the gyro, and the drift was reduced to 3 degrees over the same distance. Seems like rubber couplers are a must-have when you buy one of these.

Another user suggested mounting the battery on top of rubber bumpers, attaching the gyro to a battery clip, and then clipping the gyro to the top side of the battery. The battery’s mass would itself reduce small vibrations.

What It Measures

The sensor outputs the degrees the robot has turned away from the “north pole” of where it was facing when you turned it on and started your program running. The value the sensor returns is in tenths of a degree. So if it turns 60 degrees, the sensor will read 600.

Sensor values can be negative! If you turn in one direction from your starting “north pole,” the sensor will give you a positive value; if you turn back to your starting point and keep going, the readings will be negative.

Orienting Itself: Gimme a Sec!

The robot needs to sit perfectly still for several seconds when the gyro is started in order for it to calibrate itself to the big wide world. In competition programs, you do this gyro-initializing step in the Initialize (easyC) or pre-autonomous (RobotC) portion of the program, so it does this “I need to sit still so don’t bother me” part when the team is standing around doing nothing anyway.

Scaling

Every device is a little different, and none of them will return 600 exactly when you turn it 60 degrees. So you must figure out the scaling factor for your component before you can really use this thing. The good news is that the scaling factor is linear, so you just have to figure out one number; it’s not some crazy logarithmic or geometric thing you have to figure out.

  1. In all of your testing and when you’re creating your programs, use the LCD screen (or the debugger window in RobotC) every step of the way and print out as much data as you can while you’re figuring out how to use this sensor. You will really be happier for it.
  2. Watch the video below. This is one of this year’s Online Challenge videos, all about the gyro! It’s only 3 minutes long, so watch the whole thing, because it’s full of incredibly useful stuff. For scaling your component, pay close attention at 2:20 to see the device that this team created to test their sensor; it’s pretty cool, and not that complex. (They also demonstrate the effects of vibration on the sensor at this time.)

We had a less-sophisticated way of figuring the scaling factor on our team, since it was attached to the robot at the time; you can consider it a more “quick and dirty” method for a Phase 1-type calibration.

  • You’ll need a very basic test program on your robot that clears any old sensor data, gets the analog data from the sensor, and prints it to the LCD screen.
  • Place your robot on the competition field and line up a corner of the chassis as closely as you can with the corner of a field tile.
  • Turn on the robot and let it sit perfectly still for 5 seconds. The LCD should read 0.
  • Pick up the robot and turn it exactly 90 degrees so that another corner of the robot is lined up with the field tiles. Write down the number shown on the LCD.
  • Do this 3 more times for 180 degrees, 270 degrees, and back to 360 degrees where you started.
    • In RobotC, the sensor value will “loop around” to 0 when you get to 360 degrees; in easyC it keeps counting up forever.
    • In RobotC you can set a special variable called SensorFullCount to something other than 3600 if, based on your testing you find that it should really “loop around” to 0 when it gets to, say, 3724 instead of 3600. If you do not sest this variable explicitly, then it will use 3600.

To calculate your scaling factor:

  • Divide your first reading by 10 and then by 90 (since the reading is in tenths of a degree)
  • Divide the second by 10 and 180
  • Divide the third by 10 and 270
  • Divide the 4th by 10 and 360; if the sensor did “loop around” to 0, add 3600 to the number on the LCD screen, then do the division.

Hopefully these resulting numbers will:

  • all be reasonably close to 1.0; in our program we ended up with 0.94.
  • all be reasonably close to each other.

At this point, we took an average of our 4 scaling numbers to get the final factor of 0.94. Once you have a scaling factor, in your program, the degrees the robot has actually moved from its “north pole” is represented by the following:

degreesTurned = sensorValue / 10 * scalingFactor
(and then truncate or round this to the nearest whole number)

Limitations

According to the easyC help files, the sensor has a maximum rate of rotation between 80 and 300 degrees per second, so if you’re spinning like a Tasmanian devil, it will probably give you … misleading information.

Drift

As mentioned above, drift is the biggie. The team in the video above obviously found a solution to drift, because they were able to aim their turret at the NbN net throughout the match after lots of driving around. Step 1 of reducing drift is reducing vibration, as stated above. The other is time; this sensor will definitely be easier to use in autonomous for a limited number of movements than in driver control with multiple turns and lots of movement for 1:45.

You will need to first figure out what your drift IS, via testing and your trusty LCD screen (or RobotC debugger window). Line up your robot again to the corner of some field tiles & turn it on. Let it sit to orient itself; the LCD should read 0 (it will help if you have it display degreesTurned, unless you like thinking in terms or raw sensor output).

  • Turn the robot off and on in between each of the following tests so that the gyro completely resets to 0. After you turn it back on, remember to let it rest for a few seconds before driving it.
  • Drive around randomly, as in a match, for set periods of time, stop, and line the robot back up with the field tiles and check your value. How close to 0 is it?
  • Drive back & forth in a straight line for 30 seconds and see what your drift is now.
  • Spin slowly in place for 5 rotations. What is it now? How about 5 rotations in the other direction — is it the same? (For the love of God, I hope it is.)
  • Let the robot sit in one place without driving it at all for a minute or 2; what happens?
  • Do the above tests 5 times each; do you get about the same drift each time?

The point of all of this is that before you try to get really sophisticated with programming your sensor, you have to have a really, really good understanding of the values it is giving you, and how you need to interpret them. Doing these types of tests, and figuring out if you can compensate for the results programmatically or in the physical placement of the sensor will then tell you what you will be able to use this sensor for. If you can’t figure out a way to compensate for drift after 10 seconds of driving no matter what you do, then you might just want to plan on using it in autonomous mode. Be realistic.

There is hope; the last comment in this forum thread has this to say:

I am unsure what amount of drift others are experiencing, but I have had very good performances with very minimal (if any) drift with the gyroscopic sensor using the latest version (really, ever since version 3.x was released) of RobotC. Be sure to calibrate the sensor in the pre-autonomous portion of the Competition Template. You may also need to adjust the “SensorScale” such that the sensor’s degree measurements are accurate. Information about calibrating the gyro and adjusting the SensorScale can be found here: http://robotc.net/blog/2011/10/13/programming-the-vex-gyro-in-robotc

This vamfun blog post from 2013 has some specific calculations that the author did concerning drift that more advanced readers may find helpful (and if you want to get *really* advanced, he has another post “Using a Line Sensor to Update Gyro Heading“). I admit that since I have not dived that deeply into trying to calculate anything specific in this realm, I cannot attest to its helpfulness as of this writing in 2017.

Noise

In easyC, there is a parameter to set the “deadband,” or sensitivity level of the sensor. A lower sensitivity produces a smoother curve of output data; a higher sensitivity is more accurate, but the numbers are more jumpy. In RobotC, however, you must set up your own deadband variable and use it in your while loop comparison statements (or however you’re using it).

Electrical Interference

Some users—but not others—have reported that their gyro values are affected by electrical interference from nearby wiring or other components. It’s another thing to keep in mind if you are running into unexplainable problems; try mounting the component away from everything else and see if it makes a difference.

A Reddit comment suggests a solution for static build-up:

You have to unplug and replug the cable before every match. Why? Because static builds up, and eventually it stops reading. You NEVER know when this will happen. It could be 25 matches without a problem, or you could run it once, and on the reboot it’s dead.

User Reactions All Over the Map, Really

As you can see from the video and Forum quote above, many teams have successfully integrated gyros into their robot lives. Other people are like this one below (and me), pulled from this VEX forum thread, have not.

Unless you desperately need a gyro for something like position tracking, just use encoders. I have never had a gyro work either old or fresh out of the box. They are very finicky, and even with stuff like the QCC2 gyro lib, they still have noise and errors.

That’s Lovely, Now What Do I Do With This?

As I mentioned at the start, now you treat your incoming information the same way you would treat, say, potentiometer data you’re using to lift up an arm. If I wanted to turn my robot 90 degrees, I could use a while loop (in a very simple example):

desiredValue = round(90 * 10 * scalingFactor);
actualValue = get(sensorValue);
while (actualValue <= desiredValue) {
set chassis motors so robot turns;
wait(100);
actualValue = get(sensorValue);
}

set chassis motors to 0;

Programming Details

Since (a) we had an epic fail trying to use this in easyC, and (b) we have not yet switched to RobotC, I don’t have much to offer in the way of programming specifics. jpearman and lots of other thoughtful people have posted sample code in the VEX forum (and there is also sample code in the easyC and RobotC libraries). I recommend searching in 2 different ways. (a) Google search on “VEX + gyro” or “VEX forum gyro”, etc.; and (b) go to the VEX forum and search all channels for the word “gyro.” These 2 methods will give some non-overlapping returns.

RobotC has a helpful page on the gyro (which is similar code to the sample program in the software’s library).

In addition, here is a helpful video from 2014 by Team 8756, that goes into specific details on how to program this sensor in RobotC, with screen-view/voice-over action (my personal favorite). The gyro part of this video appears around 16:40. Thanks to RunTheCode for posting this video to the VEX Forum while I was in the middle of writing this post!

Resources

The Conclusion, of this Very Long Post

For goodness sake, if I’ve gotten anything wrong here—or in any of my other posts—please email me and let me know and I will fix things as quickly as possible. I appreciate the knowledge of others, tremendously. This post is really a collection of our team’s experiences with this sensor, combined with various VEX forum posts; I am hoping that having this information all in one place will be helpful.


Other Sensors

Here’s a list of all of the sensors in my review:

Share this post: