I have been working to convert our Swerve code from using the SDS libraries to the WPI method. Our swerve is using Falcon 500s and trying to use the onboard PID control. I was trying to program it to use the PID constraints from the SDS libraries.
We are working on a similar project this preseason. We don’t quite have the code working yet, but we found Team 364’s code very helpful: https://github.com/Team364/BaseFalconSwerve
I liked the method from 364 so I made another version that uses their their setup combined with my code. I had to make a few changes to get rid of a few errors but have hit a road block where the code crashes at startup.
The SwerveModule’s getState method is calculating the velocity as NaN. This is because the value of Constants.ModuleConstants.driveGearRatio is 0. This constant is defined as:
public static final double driveGearRatio = (((50/14)*(17/27)*(45/15)) / 1.0); //6.75:1
public static final double angleGearRatio = (((32/15)*(60/10)) / 1.0); //12.8:1
Java will perform integer division if both values are ints instead of doubles. As a result 17/27 evaluates to 0, which results in the entire expression evaluating to 0. Use double literals instead:
public static final double driveGearRatio = (((50.0/14.0)*(17.0/27.0)*(45.0/15.0)) / 1.0); //6.75:1
public static final double angleGearRatio = (((32.0/15.0)*(60.0/10.0)) / 1.0); //12.8:1
Looking for some help to understand why sometimes when we start the robot one of the modules ends up 90 out of rotation. When we restart the code it often fixes the issue. It’s hard to diagnose as it only happens sometimes and I think only when we turn on the robot or upload new code but I am not sure.