First time swerve code help

Link to code: GitHub - FRC4418/2023_Offseason_Swerve

Link to video: swerve bug - YouTube
We just started programming our first swerve drive and we’re having a problem with turning. When the rotation stick is pushed slightly to one side, the robot turns one way, while when it is pushed fully to that side, it turns the other side. The affected direction is random and the other direction always works as intended. The video shows an example of this bug. Does anyone have ideas on where this problem could be coming from? This code is building using Yet Another Swerve Library and its example project.

If I were to hazard a guess, it might be a data type issue, causing an overflow, or rollover in values.
That said, is this roll your own code, or some other pre packaged code?

Hiii!!! Are you using navx?
So I saw that in SwerveSubsystem.getHeading you are using getYaw which is a function that only gives values from -180 to 180 which sometimes can confuse the swerve WPIlib libraries. Try instead using this funcion:

public double getHeading() {
return Math.IEEEremainder(gyro.getAngle(), 360);
}

Hope it helps

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.