Currently, SwerveModule.periodic() only updates the turn voltage. The drive voltage is only updated when SwerveModule.setSpeed() is called. Since drivetrain code might not call setSpeed() regularly (e.g. if nothing is changing the speed), the drive pid controller won't be called to determine the correct voltage to use to achieve the most recently requested speed. Seems like the code in setSpeed() should be moved into periodic() and setSpeed() should just save the desired speed in a field for use by periodic().
This is almost definitely the cause of the robot drifting while it's supposed to be stopped in the middle of an auto routine.
Currently,
SwerveModule.periodic()
only updates the turn voltage. The drive voltage is only updated whenSwerveModule.setSpeed()
is called. Since drivetrain code might not callsetSpeed()
regularly (e.g. if nothing is changing the speed), the drive pid controller won't be called to determine the correct voltage to use to achieve the most recently requested speed. Seems like the code insetSpeed()
should be moved intoperiodic()
andsetSpeed()
should just save the desired speed in a field for use byperiodic()
.This is almost definitely the cause of the robot drifting while it's supposed to be stopped in the middle of an auto routine.