I’m having trouble getting the CTRE Swerve Generator to work on our competition robot. I got it to work on our robot that we made in the offseason which is almost the exact same setup except the new bot has a CANivore, Roborio 2 instead of 1, and 2 of the motors are flipped (which is being handled in the code). I’ve updated the devices firmwares several times, reimaged the roborio, and swapped our canivore for a different one we had.
The specific problem I’m having is that whenever the steer motors are ran, they start spasming and going crazy. When calibrating it with the swerve generator, the steering test worked perfectly fine and the driving test worked only when the wheels were already rotated to 0 heading. All of this makes me assume that it’s something with the closed loop mode but I can’t seem to figure out what the problem is.
That tells me the steering test likely failed. In the steering test, all swerve modules should rotate counter-clockwise, as seen from the top of the robot. Additionally, CANcoder position should increase as the modules spin counter-clockwise.
If your modules are flipped, the CANcoders are likely still correct, but the swerve modules probably rotated clockwise instead of counter-clockwise. If you press “No” when asked if they all spun the correct direction, then we invert the steer motors so you can test again.
Since you already generated a project, you should be able to change kSteerMotorReversed to change the invert of the steer motors.
The steer test passed everything except for the one module with a flipped steer motor. I didn’t check the output of the cancoder while it was running though.
Another interesting thing I noticed was when in the swerve generator and the robot was enabled, if any wheel was rotated, the amount of resistance the motor was outputting was not consistent. When the wheel was facing around 0 degrees, there was almost no motor resistance and when it was 180, there was much more motor resistance. I’m not sure if this is expected or not, just something I observed.
During the steer test, the drive motors were also running at a constant speed. Based on this, I’m assuming it’s a problem with the PID values.
So the steering gains P value is generated to be 100 but the cancoder output is -0.5 to 0.5. Could this be the problem? I checked on our offseason robot and it’s got the same thing but that robot hasn’t been restored to factory defaults in a while so if something in those defaults has changed and the swerve generator didn’t change to match it, could that be the problem?
We experienced the same behavior during our last meeting (SDS MK4is, Krakens). Everything worked perfectly aside from the “rotate module to 0 degrees” part of the drive test. Sometimes it would work, sometimes a module would violently oscillate around the setpoint and then overshoot off to some random angle before enabling the throttle motors.
We opted to just use the drive test to check throttle motor inversion and call it a day. One guess as to this behavior is that the default PID gains generated assume that you have Phoenix Pro licensed and we didn’t have the licenses applied at the time, so the gains may have been a little aggressive for the system. Applying the license and actually driving around is on the docket for today’s meeting.
Weird. I’ve got pro licenses on all the motors and cancoders. When looking at the steer motors (Falcons), they had the pro license enabled as well as some other license that I didn’t look much into and don’t remember enabling. Could this be the reason I’m having troubles? There also isn’t a pro license on our canivore but my mentor said that was fine.
Hey, just an update, our violent oscillations were due to a switched pair of CANCoder CAN IDs. Went back through the wizard and double checked everything and the generator worked great.
Forgot to update on this yesterday, but I figured out the problem.
As I mentioned, we have 2 flipped motors. One is steer and one is drive, both on the front of the robot. When I went into the TunerConstants file to flip the steer motor, I did .withSteerMotorInverted(true). Since we have Mk4i’s, all of the steer motors already needed to be inverted so when I set the motor inversion to true, it wasn’t doing anything. The fix was to set it to false.
I definitely should’ve caught this sooner but I’m glad it wasn’t something bigger like a dysfunctional part.