Swerve drive wheel(s) moving in wrong direction after a pi flip

The students have been madly trying to get their swerve (dual Neos on SDS MK4i’s) working after our conventional WCD bot was mobbed by swerve bots in week 1. We are using the rev maxswerve template that was ported to python by @virtuald (thanks, Dustin!). Using some good tips found in earlier threads we were able to get our motion working well, because there was a maddening left/right swap that was turning our rotation diamonds into X’s.
The main issue now is that there is one huge problem that prevents it from driving for a long time. As you start to switch from strafe to rotating etc, it of course turns wheels, and pretty quickly it has at least one wheel with a pi offset (180°) to the target angle. This would be fine because we’re still pointing the wheel in the correct direction, but the (kinematics/chassisspeeds?) is apparently not applying a minus sign to the velocity in that case, so that wheel ends up fighting the others.

We’re using what seems to be fairly vanilla swerve code in our swerve branch, although there are still some housekeeping issues of getting rid of the relics in the template we don’t need. Has anyone else come across this pi offet causing driving problems?

Note we are still using relative encoders - just setting the wheels straight to start and resetting the sparkmax encoders for turning to zero. But it keeps track of the angle very well.

I’m not sure this explains everything you’re experiencing here, but I think you need to call self.turningPIDController.enableContinuousInput().

Thanks for the tip. We did have that one in the code.
It seemed to boil down to trying to test before we put our absolute encoders on.
Our analog encoders were just super noisy if we put them directly into the sparkmax, but once we shifted to the roborio they were nice an quite.
Then once we stopped trying to set the wheels to zero and use the controller’s encoder, that wheel direction / flip issue stopped happening.
Basically, the lesson learned is that it’s far easier to debug after putting on the absolute encoders.