Here is the pseudo code for how I got around the 360 degree limit on the swerve drive modules (aka: after 359 degrees it would go the long way to get to 1 degree)

Set a variable to the current encoder position (I'm going to refer to it as variable A)

Set that variable to itself divided by 1657 (the number of encoder counts per rotation)

Set a temporary variable to the next setpoint (aka the temp variable for now)

Round variable A down to the nearest whole number, and add it to the temp variable (but don't actually change variable A) (In Java, you can just cast to an Integer for this step.)

Set the encoder value to itself mod 1. (mod = modulus, which is a % sign in java)

If the next setpoint (not the temp variable) - the encoder value is greater than 0.5, then subtract 1 from the temp variable.

If the next setpoint (again not the temp variable) - the encoder value is less than -0.5, then add 1 to the temp variable.

Set the setpoint on the talon to the temp value

enable the talon.

Here is the code in Java:

double encPos1=cANTalon1.getEncPosition();

encPos1/=1657;

double temp1 = setPoint1;

temp1+=(int)encPos1;

encPos1= encPos1%1;

if ((setPoint1 - encPos1) > 0.5){

temp1-=1;

}

if ((setPoint1 - encPos1) < -0.5){

temp1+=1;

}

cANTalon1.set(temp1);

cANTalon1.enable();