pamoja_sim/lib.rs
1//! Hardware-free device simulators for the pamoja SDK.
2//!
3//! The SDK is meant to be built and tested with no hardware at all, and that promise
4//! only holds if there are convincing stand-ins for the parts a device would have.
5//! This crate provides those stand-ins as ordinary implementations of the core
6//! [`Sensor`](pamoja_core::Sensor) and [`Actuator`](pamoja_core::Actuator) traits, so
7//! they drop into a `Node`, a profile, or a test exactly where a real driver will go
8//! once the hardware-I/O layer lands:
9//!
10//! - [`SimSensor`] - a fake sensor that generates a lifelike signal from a baseline,
11//! a drift, and bounded, seedable noise, so a control loop meets the kind of messy
12//! input it will see in the field.
13//! - [`Replay`] - a fake sensor that plays back an exact sequence of readings, for
14//! deterministic tests and scripted demos.
15//! - [`RecordingActuator`] - a fake actuator that logs every command instead of
16//! driving hardware, so a test can assert what a control loop decided to do.
17//! - [`DegradedLink`] - a [`Transport`](pamoja_core::Transport) decorator that
18//! simulates a lossy and intermittent radio link, so offline-first store-and-
19//! forward can be proven against a realistic bad network rather than assumed.
20//! - [`SimRobot`] - a hardware-free differential-drive robot driven by a `Twist` and read back as
21//! a `Pose`, so a robot control loop can be developed and tested with no robot.
22//!
23//! # Examples
24//!
25//! Drive a recording relay from a scripted probe, with no hardware:
26//!
27//! ```
28//! use pamoja_core::{Actuator, Sensor};
29//! use pamoja_sim::{RecordingActuator, Replay};
30//!
31//! # async fn demo() -> pamoja_core::Result<()> {
32//! let mut probe = Replay::new(vec![3.0, 7.0]);
33//! let mut relay = RecordingActuator::new();
34//! let log = relay.log();
35//!
36//! // Switch the relay on whenever the probe reads warm.
37//! while let Ok(reading) = probe.read().await {
38//! relay.apply(reading > 5.0).await?;
39//! }
40//!
41//! assert_eq!(log.commands(), vec![false, true]);
42//! # Ok(())
43//! # }
44//! ```
45
46mod actuator;
47mod link;
48mod robot;
49mod sensor;
50
51pub use actuator::{ActuatorLog, RecordingActuator};
52pub use link::DegradedLink;
53pub use robot::SimRobot;
54pub use sensor::{Replay, SimSensor};