|
roo_control
API Documentation for roo_control
|
Switch that adds inertia between state changes on top of a raw actuator. More...
#include <inert_switch.h>
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. | |
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.
Definition at line 27 of file inert_switch.h.
|
inline |
Definition at line 29 of file inert_switch.h.
|
virtualdefault |
|
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.
|
inlineoverride |
Returns the actual state the switch is currently at.
Definition at line 44 of file inert_switch.h.
|
inline |
Returns true if a deferred update is pending.
Definition at line 99 of file inert_switch.h.
|
inline |
Returns the inertia interval.
Definition at line 105 of file inert_switch.h.
|
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().
|
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().
|
inline |
Returns the time of last actual state change.
Definition at line 102 of file inert_switch.h.