MK4i, CANCoders, NEO - Swerve Offset Issues

Have a swerve drive setup with the following:

  • SDS MK4i
  • CANcoder absolute encoders
  • NEO drive and turn motors
  • Pigeon 2.0 gyro

I am attempting to initialize the zero angle with the CANcoders and then use the SPARK MAX to drive the turn motors with the internal PID. I have gotten it to the point where the motors react correctly to driving, but all point to an incorrect zero. Further more, the zero point is different for each of them every time I redeploy code.

I have checked the offset angle dozens of times through Phoenix Tuner; I must be doing something else wrong.

Could someone check my SwerveModule.java and see where I am going wrong? The drive subsystem and robot container remain the same from previous years doing swerve drive, so I am assuming I am setting this up wrong.

Check out this fourm post: Official SDS MK3 & MK4 Code - #99 by Zach_O

We had experienced a similar with our offsets and implementing both options 1 & 2 seems to have eliminated the issue.

Thanks for the help. I already had it boot to absolute so I added the second option. They all reported “Ok” every time so that is nice to see.

I fixed my offsets as someone had changed the range to unsigned 0-360. All the modules point in the same direction now.

However, I have a new problem. While I can turn to the correct position, the modules jitter a lot when going to position. They don’t oscillate around setpoint, just jitter while going there.

Ignore me. It was a low battery…

I’m pretty bad at this stuff.

No problem! If you look at your DriverStation Log (Driver Station Log File Viewer — FIRST Robotics Competition documentation) you can look at the current draw of your PDP/PDH. If you continue to see Jitter like that you may want to add or adjust your current limiting on your swerve module motors. Additionally voltage compensation could help.

1 Like

we had this same issue like 2 years ago, spent hour trying to do offsets everytime it kept changing and we were so confused, turns out the battery was just low lol. happy you figured it out

1 Like

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