npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

awesome-pid

v1.0.3

Published

A PID controller with built-in looping functionality.

Downloads

40

Readme

awesome-pid

A PID controller with built-in looping functionality.

Installation

$ npm install awesome-pid

Creating awesome-pid object with options

var PID = require('awesome-pid');
var options = {
  kp: 0.5,
  ki: 0.05,
  kd: 0.1,
  dt: 300,  // milliseconds
  initial: 0,
  target: 100,
  u_bound: 30,
  l_bound: -30
}

var testPID = new PID(options);

Parameters

Options

Property | Type | Description | Default -------- | ---- | ----------- | ------- kp | Number | Proportional gain | 0 ki | Number | Integral gain | 0 kd | Number | Derivative gain | 0 dt | Number | Time interval in milliseconds | 1000 initial | Number | Initial input value | 0 target | Number | Target value | 0 u_bound | Number | Output upper bound | l_bound | Number | Output lower bound |

Functions and Accessors

Option parameters can be used (above), or each value can be set individually.

var PID = require('awesome-pid');

var testPID = new PID();

// Set kp, ki, kd values respectively
testPID.setTuning(0.5, 0.05, 0.1);
console.log('kp: ' + testPID.kp + ' | ki: ' + testPID.ki + ' | kd: ' + testPID.kd);
// => kp: 0.5 | ki: 0.05 | kd: 0.1

// Set time interval (dt) in ms
testPID.setTimeInterval(300);
console.log('dt: ' + testPID.dt);
// => dt: 300

// Set input value
testPID.setInput(10);
console.log('Input: ' + testPID.input);
// => Input: 10

// Set target value
testPID.setTarget(100);
console.log('Target: ' + testPID.target);
// => Target: 100

// Set upper bound of output
testPID.setUBound(20);
// Set lower bound of output
testPID.setLBound(-20);
console.log('ubound: ' + testPID.u_bound + ' | lbound: ' + testPID.l_bound);
// => ubound: 20 | lbound: -20

// Reset PID
testPID.reset();

Example

var PID = require('awesome-pid');
var currentValue = 0;
var targetValue = 100;

var options = {
  kp: 0.5,
  ki: 0.05,
  kd: 0.1,
  dt: 300,  // milliseconds
  initial: currentValue,
  target: targetValue,
  u_bound: 30,
  l_bound: -30
}

var testPID = new PID(options);

console.log('Starting loop...');
testPID.startLoop();

// Will be emitted every dt milliseconds
testPID.on("output", function(output) {
  currentValue += output;
  var val = parseInt(currentValue);
  console.log('Output: '  + parseFloat(output).toFixed(2) + ' | Value: ' + parseFloat(currentValue).toFixed(2));
  this.setInput(currentValue);

  // Stop and exit function once integer value of current value is equal to target value.
  if (val === targetValue ) {
    this.stopLoop();
    console.log('Current value equal to target value.  Stop loop and exit program.');
  }
});