3-phase PV router
|
Manages a collection of relays and their behavior based on surplus and import thresholds. More...
#include <utils_relay.h>
Public Member Functions | |
constexpr | RelayEngine (const relayOutput(&ref)[N]) |
Construct a list of relays. | |
constexpr | RelayEngine (integral_constant< uint8_t, D >, const relayOutput(&ref)[N]) |
Construct a list of relays with a custom sliding average. | |
constexpr const auto & | get_relay (uint8_t idx) const |
Get the relay object. | |
void | inc_duration () const |
Increment the duration's state of each relay. | |
void | printRelayEngineConfiguration () const |
Print the configuration of each relay. | |
void | proceed_relays (uint16_t &overrideBitmask) const |
Proceed all relays in increasing order (surplus) or decreasing order (import). | |
constexpr auto | size () const |
Get the number of relays. | |
Static Public Member Functions | |
static auto | get_average () |
Get the current average. | |
static void | update_average (int16_t currentPower) |
Update the sliding average. | |
Private Attributes | |
const relayOutput | relay [N] |
uint8_t | settle_change { 60 } |
Static Private Attributes | |
static EWMA_average< D *60/DATALOG_PERIOD_IN_SECONDS > | ewma_average |
Manages a collection of relays and their behavior based on surplus and import thresholds.
The RelayEngine
class provides functionality to manage multiple relays, including their initialization, state transitions, and configuration. It uses a sliding average to determine the current power state and adjusts the relays accordingly.
N | The number of relays to be managed. |
D | The duration in minutes for the sliding average (default is 10 minutes). |
Definition at line 314 of file utils_relay.h.
|
inlineexplicitconstexpr |
Construct a list of relays.
Definition at line 321 of file utils_relay.h.
|
inlineconstexpr |
Construct a list of relays with a custom sliding average.
ic | Integral constant representing the sliding average duration. |
ref | Array of relay configurations. |
Definition at line 332 of file utils_relay.h.
|
inlinestatic |
Get the current average.
Definition at line 363 of file utils_relay.h.
|
inlineconstexpr |
Get the relay object.
idx | The index of the relay |
Definition at line 353 of file utils_relay.h.
void RelayEngine< N, D >::inc_duration | ( | ) | const |
Increment the duration's state of each relay.
This method updates the duration of the current state for each relay and decreases the delay (settle_change
) until the next state change is allowed.
Definition at line 462 of file utils_relay.h.
|
inline |
Print the configuration of each relay.
This method outputs the configuration of all relays, including their pin assignments, thresholds, and minimum ON/OFF durations, to the Serial interface.
Definition at line 442 of file utils_relay.h.
|
inline |
Proceed all relays in increasing order (surplus) or decreasing order (import).
overrideBitmask | Reference to override bitmask - relay bits will be cleared after processing |
This method adjusts the state of the relays based on the current average power. If surplus power is available, it tries to turn ON relays in increasing order. If power is being imported, it tries to turn OFF relays in decreasing order. Override bits for individual relays are handled and cleared during processing.
Definition at line 400 of file utils_relay.h.
|
inlineconstexpr |
Get the number of relays.
Definition at line 342 of file utils_relay.h.
|
inlinestatic |
Update the sliding average.
currentPower | Current power at the grid |
Definition at line 373 of file utils_relay.h.
|
inlinestaticprivate |
EWMA average
Definition at line 459 of file utils_relay.h.
|
private |
Array of relays
Definition at line 455 of file utils_relay.h.
|
mutableprivate |
Delay in seconds until next change occurs
Definition at line 457 of file utils_relay.h.