pub struct SimSensor { /* private fields */ }Expand description
A fake sensor that generates a signal from a baseline, drift, and noise.
This is the workhorse for hardware-free development: it implements the core
Sensor trait, so it drops into a Node, a profile, or any test exactly where
a real probe would, and it produces readings that look like the field rather than
a clean constant. A reading is the baseline plus any accumulated drift plus a
bounded pseudo-random wobble, so a control loop can be exercised against a signal
that warms, sags, or jitters the way a real one does.
The noise is deterministic for a given seed - a small xorshift generator drives
it, with no rand dependency - so a test that uses a SimSensor produces the
same sequence every run and stays reproducible in CI.
§Examples
A noisy thermometer that warms by 0.1 degrees each reading:
use pamoja_core::Sensor;
use pamoja_sim::SimSensor;
let mut probe = SimSensor::new(20.0).with_drift(0.1).with_noise(0.05).with_seed(7);
let first = probe.read().await?;
assert!((first - 20.0).abs() <= 0.05); // the first reading sits near the baselineImplementations§
Source§impl SimSensor
impl SimSensor
Sourcepub fn new(baseline: f32) -> Self
pub fn new(baseline: f32) -> Self
Creates a sensor that reads baseline with no drift or noise.
§Arguments
baseline- the value the sensor reads before drift and noise are added.
§Returns
A steady sensor; add with_drift and
with_noise to make it lifelike.