Gyro Drift and correction

So at our last competition our alliance partners bumped us while we were shooting causing us to miss a number of shots before we corrected, and I thought, hey, what if the robot could correct that automatically, so I re-wrote the code that makes the robot turn, I now set a value I called target, and the robot uses gyros and PID controller to turn to the target angle. I tested this entire set up on a square bot and it worked great, so I moved it over to my competition robot. which has these two massive spinning vibrating wheels. The code works fine most of the time, however, as soon as we power up the flywheel, the gyros start to drift, slowly, about .5 degrees per second. and the PID loop dutifully keep the robot on the target angle, but the angle keeps changing, so the robot turns.

I have brought up the issue of gyro drift before, but this has never happened while the robot is sitting still.

I have done the best I can to eliminate the vibrations that reach the gyros by mounting them on two layers of rubber links. also I have two gyros that I average.

the other option I have thought of is a kalman filter that fuses data from the sensors such as drive encoders. however this will take time and lots of testing to implement. I am hopping for an easier solution.

I am trying to think of some way to test when the gyros are drifting, as opposed to when it is turning or has been hit. I don’t need to adjust for drift, I just need to be able to tell when it is happening, if anyone has any ideas please let me know

My best suggestion would be to not use the gyros to find your position, but rather to make turns. for instance, you drive against the left wall and you are shooting into the red goal, so instead of telling the robot to turn to 0 degrees in relation to the field, you tell it to turn 5 degrees to the right, so that drifting does not affect your angle. The only thing I can think of to know your position all the time is having the gyro tell an int to increase or decrease by however much it has increased/decreased in that second only if it is greater than 1 degree. That way any drifting at less than 1 degree per second will be trashed while your turns are usually faster than 1 degree per second.

It looks like your flywheel’s vibration is causing the gyro to drift, filtering wont fix this unless you are polling the gyro ridiculously fast, what i suggest is lubricating and aligning your flywheel’s bearings and isolating your gyro with rubber bands, plastic washers, etc and put it further away from the flywheel

Have you tried calibrating the gyro while the flywheel is running? If you plan on having it running most of the match, or at least while you will be utilizing it, then it is probably best to calibrate the gyro with the flywheel running.

I agree with pixel here. Creating an isolated ‘pad’ for the gyro to sit on can really help get you more accurate readings.

I already have an isolated pad, or as Isolated as it can be. I have a piece of angle that is mounted to the robot with rubber links, then the gyros are mounted to that piece of angle by rubber links.

as for the suggestion of using the gyro to turn relative to the robot, that kind of defeats the idea of the code. the idea is that the robot would automatically return to a position when hit, so even if I gave it instructions to turn relative to a current position either it would
a) turn to that position then terminate the PID control, which means it wont help if I get hit,
b) have it turn to a position relative to current position and maintain the PID, but this wouldn’t solve the drift problem, I think at this point my best option is to filter out slow changes is gyro values.

You could use the gyro as QCC2 did for skyrise. They use it as a rate gyro, and reject any rate under a certain amount, then integrate it with time to get position. Look for their library on github.