JSPM

node-pid-controller

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9716
  • Score
    100M100P100Q131528F
  • License BSD

Node.js PID controller

Package Exports

  • node-pid-controller

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-pid-controller) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-pid-controller

Simple Node.js PID controller

pid

Installation

  $ npm install node-pid-controller

Example

Let's take the example of a car cruise control. We want the car driving at 120km/h.

Create a Controller instance

var Controller = require('node-pid-controller');
var ctr = new Controller(0.25, 0.01, 0.01); // k_p, k_i, k_d

Set the target

ctr.setTarget(120); // 120km/h

Get the correction

var correction = ctr.update(110); // 110km/h is the current speed

Real example

Normally, you use the correction to a measure, in a closed loop

var goalReached = false
while (!goalReached) {
  var output = measureFromSomeSensor();
  var input  = ctr.update(output);
  applyInputToActuator(input);
  goalReached = (input === 0) ? true : false; // in the case of continuous control, you let this variable 'false'
}

Test

mocha test

Author

Philmod <philippe.modard@gmail.com>