BitBucketsFRC4183 / FRC2022-Rapid-React

Team 4183's repository for our Rapid React robot's code
MIT License
4 stars 17 forks source link

testPeriodic() should call "stop" on drive train #169

Closed cpostbitbuckets closed 2 years ago

cpostbitbuckets commented 2 years ago

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.

cpostbitbuckets commented 2 years ago

Fixed by Scott