Gyroscope Drift Detection

When I was still competing in FLL, the most important thing which I wanted to implement was a Gyro drift detection, during the match. Furthermore turning off the Gyro or killing it if it drifts. If the problem persists, making the robot automatically rely on the encoders rather than the Gyro. Rather than just the start. I never had the chance to do so. Hopefully someone has a solution for this for Vex.

i can PM you some code to help with Gyro. which makes it 99% accurate

@FlyingRobot2917X can you by chance send me the same code?

@FlyingRobot2917X could you also send me the code as well by any chance?

Could you just post the code here?

You could continually compare the encoder values to that of the gyroscope. Using the arc length covered by both sides, the angle of the robot is just the difference of the distance covered by the right and left encoders, divided by the distance between them. Even if the wheels slip, you have a very good approximation of the angle still. If the gyroscope goes above or less than a certain percent of tolerance you experimentally derive, you can make the gyroscope reset while the encoders takeover.

If no encoders are present, you can use 2 gyros stacked on top of one another. The amount of drift on both of them will be the same, but opposite, and can be therefore eliminated.

Both of these methods require much testing.

1 Like

Here is my code:
its just the part which processes the gyro value to make it drive strait, not to make sure the gyro readings are correct
(im writing it in pros but its not so much of a difference)

float gyroValue = 0;
float moveTick,moveFix,moveBuffer;
float leftSpeed,rightSpeed;

task absDriveService(){
  float leftPos,rightPos,fix;
    leftPos = leftMotorGroup.position();
    rightPos = rightMotorGroup.position();
    gyroValue = gyro.get_value();
    //fabs is same as abs but for floats
    if( fabs(leftPos) >= moveTick || fabs(rightPos) >= moveTick){
    if( fabs(gyroValue) > moveBuffer){
      fix = gyroValue * moveFix;
      leftSpeed += fix;
      rightSpeed -= fix;
  //to prevent overload
//tune the default value of fix and buffer yourself
bool absForward(int cm, int speed, int fix = 3, int buffer = 1){
  //tare position
  //this just set motor speeds, this is not the typical way you do it, but is just a feature of mine
  leftSpeed = speed;
  rightSpeed = speed;
  //converts cm to ticks, but tune "WHEEL_DIAMETER" yourself
  moveTick = ((cm / (WHEEL_DIAMETER * 3.14159)) * 900);
  moveFix = fix;
  moveBuffer = buffer;

hope it helps :slight_smile:


i would prefer not to, but if you want it i can PM it to you

1 Like

my method checks if the gyro’s rate is very small so then it is probably drift and then subtracts that from the current value to give you an extremely accurate reading

1 Like

Yes please

i have PM it to you :slight_smile:

Could I also get the code PMed as well?

Could I get that gyo code also?

1 Like

Please, @FlyingRobot2917X can you post it here or tell us the basic logic?

1 Like

@FlyingRobot2917X Please PM me the code

Just the logic would be fine

i will not be PM the code anymore but i will give you the basic logic

you get the gyro rate and if it is small it is likely to be drift
you subtract the amount of drift that happened in the time period that the rate was small from the current value to give you an accurate reading

if you really need help email me at

also i will not give code out to beginners becuase that defeats the purpose of learning @thorstenl312 @toastedman @DiamondDragon @langchen


I dont really like people sharing chuncks of code for people to copy. Sharing the logic can let them investigate (in this case) eg: how to measure the rate


i 100% agree. :grin: :+1:

1 Like

Sure. thanks for offering the help.