swerve-lib calls resets the motor encoder state every 500 loops (10s).
// Reset the NEO's encoder periodically when the module is not rotating.
// Sometimes (~5% of the time) when we initialize, the absolute encoder isn't fully set up, and we don't
// end up getting a good reading. If we reset periodically this won't matter anymore.
if (motor.getSelectedSensorVelocity() * motorEncoderVelocityCoefficient < ENCODER_RESET_MAX_ANGULAR_VELOCITY) {
if (++resetIteration >= ENCODER_RESET_ITERATIONS) {
resetIteration = 0;
double absoluteAngle = absoluteEncoder.getAbsoluteAngle();
motor.setSelectedSensorPosition(absoluteAngle / motorEncoderPositionCoefficient);
currentAngleRadians = absoluteAngle;
}
} else {
resetIteration = 0;
}
This only gets called if we actually set the reference angle, which only gets called if we call setStates() with the same angle (i.e. when sitting still). We should make sure this is called in testPeriodic so our swerve modules will "snap" into place.
To do this, I think we can just call drivetrainSubsytem.stop() in testPeriodic.
swerve-lib calls resets the motor encoder state every 500 loops (10s).
This only gets called if we actually set the reference angle, which only gets called if we call setStates() with the same angle (i.e. when sitting still). We should make sure this is called in testPeriodic so our swerve modules will "snap" into place.
To do this, I think we can just call drivetrainSubsytem.stop() in testPeriodic.