Repository navigation
feat(sim): simulate relay diversion - #176
Merged
Merged
Conversation
grid_sim gets relay loads: `relay <pin> <phase> <W>` follows its pin at once, with no zero-crossing latching. For every load it now tracks the shortest complete ON and OFF periods, reported for relays, and checked with `expect min_on|min_off <pin> <s>`; `expect switches <pin> <min> <max>` counts switch-ons. configs/relays.patch builds the firmware with two relays on D8 and D9 (1000 / 2000 W of export to come in, 200 W of import to go out, 2 minutes minimum ON and OFF, 1-minute filter), in .pio/build-relays so the basic firmware stays. The minimum times are longer than the 1-minute settle time after any relay change: with equal ones, a firmware ignoring them passed. Without them, relay_min_times now fails. scenarios/relays (make check-relays, a CI job of its own): - relay_steps: in by threshold, each once; out in reverse order, a settle time apart - relay_min_times: held ON through an import, then OFF through a returning surplus, for the minimum times - relay_import_first: import is cut first - relay 1 goes out before relay 2 while relay 2 is within its minimum ON time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The relay job set the CI time (3 min, against 2 for the grid one). It moves to relay-sim.yml, which runs on pull requests only when something the relays depend on changes - relay engine, filter, pin writes, the power they decide on, configuration, the simulator - and on every push to main and dev. The scenarios end shortly after their last event: 1185 s simulated instead of 1300. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
grid_sim now simulates relay diversion, with three scenarios run against a firmware with two relays.
grid_sim
relay <pin> <phase> <W>: a resistive load on a relay - it follows its pin at once, with no zero-crossing latching.expect switches <pin> <min> <max>,expect min_on <pin> <s>,expect min_off <pin> <s>.Firmware:
configs/relays.patchTwo relays on D8 and D9: in at 1000 / 2000 W of export, out above 200 W of import, 2 minutes minimum ON and OFF, a 1-minute filter. Built in
.pio/build-relays(PLATFORMIO_BUILD_DIR), so thebasicfirmware ofmake checkstays.The minimum times are longer than the 1-minute settle time the relay engine waits after any change. With 1-minute minimums, the settle time alone produced the very same holds, and a firmware ignoring the minimum times passed
relay_min_times. Checked: such a mutant now fails bothrelay_stepsandrelay_min_times(it lets go after 91 s instead of 120 s).Scenarios (
make check-relays)relay_stepsrelay_min_timesrelay_import_first24 expectations; the three scenarios take ~80 s in parallel. They run in a CI job of their own, "Grid simulation (relays)", alongside the existing one, which does not get longer.
Test plan
relay_stepsandrelay_min_timesmake checkunchanged (30/30)🤖 Generated with Claude Code