Rapidly updating TalonFX Current Limit causes Loop Time Overruns

In order to prevent brownouts, we implemented an algorithm that lowers the supply current limit of a set of drive motors (the majority of the robot’s current draw) as battery voltage (as sensed by the PDP) drops below a threshold. This successfully prevents brownouts, as tested on the same battery before and after enabling the code. However, implementing this causes the execution time of our iterative loops to jump from the expected stable 20ms (+/- a bit) to 30-60ms, which is not ideal.

We originally thought the timeout included in the argument was causing code blocking while waiting for a response, which could be fixed by setting the timeout to 0, as described in the documentation for TalonFX::ConfigSupplyCurrentLimit(). However, this seems to occur whether or not the timeout is set to zero or a nonzero value. Has anyone else seen this problem?

In the meantime, we will probably end up implementing edge detection for falling below/rising above the voltage threshold, and only set the current once per pass of the threshold, in order to limit the effect of the loop overruns.

Yes. There are other calls that result in the same thing - pidf setting being one of them. Try only changing them when you need to rather than every loop.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.