Swerve encoders

YAGSL seems to accomplish this quite well, I suggest you look in to their codebase.