Mk4i Swerve Drive losing offset values after building/restarting the code

Our team uses 364’s library to drive the Mk4i swerve. After testing for a couple of days we noticed that the chassis drives well after we offset it using the setSelectedSensorPosition with the desired angle (including autonomous) but after building/restarting the code the modules lose their offset values in random way. sometimes the value becomes negative and sometimes it doesn’t. Its causing a situation where we don’t know whether the code will work or not.
the problem is probably within the setSelectedSensorPosition function. What can we do to solve the issue? Or is the problem within the wpilib?

before using 364’s library we were using the SDS library and were offsetting the modules by changing the CANCoder’s position directly.

1 Like

My team is having this same issue. We also are currently switching from SDS to this There is an open pull request for the issue and they say they are working on it so I would wait for updates on.
After restarting the Robot We need to re align the wheels at the start · Issue #8 · Team364/BaseFalconSwerve · GitHub

1 Like

We tried putting the resetToAbsolute() method inside of SwerveModule one a button binding to test if it was an initialization issue. Here was our testing process:

Robot is powered off
Modules are rotated in random directions
Robot is powered on
We connect to robot
We enable and the swerve modules are in somewhat random orientations
We reset to absolute again using the button (x) that lacy and I made that reruns the `resetToAbsolute()` method that gets the current angle from the absolute encoders, subtracts the offset and sets the integrated encoder
Swerve modules are aligned as expected when driving

It is our opinion that this issue lies in the resetToAbsolute() method being called too early into robot initialization. The exact issue is not known at the moment.

Did you see this thread? Official SDS MK3 & MK4 Code - #99 by Zach_O
There are a variety of things you can do to minimize it, but nobody seems to have fully solved it.