Swerve Drive spinning out and flipping at 0 degrees using REV

Our team has been building a swerve drive. When programming it using Java we come to an error. At 0/360 degrees, the module tends to spin out.

Our issue is the same as Swerve Modules flip 180 degrees periodically/conditionally
However the solution won’t work for our drive as we are using REV motors instead of falcon.

I believe the issue is with REV’s setRefrence() method of setting the swerve’s wheel position. The solution in the attached post doesn’t help us as it doesn’t change the fact the the setRefrence() method only takes a desired position and a control type as inputs. If the motor was set at 340 degrees and was told to set to 0, the method would -340 degrees instead of +20.

Any help would be appreciated

As you can see from that thread, you need to be able to wrap the encoder input (have the end of the left side of the range be treated as the same point as the right side of the range). I can’t find that feature in the Spark Max’s PID controller API, so your choices are:

  1. Use WPILib’s PIDController or ProfiledPIDController instead. Call enableContinuousInput() to enable it. That thread mentioned some bugs in continuous input mode that have since been fixed upstream, so you’d need to copy the latest MathUtil and PIDController classes into your robot code.
  2. Implement the logic from WPILib yourself so you can pass a corrected reference to setReference().
2 Likes

You might want to upvote and/or comment on the issue in REV’s S/W issue tracker: Add continuous PID capability.

FWIW, this issue seems to come up often any time there is a new motor controller; there’s the thread mentioned in the lead post (reported on Falcon 500), and years ago the same issue existed on the original CAN-based motor controller, the Jaguar: Jaguar Speed & Position Control with Encoders - #17 by nuttle.

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