pub struct Thermostat { /* private fields */ }Expand description
A hysteresis (bang-bang) controller for a single on/off actuator.
This is the controller behind “keep a temperature”. It switches a cooler or heater on and off to hold a reading near a setpoint. A deadband around the setpoint - the hysteresis - stops the output chattering when the reading hovers at the threshold, which protects relays and compressors that have a limited number of switching cycles in them.
§Examples
use pamoja_kit::Thermostat;
let mut fridge = Thermostat::cooling(4.0, 0.5);
assert!(fridge.update(5.0)); // above the deadband: the cooler runs
assert!(fridge.update(4.2)); // inside the deadband: it holds its state
assert!(!fridge.update(3.4)); // below the deadband: the cooler stopsImplementations§
Source§impl Thermostat
impl Thermostat
Sourcepub fn cooling(setpoint: f32, hysteresis: f32) -> Self
pub fn cooling(setpoint: f32, hysteresis: f32) -> Self
Creates a thermostat that drives a cooler, such as a fridge.
The output turns on when the reading reaches the top of the deadband and off when it reaches the bottom.
§Arguments
setpoint- the target reading. One that is not a number never switches.hysteresis- half the deadband width; its magnitude is used, and one that is not a number is taken as zero.
§Returns
A thermostat whose output starts off.
Sourcepub fn heating(setpoint: f32, hysteresis: f32) -> Self
pub fn heating(setpoint: f32, hysteresis: f32) -> Self
Creates a thermostat that drives a heater.
The output turns on when the reading reaches the bottom of the deadband and off when it reaches the top.
§Arguments
setpoint- the target reading. One that is not a number never switches.hysteresis- half the deadband width; its magnitude is used, and one that is not a number is taken as zero.
§Returns
A thermostat whose output starts off.
Sourcepub fn update(&mut self, reading: f32) -> bool
pub fn update(&mut self, reading: f32) -> bool
Updates the controller with a reading and returns whether the output is on.
A reading that is not a finite number, such as the NaN a failed probe reports, is ignored and the output stays as it was: a heater that was on stays on. A node that must fail safe checks the reading itself and decides what off means for its plant.
§Arguments
reading- the latest measured value.
§Returns
true if the cooler or heater should be running.
Trait Implementations§
Source§impl Clone for Thermostat
impl Clone for Thermostat
Source§fn clone(&self) -> Thermostat
fn clone(&self) -> Thermostat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more