Giter VIP home page Giter VIP logo

node-pid-toolkit's Introduction

node-pid-toolkit

Flexible pluggable PID controller toolkit for node.

Most PID implementations are fairly opinionated in how they behave and what set of features to implement. PID-Toolkit aims to instead provide a framework to implement a PID using the particular mix ofbehaviours you want via middlewares.

Uh, what's a PID controller?

PID stands for Proportional, Integral, and Derivative. It's a type of controller that attempts to adjust a control to adjust an observed value (the "process variable") until it meets a target value (the "set point"). It does this by making the control output be proportional to the error (the gap between target and observed value), the rate of change of the error (the derivative) and the accumulated error over time (the integral).

You can, roughly speaking, visualise this as being proprtional to how wrong the value is (error), looking forwards at how rapidly we're correcting the error (the derivative), and looking backwards at how wrong we've been in the past (the integral).

Scaling to all three of these components compensates for short-comings in each.

That's the theory at least, in practice there's some complications with the naive simple approach and so there's various compensation techniques that eleborate on it, but there's no commonly-accepted "perfect" approach. That's where PID-Toolkit comes in: you can pick and choose which modifications to basic behaviour you wish to apply.

And because it's hard to visualise just what these changes do, it comes with an in-browser sandbox to visualise the effects as you toggle them on and off.

Install

Not on npm yet, so you'll have to download it the old fashioned way. FIXME: update once it's released.

Usage

const { PID } = require('pid');
const { Basic } = require('behaviours/basic');
const { SmoothValue } = require('behaviours/smooth-value');

let pid = new PID({
    t: 0,
    kP: 0.05,
    tI: 10,
    tD: 4,
    behaviours: [
        new Basic(),
        new SmoothValue({
            value: 'rateError',
            smoothFactor: 0.3
        }),
        new SmoothValue({
            'pV',
            smoothFactor: 0.5
        })
    ]
    );

// Value we want to target.
pid.sP = 100;

let timer = setInterval(() => {
    // Read this from your sensor
    let pV = measurementFromSomeSensor;
    let t = timeOfMeasurement; // defaults to performance.now() if not provided.

    let control = pid.update(pV, t);

    // control isn't clamped, and the value is largely meaningless based on the gain you provided
    // I personally tend to choose the gain so that it's meaningful on a -1.0..1.0 range,
    // and then map that to max controller input, but it's really up to you.
    someControl.setOutput(control);
}, 1000);

LICENSE

Distributed under an MIT license, terms in the LICENSE.md file in the root of the distribution.

node-pid-toolkit's People

Contributors

illusori avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.