roo_control
API Documentation for roo_control
Loading...
Searching...
No Matches
roo_control::InertSwitch< StateT > Class Template Reference

Switch that adds inertia between state changes on top of a raw actuator. More...

#include <inert_switch.h>

Inheritance diagram for roo_control::InertSwitch< StateT >:
[legend]
Collaboration diagram for roo_control::InertSwitch< StateT >:
[legend]

Public Types

using State = StateT
 

Public Member Functions

 InertSwitch (roo_scheduler::Scheduler &scheduler, Switch< StateT > &actuator, roo_time::Duration inertia=roo_time::Millis(500))
 
virtual ~InertSwitch ()=default
 
bool getState (State &result) const override
 Returns the actual state the switch is currently at.
 
bool getIntendedState (State &state) const
 Returns the state that the switch has been requested to take.
 
bool setState (State state) override
 Sets the intended state of the switch.
 
bool hasPendingChange () const
 Returns true if a deferred update is pending.
 
roo_time::Uptime whenSwitched () const
 Returns the time of last actual state change.
 
roo_time::Duration intertia () const
 Returns the inertia interval.
 
- Public Member Functions inherited from roo_control::Switch< StateT >
virtual ~Switch ()=default
 
- Public Member Functions inherited from roo_control::Selector< State >
virtual ~Selector ()=default
 
virtual bool getState (State &result) const =0
 Retrieves the current state, or returns false when it cannot be read.
 

Protected Member Functions

virtual void stateChanged () const
 Can be overridden to receive state change notifications.
 

Detailed Description

template<typename StateT>
class roo_control::InertSwitch< StateT >

Switch that adds inertia between state changes on top of a raw actuator.

Useful to counter-act bouncing that could damage physical relays.

This switch provides some degree of fault tolerance: as long as the actuator reports false from setState(), the inert switch will keep retrying calling it. (You can specify a retry policy for doing so; the default policy is a randomized exponential backoff). However, when the actuator reports true from setState(), the inert switch trusts it to enforce the setting.

If you need stronger fault tolerance, e.g. when the switch is remotely controlled, consider using a FaultTolerantSwitch.

Definition at line 25 of file inert_switch.h.

Member Typedef Documentation

◆ State

Definition at line 27 of file inert_switch.h.

Constructor & Destructor Documentation

◆ InertSwitch()

template<typename StateT >
roo_control::InertSwitch< StateT >::InertSwitch ( roo_scheduler::Scheduler &  scheduler,
Switch< StateT > &  actuator,
roo_time::Duration  inertia = roo_time::Millis(500) 
)
inline

Definition at line 29 of file inert_switch.h.

◆ ~InertSwitch()

template<typename StateT >
virtual roo_control::InertSwitch< StateT >::~InertSwitch ( )
virtualdefault

Member Function Documentation

◆ getIntendedState()

template<typename StateT >
bool roo_control::InertSwitch< StateT >::getIntendedState ( State state) const
inline

Returns the state that the switch has been requested to take.

The actual state may lag behind due to inertia. Returns false if the intended state has never been set yet.

Definition at line 52 of file inert_switch.h.

◆ getState()

template<typename StateT >
bool roo_control::InertSwitch< StateT >::getState ( State result) const
inlineoverride

Returns the actual state the switch is currently at.

Definition at line 44 of file inert_switch.h.

◆ hasPendingChange()

template<typename StateT >
bool roo_control::InertSwitch< StateT >::hasPendingChange ( ) const
inline

Returns true if a deferred update is pending.

Definition at line 99 of file inert_switch.h.

◆ intertia()

template<typename StateT >
roo_time::Duration roo_control::InertSwitch< StateT >::intertia ( ) const
inline

Returns the inertia interval.

Definition at line 105 of file inert_switch.h.

◆ setState()

template<typename StateT >
bool roo_control::InertSwitch< StateT >::setState ( State  state)
inlineoverridevirtual

Sets the intended state of the switch.

If the intended state of the switch was already set to the same value, returns immediately. Otherwise, if the last state change was more ago than the inertia interval, the state change is immediately attempted by calling setState() on the actuator. Otherwise, the state change attempt is scheduled to occur after the inertia interval since the last change.

In case that setting the state fails, a retry is scheduled, according to the retry policy specified at creation time (by default, a randomized exponential backoff, truncated at 5s). The retries continue until actuator.setState() returns true.

Implements roo_control::Switch< StateT >.

Definition at line 70 of file inert_switch.h.

References roo_control::InertSwitch< StateT >::stateChanged().

◆ stateChanged()

template<typename StateT >
virtual void roo_control::InertSwitch< StateT >::stateChanged ( ) const
inlineprotectedvirtual

Can be overridden to receive state change notifications.

Triggers when either the intended state changes, or setState() on the actuator succeeds (confirming update request of the actual state), or both.

Definition at line 113 of file inert_switch.h.

Referenced by roo_control::InertSwitch< StateT >::setState().

◆ whenSwitched()

template<typename StateT >
roo_time::Uptime roo_control::InertSwitch< StateT >::whenSwitched ( ) const
inline

Returns the time of last actual state change.

Definition at line 102 of file inert_switch.h.


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