PID for both Gyro and Encoders

Hi! My team has been preparing for upcoming competitions and we have been using both a Gyro or encoders (we have a differential drive) for autons and skills. I have a simple PID controller for our Gyro and am using the built-in v5 PID for the encoders. I wanted to know if it was possible to use both the Gyro and Encoders for our turns. I know how to use the Gyro in correspondence with our encoders for driving straight, but I can’t figure out how to combine the error for the encoders and the gyro into a single closed loop. Any help would be greatly appreciated. Thanks! (By encoders I mean the built-in ones on the v5 smart motors)

What kind of robot are you? Flywheel? Puncher? If you’re flywheel, I wouldn’t recommend a gyro. My team used a gyro on our flywheel robot for turning and the robot would always end up turning differently. For this reason, my team only uses encoders for the PID turn. It is somewhat like our PID move (straight) where we check sensor values on both sides of the drive and using proportional and derivative constants, we adjust the speed of one side to match the other so the robot drives straight.

However, for your actual problem, maybe try using the encoders to get close to the position you want your drive to be in and use the gyro to move the robot to the final desired position. I personally think that gyros are decently accurate so it might be worth trying to have the encoders do the bulk of the work and have the gyro do the rest. Could you also maybe show your drive code? That may help.

This is probably due to the vibration inherent to a flywheel, and can be reduced by mounting the gyro to 2 rubber links with a small amount of extra weight (like locking collars) on the links.

We saw that it was in fact the vibrations. One of our coaches recommended taking it off. Thanks for the suggestion though.

Yeah, it was something that we found out the hard way in nothing but net, another thing that helps is to set the port to nothing, and then to reset it to a gyro and this is part of the “initialization” that we had to go through to get it to read values correctly. The gyro makes things easier for quick and dirty turns where accuracy doesn’t matter that much, and can get you to a reasonable level of accuracy, but encoders ended up being more precise and repeatable for turning anyways.