Swerve train does not operate as expected

When trying to control our swerve drivetrain with an Xbox controller, the wheel only spins in one direction whether a positive or negative input is given. The module refuses to rotate, and the steer axis runs the drive motor at a slower speed that the other axes.

Repo Link:
BreakerBots/OffSeason_Swerve_Bot_2022

Notes:

  1. we are using the Talon FX integrated PID for bolth drive and azimuth control of the motors
  2. we are using MK4I swerve modules with the CANcoder as a remote sensor.
  3. we are aware of the existence of library’s for swerve drive robots (SwerveLib, etc) but we prefer to build stuff like this from scratch.
1 Like

My team uses the WPILib PIDF (the whole SwerveBot) instead of the TalonFX PID + F so I can’t make good specific comments - just a bunch of questions.

Your code is very sophisticated and you use many “advanced” features such as PIDF controllers, complicated configurable remote sensors, arbitrary feedforward. Has any previous version of this code worked? If so, backup to that and add features one at a time. If this code has never worked then start again very small. I start with one-liners (make the motors move with a set command) and build slowly one line, one function at a time testing all the way.

Have you previously used successfully remote sensors, the CANcoder, arbitrary feedforward and know how to assure they are right as they go into the black hole of the TalonFX? Or maybe the TalonFX isn’t a black hole and you can get it to regurgitate the values to make sure they are right?

The code doesn’t define all the CANcoder configs. That means reviewers can’t verify their reasonableness and the code can’t guarantee they are set right. My team does use the Phoenix Tuner to experiment with device configs then when a working set is determined they are hard-coded in the Java so we know for sure what they are set to.

CANconder configs are critical and much to go wrong.
Are the units in the CANcoder and the rest of the code and Talons consistent?
Has the continuous/non-continuous config been set right? In the CANcoder and the Talon?
Are the absolute positions being reported with the correct magnet offset already applied?
Is the Cancoder range used consistently between the CANcoder and the Talon?

I applaud your willingness to write your own code instead of using others’ libraries. That’s good practice for some things. I do think there is no shame in using the WPILib SwerveBot example to start with. (It does need to have PIDF stuff tuned to work otherwise it’s good if not perfect. You could look at my team’s tuning and that would probably work for you except the units are for WPILib and not Talons. SDS library PIDF tuning is already done for you and that was very nice.) If you can even understand how SwerveBot or SDS code works, you have accomplished much.

4 Likes

Thank you for your time and help. As it turns out, the error was coming from a misconfiguration of the azimuth motors inversion and remote sensor phase, as well as accidentally imputing degrees as the angle target when native units were expected. After correcting this, our code actually functioned quite well! Thanks again for your help!

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