add derivative measurement option
authorRobin Krens <robin@robinkrens.nl>
Wed, 24 Jan 2024 10:25:36 +0000 (11:25 +0100)
committerRobin Krens <robin@robinkrens.nl>
Wed, 24 Jan 2024 10:25:36 +0000 (11:25 +0100)
src/menu.js
src/pid-controller.js

index f78a5be..fcc58bc 100644 (file)
@@ -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",
index 31240a5..f225098 100644 (file)
@@ -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;
                }