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.
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.