Encoder synchronization causing loop overrun
Closed this issue · 1 comments
I am running swerve with Falcon 500 drive and steer and CANCoders.
During teleop on every 6th periodic call SwerveDrive attempts to re-synchronize the integrated motor encoders to the CANCoders. This action takes about 5ms for each motor, which results in a loop overrun.
The cause of this issue is the call to cfg.setPosition
on line 418 of TalonFxSwerve.java, which sends a new configuration to the motor. The default timeout of 50ms is used.
It also seems to be a bug that this feature runs on every 6th loop rather than every 5th, and moduleSynchronizationCounter
does not get reset when the robot starts moving.
I'm not entirely sure why the encoders are re-synced every 120ms. The code references 'democrat's SDS lib' as the inspiration for the feature, but I couldn't find the original implementation. There doesn't seem to be any reason that the encoders would become desynced after the robot is started.
It's possible to implement a workaround to maintain this functionality or only update the config when a large enough offset is detected, but it might be easier to just remove the periodic encoder synchronization if it's not needed.
Fixed in latest commit by making this functionality optional