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

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

@FlyingRobot3428B 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.

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)

#define WHEEL_DIAMETER 1
float gyroValue = 0;
float moveTick,moveFix,moveBuffer;
float leftSpeed,rightSpeed;

task absDriveService(){
  float leftPos,rightPos,fix;
  while(1){
    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){
      leftMotorGroup.move(0);
      rightMotorGroup.move(0);
      break;
    }
    if( fabs(gyroValue) > moveBuffer){
      fix = gyroValue * moveFix;
      leftSpeed += fix;
      rightSpeed -= fix;
      leftMotorGroup.move(leftSpeed);
      rightMotorGroup.move(rightSpeed);
    }
  //to prevent overload
  pros::delay(5);
  }
}
//tune the default value of fix and buffer yourself
bool absForward(int cm, int speed, int fix = 3, int buffer = 1){
  //tare position
  leftMotorGroup.tare();
  rightMotorGroup.tare();
  //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;
  leftMotorGroup.move(speed);
  rightMotorGroup.move(speed);
  //converts cm to ticks, but tune "WHEEL_DIAMETER" yourself
  moveTick = ((cm / (WHEEL_DIAMETER * 3.14159)) * 900);
  moveFix = fix;
  moveBuffer = buffer;
  absDriveService();
}

hope it helps :slight_smile:

4 Likes

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?

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

1 Like

@FlyingRobot3428B 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 flyingnerd123@gmail.com

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

4 Likes

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

2 Likes

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

1 Like

Sure. thanks for offering the help.