3-phase PV router
Loading...
Searching...
No Matches
RelayLogic::Engine< R, N, D > Class Template Reference

A collection of relays, switched one at a time from a sliding average. More...

#include <relay_engine.h>

Inheritance diagram for RelayLogic::Engine< R, N, D >:
Collaboration diagram for RelayLogic::Engine< R, N, D >:

Public Member Functions

constexpr Engine (const R(&ref)[N])
 Construct a list of relays.
 
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 proceed_relays (const uint16_t overrideBitmask, const bool diversionEnabled=true) const
 Proceed all relays: OFF in decreasing order, ON in increasing order.
 
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.
 

Protected Attributes

const R relay [N]
 

Private Member Functions

template<uint8_t... I>
constexpr Engine (const R(&ref)[N], index_sequence< I... >)
 Copies each relay of ref: an array cannot be initialized from another.
 

Private Attributes

uint8_t settle_change { 60 }
 

Static Private Attributes

static EWMA_average< D *60/DATALOG_PERIOD_IN_SECONDS > ewma_average
 

Detailed Description

template<typename R, uint8_t N, uint8_t D>
class RelayLogic::Engine< R, N, D >

A collection of relays, switched one at a time from a sliding average.

Template Parameters
RThe relay type: a Relay<>, or a type derived from one.
NThe number of relays to be managed.
DThe duration in minutes for the sliding average.
  • Relay Management: Handles the state of multiple relays, turning them ON or OFF based on surplus and import thresholds.
  • Sliding Average: Uses an Exponentially Weighted Moving Average (EWMA) to calculate the average power over a configurable duration.
  • State Transitions: Ensures stable operation by enforcing minimum ON/OFF durations and a delay between state changes.

Definition at line 314 of file relay_engine.h.

Constructor & Destructor Documentation

◆ Engine() [1/2]

template<typename R, uint8_t N, uint8_t D>
RelayLogic::Engine< R, N, D >::Engine ( const R(&) ref[N])
inlineexplicitconstexpr

Construct a list of relays.

Parameters
refArray of relay configurations.

Definition at line 322 of file relay_engine.h.

◆ Engine() [2/2]

template<typename R, uint8_t N, uint8_t D>
template<uint8_t... I>
RelayLogic::Engine< R, N, D >::Engine ( const R(&) ref[N],
index_sequence< I... >  )
inlineconstexprprivate

Copies each relay of ref: an array cannot be initialized from another.

Definition at line 447 of file relay_engine.h.

Member Function Documentation

◆ get_average()

template<typename R, uint8_t N, uint8_t D>
static auto RelayLogic::Engine< R, N, D >::get_average ( )
inlinestatic

Get the current average.

Returns
auto The current average

Definition at line 353 of file relay_engine.h.

◆ get_relay()

template<typename R, uint8_t N, uint8_t D>
const auto & RelayLogic::Engine< R, N, D >::get_relay ( uint8_t idx) const
inlineconstexpr

Get the relay object.

Parameters
idxThe index of the relay
Returns
constexpr const auto& The relay object

Definition at line 343 of file relay_engine.h.

◆ inc_duration()

template<typename R, uint8_t N, uint8_t D>
void RelayLogic::Engine< R, 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 458 of file relay_engine.h.

◆ proceed_relays()

template<typename R, uint8_t N, uint8_t D>
void RelayLogic::Engine< R, N, D >::proceed_relays ( const uint16_t overrideBitmask,
const bool diversionEnabled = true ) const
inline

Proceed all relays: OFF in decreasing order, ON in increasing order.

Parameters
overrideBitmaskOverride bitmask (local pins): a relay is forced ON while its bit is set
diversionEnabledWhether diversion is enabled - if false, only the forced relays are ON

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. On a surplus too, a relay in battery mode (negative import threshold) that goes OFF does so in decreasing order, before any relay comes in. When diversion is disabled, the relays that are not forced are turned OFF. The minimum ON and OFF times, and the settle time after any change, always apply.

Definition at line 394 of file relay_engine.h.

◆ size()

template<typename R, uint8_t N, uint8_t D>
auto RelayLogic::Engine< R, N, D >::size ( ) const
inlineconstexpr

Get the number of relays.

Returns
constexpr auto The number of relays

Definition at line 332 of file relay_engine.h.

◆ update_average()

template<typename R, uint8_t N, uint8_t D>
static void RelayLogic::Engine< R, N, D >::update_average ( int16_t currentPower)
inlinestatic

Update the sliding average.

Parameters
currentPowerCurrent power at the grid

Definition at line 363 of file relay_engine.h.

Member Data Documentation

◆ ewma_average

template<typename R, uint8_t N, uint8_t D>
EWMA_average< D * 60 / DATALOG_PERIOD_IN_SECONDS > RelayLogic::Engine< R, N, D >::ewma_average
inlinestaticprivate

EWMA average

Definition at line 455 of file relay_engine.h.

◆ relay

template<typename R, uint8_t N, uint8_t D>
const R RelayLogic::Engine< R, N, D >::relay[N]
protected

Array of relays

Definition at line 442 of file relay_engine.h.

◆ settle_change

template<typename R, uint8_t N, uint8_t D>
uint8_t RelayLogic::Engine< R, N, D >::settle_change { 60 }
mutableprivate

Delay in seconds until next change occurs

Definition at line 453 of file relay_engine.h.


The documentation for this class was generated from the following file: