Skip to content

Performance tweaks 3#98

Merged
caparomula merged 4 commits intomainfrom
performance-tweaks-3
Feb 27, 2026
Merged

Performance tweaks 3#98
caparomula merged 4 commits intomainfrom
performance-tweaks-3

Conversation

@caparomula
Copy link
Contributor

Deploys and runs fine, though I only tested it in disabled.

Phase 1 of performance optimization work ported from performance-tweaks-2.

Profiling Infrastructure:
- Robot.java: Track scheduler and gameState timing (>20ms threshold)
- Drive.java: Track lock, gyro, modules, odometry timing (>5ms threshold)
- Module.java: Track updateInputs and logging timing (>2ms threshold)
- Vision.java: Track copyInputs, cameraLoop, consumer timing (>5ms threshold)
- Intake.java: Track update and logging timing (>2ms threshold)
- Feeder.java: Track spindexer and kicker timing (>2ms threshold)

CAN Optimization:
- Remove BaseStatusSignal.refreshAll() calls that block on CAN responses
- Rely on Phoenix 6 auto-update at configured frequency (50Hz telemetry)
- Position signals for odometry handled by PhoenixOdometryThread at 250Hz
- Check connection status via .getStatus().isOK() instead of blocking refresh

Files modified:
- Drive.java: Remove batched signal refresh, add profiling
- Module.java: Remove refreshSignals()/getStatusSignals(), add profiling
- ModuleIO.java: Remove interface methods for signal refresh
- ModuleIOTalonFX.java: Remove allSignals array and refresh methods
- IntakeRollerIOTalonFX.java: Use non-blocking status checks
- FlywheelIOTalonFX.java: Use non-blocking status checks

Documentation:
- Add doc/TWEAKS3.md explaining changes and methodology
Phase 2 of performance optimization work.

Profiling:
- Launcher.periodic(): Track update, log, aimLog, ballistics timing (>3ms)
- Launcher.aim(): Track v0nom, baseSpeeds, v0replan, setPos timing (>500μs)

Deferred Logging:
- Cache values in aim() instead of calling Logger.recordOutput() directly
- Log cached data in periodic() via logCachedAimData()
- Moves Logger overhead out of time-critical aim() hot path

Zero-Velocity Guard:
- Check v_r < 1e-6 before calling Translation2d.getAngle()
- Prevents ArithmeticException or NaN when velocity is near zero

Method Renames:
- getV0() → getV0Nominal() (for impact angle calculation)
- getV0() → getV0Replanned() (for flywheel speed recalculation)
Phase 3: Analyzed subsystems added since performance-tweaks-2 was
branched for blocking CAN calls and added profiling where needed.

Changes:
- Add profiling to Hopper.java periodic() with 2ms threshold
- Document Phase 3 analysis in TWEAKS3.md

Analysis findings:
- All Spark-based IOs (Spindexer, Kicker, Hood, Turret) already use
  SparkOdometryThread for non-blocking CAN reads
- GyroIOBoron uses CanandgyroThread for non-blocking reads
- Pneumatic IOs (Hopper, IntakeArm) use DoubleSolenoid which has no
  blocking CAN concerns

The codebase is well-structured with consistent use of background
threading for motor controller IO operations.
Profiling showed [Intake] update=23ms spikes caused by Logger.recordOutput()
calls inside IntakeRollerIOTalonFX.updateInputs(). Each Logger call can
take 10-30ms due to serialization overhead.

Fix: Move follower telemetry into the IntakeRollerIOInputs struct so it
gets logged via Logger.processInputs() in the subsystem's periodic()
instead of blocking inside updateInputs().

Changes:
- IntakeRollerIO: Add followerAppliedVolts, followerCurrentAmps fields
- IntakeRollerIOTalonFX: Populate input fields instead of Logger calls
- TWEAKS3.md: Document Phase 5 fix
@caparomula caparomula merged commit 0267b53 into main Feb 27, 2026
2 checks passed
@caparomula caparomula deleted the performance-tweaks-3 branch February 27, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant