Skip to content

fix(control): sync PI.Setpoint when energy-dispatch zeros GridTargetW - #84

Merged
frahlg merged 1 commit into
masterfrom
fix/energy-dispatch-pi-setpoint
Apr 17, 2026
Merged

frahlg merged 1 commit into
masterfrom
fix/energy-dispatch-pi-setpoint

Conversation

@frahlg

@frahlg frahlg commented Apr 17, 2026

Copy link
Copy Markdown
Member

Addresses the P1 Codex raised on #79 — #79 (comment)...

What was wrong

The energy-dispatch branch in ComputeDispatch zeroed GridTargetW with a direct assignment and called PI.Reset() (which only clears the integral, not the setpoint). If the operator later left a planner mode, the legacy PI path would compute error = PI.Setpoint - gridW against a stale setpoint while deadband / error checks used the synced GridTargetW=0. Result: the controller could issue no correction when one was needed, or the wrong correction, until another explicit SetGridTarget call happened.

Fix

One-liner: state.GridTargetW = 0 → state.SetGridTarget(0). The helper updates both fields in lockstep, same pattern as every other caller in the package.

Test

Pre-poisons PI.Setpoint + GridTargetW = 3000, runs one energy-dispatch cycle, asserts both are 0 afterward. Fails cleanly before the fix, passes after.

Test plan

  • Go unit tests green (go test ./...).
  • CI passes.

🤖 Generated with Claude Code

The energy-dispatch branch in ComputeDispatch was setting GridTargetW=0
via direct assignment and calling PI.Reset() (which only zeros the
integral, not the setpoint). Result: if the operator later left a
planner mode — e.g. via POST /api/mode — the legacy PI path would
compute error against a stale PI.Setpoint while deadband/error checks
used GridTargetW=0. Under those conditions the controller could issue
no correction when one was needed (or the wrong correction).

Use SetGridTarget(0) so both fields move in lockstep. This mirrors
every other caller in the package.

Regression test pre-poisons PI.Setpoint + GridTargetW to 3000, runs one
energy-dispatch cycle, and asserts both are 0 afterward.

Caught by Codex on PR #79.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit ae5ab72 into master Apr 17, 2026
1 check passed
@frahlg
frahlg deleted the fix/energy-dispatch-pi-setpoint branch April 17, 2026 11:19
frahlg added a commit that referenced this pull request Nov 17, 2026
The worker keeps a battery that may not cover the car out of the car's
import room (srcfl/energyplan#83 for the library, #84 for the fleet
model that plans every request where a car can charge), the rule Core
enforces since #2023. The binaries are byte-identical to the ones
Energyplan's local CI tested on 55118a38, which has the same tree as
7ea7d998.

A native test plans the field night with the bundled worker and needs
Core to accept the plan. With the bundle it replaces (847936a) Core
rejects the plan in slot 0.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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