Phoenix 6 API Efficiency

We are running into loop timing issues.

It isn’t clear from the Phoenix 6 docs Status Signals if calling .getVelocity().value in every loop is bad in Python or if we need to get all the signals once in __init__ and then use BaseStatusSignal.refreshAll([listOfSignals]) once in periodic or is it okay to call .getVelocity().value each loop and possibly multiple times in a given loop?

Our DriveTrain update, that runs odometry for our swerve and LL pose correction, takes about 0.01 seconds on its own. We’d like to reduce that if at all possible because our total loop time when running PathPlanner and auto aiming gets up to 0.03 seconds.

@ozrien

2 Likes

I found caching the signals and refreshing them in 1 refreshAll call was exactly the optimization needed to reduce frequent loop overruns quite a bit. Our team uses C++ but the Phoenix 6 docs seemed to imply that each individual refresh is rather expensive.

3 Likes

This is what I’ve seen many other teams do as well. FRC 4646’s code base was inspiration for me when I implemented it for our test branch: GitHub - frc4646/2023-robot-public

We changed over to this approach last night and saw much more consistent control across our robot. Those changes along with some network table improvements resulted in much more consistent loop timing and control loop behavior.