From: Robin Krens Date: Wed, 24 Jan 2024 10:25:36 +0000 (+0100) Subject: add derivative measurement option X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=fcba5c82e722c3c95db85c6d36ff4af6c358eaa5;p=xy-pid-controller add derivative measurement option --- diff --git a/src/menu.js b/src/menu.js index f78a5be..fcc58bc 100644 --- a/src/menu.js +++ b/src/menu.js @@ -20,6 +20,13 @@ function initMenu(pid) pid.PIDParams, "integralGain", {min: 0, max: 10, step: 0.1} ); + pidSettings.addInput( + pid.PIDParams, "derivativeMeasurement", { + options: { + error: "Error", + velocity: "Velocity" + } + }); pane.addMonitor(pid.PIDParams, "force", { title: "Force (N)", view: "graph", diff --git a/src/pid-controller.js b/src/pid-controller.js index 31240a5..f225098 100644 --- a/src/pid-controller.js +++ b/src/pid-controller.js @@ -4,7 +4,7 @@ class PIDController { // ErrorRateOfChange //} constructor() { - this.PIDParams = {proportionalGain: 2, integralGain: 0.0, derivativeGain: 2, iMin: -1, iMax: 1, integralSaturation: false, derivativeInitialized: false, outputMax: 1, outputMin: -1, magnitude: 10, force: 0}; + this.PIDParams = {proportionalGain: 2, integralGain: 0.0, derivativeGain: 2, iMin: -1, iMax: 1, integralSaturation: false, derivativeInitialized: false, outputMax: 1, outputMin: -1, magnitude: 10, force: 0, derivativeMeasurement: "Velocity"}; this.valueLast; this.errorLast; this.integrationStored = 0; @@ -34,11 +34,11 @@ class PIDController { var deriveMeasure = 0; if (this.derivativeInitialized) { - //if (derivativeMeasurement == DerivativeMeasurement.Velocity) { + if (this.PIDParams.derivativeMeasurement == "Velocity") { deriveMeasure = -valueRateOfChange; - //} else { - // deriveMeasure = errorRateOfChange; - //} + } else { + deriveMeasure = errorRateOfChange; + } } else { this.derivativeInitialized = true; }