setPID()
setPID(id,target)
Set PID target
Sets the target value for the PID.
The PID monitors the PIDs process value (PV) and adjusts the controlled output (CO) as needed to reach the configured target value.
PIDs are generally updated every 100ms. Ideally the process value error status should be monitored to ensure correct sensor fault handling. e.g.
if(io.waterPressure._err !== 0){ setPID(0,false); // Disable the PID from modifying the CO io.pumpSpeed = 55; // Manually set the CO to a safe operating value }
In practice it would be better to use the alm handling class for fault handling to ensure proper de-bouncing, recovery handling and logging.
e.g. ` alm.g("Pump 1");
let err = alm.e(alm.crit, // alarm priority "Pressure Transducer Failure", // alarm title
// alarm condition io.waterPressure._err !== 0 || io.waterPressure.raw < 3.9 || // <4mA generally bad transducer io.waterPressure.inst > 21, // >21mA generally bad transducer
// alarm trigger time 3, // alarm condition must be true for 3 seconds to throw a fault // allows ignoring small hiccups from transient events
true, // the alarm can automatically clear once the condition is false 3600, // alarm condition must be false for 3600s (1h) before automatically clearing the fault io.waterPressure.inst // Log this value when the fault is triggered, useful to record the peak pressure );
if(err){ setPID(0,false); // Disable the PID from modifying the CO io.pumpSpeed = 55; // Manually set the CO to a safe operating value } `
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| id | yes | — | PID Index # | |
| value | number | boolean | yes | — | Setpoint | true/false for enable/disable |
Returns
number
CO value
Example
setPID(0,80); // Target 80% PID output