Hello,
We are making a new swerve for our upcoming season, so as part of that we had to change some of the code from our old swerve. When we use the slightly modified code, every control only turns the drive motors either forward or backward - the angle motors never get powered. (see video 1)
I used the CTRE swerve generator through Phoenix Tuner, and that code worked.
I was wondering if anyone would be able to help me figure out why the original code isn’t working.
I have printed ParentDevice#getDeviceID() to the smart dashboard for each motor and also Constants.Swerve.Mod0.driveMotorID and all the other expected values, all match.
Additionally, I have printed the values of the double suppliers (both the raw value and the value after the deadband is applied) and both values are correct.
(printed inside of New-Swerve/src/main/java/frc/robot/commands/TeleopSwerve.java at main · Jacob6925/New-Swerve · GitHub)
Nothing screams at me while reading the new code, but I do have one early question. Why are you switching from the ctre generated code? These templates are typically very good.
We started with the first set of code (New-Swerve repository), which I worked with last year. It was the same code we used for our robot last year.
I learned about the CTRE generator this year and decided to give it a try when our code wasn’t working (middle of last week). The reason I would like to use our code instead of the generated code is because I don’t understand the generated code very much, so I’ll have a much harder time doing anything to it if need be.
It looks to me like your CANcoder IDs are conflicting with motor IDs you have in your module constants. Your CANcoder IDs need to be completely unique from any other device’s CAN ID.
You can have a CANcoder with the same ID as a Talon FX. Device IDs only need to be unique within a device type, and CANcoder, Pigeon 2, and Talon FX all have different device types from each other.
Just for reference, the 2025 Swerve API still uses much of the same logic as last year’s API so far, besides that most of the API (except for applying configs) is implemented in C++. So you can look at the LegacySwerveDrivetrain and LegacySwerveModule source code to get an idea of how everything works. Some of the new C++ implementation (including changes to seedFieldCentric() and swerve requests) is also visible in SwerveDrivetrainImpl.hpp and SwerveRequest.hpp.
As for why your original code isn’t working, as someone else pointed out it looks like your steer PID gains are all 0. As a side note, our Tuner X Swerve Project Generator supports generating just the TunerConstants.java file. So if you still want to use your own code, you could adjust your swerve subsystem constructor to work with the SwerveModuleConstants and SwerveDrivetrainConstants instances created by TunerConstants.