Crates.io | equilibrium |
lib.rs | equilibrium |
version | 0.1.0-alpha |
source | src |
created_at | 2024-02-01 12:49:07.477479 |
updated_at | 2024-02-01 12:49:07.477479 |
description | A framework for creating distributed control systems |
homepage | |
repository | https://github.com/PoorRican/equilibrium |
max_upload_size | |
id | 1123083 |
size | 80,763 |
equilibrium is a framework for creating distributed control systems.
It provides a several types of control system paradigms and is agnostic to the underlying hardware. The intention is to provide a framework that can be used in a variety of applications such as aquaponics/hydroponics, aquariums, homebrewing, bioreactors and more.
This example creates 2 controllers:
Then a runtime is created which polls the controllers every second. The output of the controllers are messages which are sent to a message broker operating on localhost.
use chrono::{Duration, NaiveTime, Utc};
use equilibrium::controllers::{Controller, TimedOutput, Threshold};
use equilibrium::{Output, Input, ControllerGroup};
#[tokio::main]
fn main() {
// this represents a grow-light
let time = NaiveTime::from_hms_opt(5, 0, 0).unwrap();
let duration = Duration::hours(8);
let mut grow_light = TimedOutput::new(
Output::new(|_| {
// low-level code would go here
}),
time,
duration,
);
// this represents a heater controller
let min_temp = 70.0; // activate heater when temp is below 70 degrees
let interval = Duration::minutes(5); // check temp every 5 minutes
let heater = Output::new(|_| {
// low-level code would go here
});
let temp_sensor = Input::new(|| {
// low-level code would go here
String::from("79.0")
});
let mut heater_controller = Threshold::new(
min_temp,
temp_sensor,
heater,
interval
);
// a group can be used to manage multiple controllers
let mut group = ControllerGroup::new()
.add_controller(grow_light)
.add_controller(heater_controller);
// create a runtime which polls every second and build an emitter
let runtime = Runtime::new(
group,
chrono::Duration::seconds(1)
).build_emitter("http://localhost:8000");
}
TimedOutput
: turns on an output at a specific time and turns it off after a durationThreshold
: turns on an output when a threshold is metBidirectionalThreshold
: increases or decreases an output when a threshold is metMore controller types (i.e.: PID) will be added in the future.
Currently, only binary output devices are supported.