JavaScript PID controller

I suppose this is the first time programing topic came up on this blog. Probably not the last time, since this is what I do most of the time.

While working on serial port usage balancing for INAV Configurator I’ve quite accidentally created a PID controller in JavaScript. Maybe it’s not the most advanced PID controller ever, but has all the things required:

  • computes P-term
  • computes I-term
  • computes D-term
  • has output limiting
  • has I-term accumulator limiting

Without further ado

Example usage:

In the example above, PID controller was configured with following settings:

  • Target value: 1.5
  • Gains: P = 16, I = 6, D = 4
  • Output limited at 0 and 97
  • I-term accumulator limited at 0 and 90

Then, to compute controller output privateScope.loadPidController.run(currentValue);

Remark: this is negative feedback output PID controller. That means, its output should me used as dampening factor for the system. It acts like a brake. To work as positive feedback, it’s output should be reversed.

Leave a Reply

Your email address will not be published.