Greetings,
The Problem
I am the only programmer on a small team, and I’ve been trying to get out WCP swerve drive modules working since last build season until now. We’ve tried many things, but so far we just can’t hit the nail on the head, as it were. I’ve tried posting more specific questions here along the way, but I am now so completely lost that I’m not sure what to check next.
I understand that the question I’m asking is extremely vague, and I will do my best to provide as much information as I can to make it less so.
Background Knowledge
The code repository in question is https://github.com/SirFireE/Swerve8551. Please note that I may be actively making new commits to this repository in the future.
Our swerve modules, as mentioned, are WCP swerve drive modules with Rev NEO motors and CTRE CANCoders. We have confirmed that all of this hardware works as expected. Our spark motor controllers are currently factory reset, and our CANCoders are factory settings except for absolute magnetic offset.
Program History
We received our CANCoders about a month ago, and since then, we have been trying to simply set the position of one module. Our first attempt was to use the WPILib PIDController
class, and call .calculate()
periodically, every 20ms, and set the returned value directly to the motor using the CANSparkMax
’s set()
method. The result of this was that the motor always overshot the target and was shaking violently, or sometimes the motor did not move at all, even though the PID error was large.
We also tried using the PIDController
for all four modules in the code repo mentioned above, but they were not outputting any value no matter what the setpoint was. We did confirm that the SwerveModuleState
s were updating and working as expected based on the Joystick inputs.
Even before this, we’ve had much better success with the SparkMaxPIDController
, but it does not take the CANCoder
as an argument for setFeedbackDevice()
. My weird idea to fix this was to get a RelativeEncoder
object and set its position to the CANCoder
’s absolute position periodically, again, every 20ms, and set the SparkMaxPIDController
’s feedback device to the RelativeEncoder
. This actually did work, but only with a very low PID proportional term (0.2) and a very high PID derivative term (0.7). The movement of the motor was fairly slow, (As expected) and sometimes the motor wouldn’t move for some reason, but we were willing to start with that as that was the best we had.
With that, we set up the same thing with all four swerve modules, as can be seen in our code repo here. The result of this was that all of the modules were overshooting their setpoint and shaking, even with the same PID terms as before (P: 0.2, D: 0.7). This was all in our last meeting, so that’s as much as we’ve found thus far.
Conclusion
All of this has been very frustrating to me personally as the only programmer because I do feel like I’m missing something obvious, but I’m not sure… We’re really hoping that we can get our swerve drive working before the 2024 reveal. I’m wondering if there is something completely obvious in our existing code that I’m just not seeing. I will try my best to provide more information as this goes along, and even if it only barely works at the end of this, I and my team will be so so so thankful for your help! We are still a relatively new and small team, so swerve drive was a big thing for us. Hope y’all have a fantastic day.