Skip to content

Fix energy analysis: AKit delta-log overcounting and Kraken regen#175

Merged
nlaverdure merged 2 commits intomainfrom
bugfix/energy-analysis-interp-clamp
Mar 25, 2026
Merged

Fix energy analysis: AKit delta-log overcounting and Kraken regen#175
nlaverdure merged 2 commits intomainfrom
bugfix/energy-analysis-interp-clamp

Conversation

@nlaverdure
Copy link
Copy Markdown
Member

Summary

  • AKit delta-log overcounting bug: AdvantageKit only writes a new record when a value changes. Motors idle at 0 A produce no log entries, so interp_entry's left-extrapolation held the first non-zero sample (e.g. a mid-shoot 60 A reading) back across the entire pre-activation window. This falsely accumulated energy for every mechanism that started the match idle. Fix: after interpolation, zero out current before the first logged timestamp within the analysis window. Corrected average totals: Kicker 22.4→16.7 kJ, Spindexer 19.0→11.9 kJ, Total 326.1→311.5 kJ.

  • Kraken regenerative braking: TalonFX/Phoenix 6 reports negative supply current during regen. The previous np.maximum(current, 0.0) clamp was silently discarding ~3.2–3.6 kJ of recovery per match (~1.8% of drive energy). Added KRAKEN_GROUPS = {"Drive", "Flywheel", "Lower Roller", "Upper Roller"} and a clamp parameter to cumulative_energy_J; non-Kraken groups and PDH-sourced Electronics retain clamping. Corrected average totals: Drive 180.6→177.4 kJ, Total 311.5→308.1 kJ.

  • Added scripts/energy_feeder_auto_q54.py — focused stacked-area plot for Spindexer + Kicker over the Q54 autonomous period only, with shoot-window annotation.

  • Updated doc/energy_analysis_writeup.md tables and key observations to reflect corrected numbers.

Test plan

  • Run python scripts/energy_analysis.py <q54_log> 150.011873 314.890358 — verify Drive ≈ 208 kJ, Total ≈ 330 kJ
  • Run python scripts/energy_analysis.py (14-match average) — verify Drive ≈ 177 kJ, Total ≈ 308 kJ
  • Run python scripts/energy_feeder_auto_q54.py — verify Spindexer ≈ 1.5 kJ, Kicker ≈ 2.0 kJ for auto only, plot saved to doc/assets/
  • Confirm no mechanism shows energy decreasing mid-match (regen dip in drive is expected during decel, but cumulative should not go negative)

🤖 Generated with Claude Code

nlaverdure and others added 2 commits March 25, 2026 14:07
interp_entry used left=vs[0] extrapolation, which holds the first logged
current value backwards in time. For motors that are idle at exactly 0 A
(spindexer, kicker pre-shoot), no log entries exist until the motor fires —
so the first in-window sample was mid-shoot (~60 A), falsely inflating energy
for the entire pre-activation window.

Fix: after interpolation, zero out current values before the first actual
logged timestamp within the match analysis window. Affects process_match()
in energy_analysis.py and the standalone energy_feeder_auto_q54.py script.

Corrected values (avg across 14 matches):
  Kicker:    22.4 -> 16.7 kJ
  Spindexer: 19.0 -> 11.9 kJ
  Total:    326.1 -> 311.5 kJ

Also adds energy_feeder_auto_q54.py — focused spindexer+kicker auto-only
plot for Q54, and updates writeup tables and observations accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove supply current floor (np.maximum(..., 0)) for Kraken-powered
mechanism groups (Drive, Flywheel, Lower Roller, Upper Roller).
TalonFX/Phoenix 6 reports negative supply current during regen;
clamping it to zero was silently discarding ~3.2–3.6 kJ of recovery
per match (~1.8% of drive energy).

Add KRAKEN_GROUPS constant to control which groups integrate without
clamping. Non-Kraken groups (Spindexer, Kicker, Turret, Hood,
Compressor) and PDH-sourced Electronics keep clamp=True since their
supply current is always non-negative.

Updated numbers (14-match average):
  Drive:  180.6 → 177.4 kJ
  Total:  311.5 → 308.1 kJ

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nlaverdure nlaverdure merged commit e7a199a into main Mar 25, 2026
2 checks passed
@nlaverdure nlaverdure deleted the bugfix/energy-analysis-interp-clamp branch March 25, 2026 18:25
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