DeepBlueRobotics / lib199

Code that we reuse in different projects/years.
Other
2 stars 0 forks source link

`SwerveModule.periodic()` does not update the drive voltage #39

Closed brettle closed 1 year ago

brettle commented 1 year ago

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.