Look at this page that describes the
Team 1640 Swerve Drive. We use a Cherry Magnetic Sensor at the top of the pivot to tell the direction. It works well, the system knows which way the wheel is facing at all times.
But, our programming team came up with a "least turn" algorithm. Since there are drive motors are for each wheel and they don't really have the concept of "forwards/backwards", the programmers know which way to spin the wheels that gets them aligned in the fastest way. So unlike the "side linked crab" swerve drives that you see, we can go from going one direction to another by only moving the wheels < 90 degrees.
It also allows us to create and drive in snake mode to make it easier to follow the ball.