1.0.0 • Published 4 years ago

@nanomatic/regulator v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Status License


📝 Table of Contents

🏁 Getting Started

Installing

npm i @nanomatic/regulator

Using

Example code below:

import { Hysteresis, Linear, PID, Regulator } from '@nanomatic/regulator';

let temperature = 0;

// Switch to hysteresis regulator
const regulator = new Regulator(new Hysteresis(10, 5));

// You can easly switch between different regulators with the same setpoint value
// Switch to linear regulator after 5s
setTimeout(() => regulator.regulator = new Linear(5, 15), 5000);

// Switch to PID regulator after 10s
setTimeout(() => {
    regulator.regulator = new PID(.5);
    setInterval(() => regulator.setpoint(Math.random() * 50), 5000);
}, 10000);

// Object simulation
setInterval(() => {
    temperature += regulator.output(temperature);
    // tslint:disable-next-line: no-console
    console.log(`${temperature.toFixed(2).padStart(5, ' ')} ℃  ➜  ${regulator.setpoint().toFixed(2).padStart(5, ' ')} ℃  (${regulator.toString()})`);
}, 100);

⛏️ Built With

✍️ Authors