# node-pid-controller

> Node.js PID controller

Latest version **1.0.1** (published 2018-03-19) · BSD license · 0 weekly downloads

## Install

```sh
npm install node-pid-controller
pnpm add node-pid-controller
yarn add node-pid-controller
bun add node-pid-controller
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-03-19 |
| First published | 2013-06-14 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= v4.0.0 |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 129 |
| Author | Philmod |
| Maintainers | philmod |
| Keywords | pid, controller, robotic, drone, system |

## Links

- npm: https://www.npmjs.com/package/node-pid-controller
- Repository: https://github.com/Philmod/node-pid-controller
- Homepage: http://github.com/philmod/node-pid-controller
- Issues: https://github.com/Philmod/node-pid-controller/issues
- npm.io page: https://npm.io/package/node-pid-controller

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-03-19
- 1.0.0 — 2016-04-01
- 0.1.2 — 2015-11-03
- 0.1.1 — 2015-06-17
- 0.0.3 — 2013-06-14
- 0.0.2 — 2013-06-14
- 0.0.1 — 2013-06-14

## README

# node-pid-controller

Simple Node.js PID controller.

![pid](http://upload.wikimedia.org/wikipedia/commons/9/91/PID_en_updated_feedback.svg)

## 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

`k_p`, `k_i` and `k_d` are the proportional, integral and derivative terms. `dt` is the interval of time between two measures. If not set, it will be automatically calculated.

```js
let Controller = require('node-pid-controller');

let ctr = new Controller({
  k_p: 0.25,
  k_i: 0.01,
  k_d: 0.01,
  dt: 1
});
```

You can also pass options as arguments:
```js
let ctr = new Controller(0.25, 0.01, 0.01, 1); // k_p, k_i, k_d, dt
```

### Set the target

```js
ctr.setTarget(120); // 120km/h
```

### Get the correction

```js
let correction = ctr.update(110); // 110km/h is the current speed
```

### Real example

Normally, you use the correction to a measure, in a closed loop.

```js
let goalReached = false
while (!goalReached) {
  let output = measureFromSomeSensor();
  let input  = ctr.update(output);
  applyInputToActuator(input);
  goalReached = (input === 0) ? true : false; // in the case of continuous control, you let this variable 'false'
}
```

## Options

* `k_p`, `k_i`, `k_d`: the PID's coefficients
* `dt`: interval of time (in seconds) between two measures. If not provided, it will be automatically calculated.
* `i_max`: the maximum absolute value of the integral term (optional)

## Test

```js
mocha test
```

## Author

Philmod &lt;philippe.modard@gmail.com&gt;

---
_Source: https://npm.io/package/node-pid-controller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
