3-phase PV router
Loading...
Searching...
No Matches
RelayEngine< N, D > Class Template Reference

Manages a collection of relays and their behavior based on surplus and import thresholds. More...

#include <utils_relay.h>

Collaboration diagram for RelayEngine< N, D >:

Public Member Functions

constexpr RelayEngine (const relayOutput(&ref)[N])
 Construct a list of relays.
 
constexpr RelayEngine (integral_constant< uint8_t, D > ic, 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.
 
constexpr auto get_size () const
 Get the number of relays.
 
void inc_duration () const
 Increment the duration's state of each relay.
 
void printConfiguration () const
 Print the configuration of each relay.
 
void proceed_relays () const
 Proceed all relays in increasing order (surplus) or decreasing order (import).
 

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_SECONDSewma_average
 

Detailed Description

template<uint8_t N, uint8_t D = 10>
class RelayEngine< N, D >

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.

Template Parameters
NThe number of relays to be managed.
DThe duration in minutes for the sliding average (default is 10 minutes).
  • 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.
  • Initialization: Provides methods to initialize relay pins and print their configuration.

Definition at line 278 of file utils_relay.h.

Constructor & Destructor Documentation

◆ RelayEngine() [1/2]

template<uint8_t N, uint8_t D = 10>
RelayEngine< N, D >::RelayEngine ( const relayOutput(&) ref[N])
inlineexplicitconstexpr

Construct a list of relays.

Definition at line 285 of file utils_relay.h.

◆ RelayEngine() [2/2]

template<uint8_t N, uint8_t D = 10>
RelayEngine< N, D >::RelayEngine ( integral_constant< uint8_t, D > ic,
const relayOutput(&) ref[N] )
inlineconstexpr

Construct a list of relays with a custom sliding average.

Parameters
icIntegral constant representing the sliding average duration.
refArray of relay configurations.

Definition at line 296 of file utils_relay.h.

Member Function Documentation

◆ get_average()

template<uint8_t N, uint8_t D = 10>
static auto RelayEngine< N, D >::get_average ( )
inlinestatic

Get the current average.

Returns
auto The current average

Definition at line 327 of file utils_relay.h.

◆ get_relay()

template<uint8_t N, uint8_t D = 10>
const auto & RelayEngine< N, D >::get_relay ( uint8_t idx) const
inlineconstexpr

Get the relay object.

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

Definition at line 317 of file utils_relay.h.

◆ get_size()

template<uint8_t N, uint8_t D = 10>
auto RelayEngine< N, D >::get_size ( ) const
inlineconstexpr

Get the number of relays.

Returns
constexpr auto The number of relays

Definition at line 306 of file utils_relay.h.

◆ inc_duration()

template<uint8_t N, uint8_t D>
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 423 of file utils_relay.h.

◆ printConfiguration()

template<uint8_t N, uint8_t D = 10>
void RelayEngine< N, D >::printConfiguration ( ) const
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 403 of file utils_relay.h.

◆ proceed_relays()

template<uint8_t N, uint8_t D = 10>
void RelayEngine< N, D >::proceed_relays ( ) const
inline

Proceed all relays in increasing order (surplus) or decreasing order (import).

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.

Definition at line 361 of file utils_relay.h.

◆ update_average()

template<uint8_t N, uint8_t D = 10>
static void RelayEngine< N, D >::update_average ( int16_t currentPower)
inlinestatic

Update the sliding average.

Parameters
currentPowerCurrent power at the grid

Definition at line 337 of file utils_relay.h.

Member Data Documentation

◆ ewma_average

template<uint8_t N, uint8_t D = 10>
EWMA_average< D * 60 / DATALOG_PERIOD_IN_SECONDS > RelayEngine< N, D >::ewma_average
inlinestaticprivate

EWMA average

Definition at line 420 of file utils_relay.h.

◆ relay

template<uint8_t N, uint8_t D = 10>
const relayOutput RelayEngine< N, D >::relay[N]
private

Array of relays

Definition at line 416 of file utils_relay.h.

◆ settle_change

template<uint8_t N, uint8_t D = 10>
uint8_t RelayEngine< N, D >::settle_change { 60 }
mutableprivate

Delay in seconds until next change occurs

Definition at line 418 of file utils_relay.h.


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