We have a swerve drive setup wtih MK4i L2, with cancoders and NEOs, with a rio1.

The issue we’re having with the YAGSL library, when we’re running the built in drive command with no controller input (X and Y are set to 0), our modules spin seemingly randomly, with the module(s) angle fluctuating between increments of 180 degrees sometimes.

Our code

You may need to invert your angle motors. Sounds like it’s trying to go to an angle and powering it in the wrong direction. Hope this helps!

I also have an active issue with this in YAGSL which will be resolved before competition season where i will overload Rotation2d with a custom one that retains the original non wrapped angle in degrees/radians. Which will fix the issue of wheels flipping between 0 and 180 when they are equivalent.

If you want to fix this issue (before i find time to do it) you would need to modify SwerveModule and all SwerveMotor.getPosition() add a SwerveRotation2d inside the swervelib.math, then modify the SwerveMath.optimizeAngle function.

Alright, thank you so much! We’ll try it out once we get the chance, and I’ll let you know if it was indeed what was up with it.

Just updated my post to include a key step i forgot to mention, updating the SwerveMath.optimizeAngle function

Hello, we are having some issues with our swerve implementation. We are trying to use a field oriented drive, and we have a drive command that works fine (a little drift but that’s unrelated) when not in field oriented mode. However, when in field oriented mode we are experiencing some unexpected behavior.

When rotated 0 degrees, the drive works as intended. However, when rotating 45 degrees clockwise, pushing the stick forwards causes the drive to move to the right (relative to the field, diagonally relative to the robot itself). When turned 90 degrees clockwise, pushing the stick forwards causes the drive to move backwards relative to the field, to the right relative to the robot.

My theory is that the robot is properly correcting for the rotation relative to the field, but is applying the correction in the wrong direction somehow? I’ve attached a video demonstrating the behavior. Is this an issue on our end that you would have any advice how to debug? The most current code should be pushed shortly after this post. Thank you for your time!

We have a video explaining the issue uploaded here: Gofile - Free Unlimited File Sharing and Storage

I can’t speak for the code I don’t see; however have you tried inverting your drive motors, and possibly the gyroscope. But if you just set field oriented in this it should work. I also encourage you to try simulating it and use Releases · frc-web-components/app · GitHub to ensure YAGSL is acting as expected