Control
Kalman filter
ctrlKalman · ctrlKalman(settings: object, state: object, measurement: double)
One step of a one-dimensional Kalman filter, smoothing a noisy measurement. Like ctrlPID it returns the whole state and takes its own previous state back in. Read the filtered value from the o field.
Parameters
| Name | Type | Description |
|---|---|---|
settings |
object |
The tuning, keys in lower case: q the process noise per second, r the measurement noise. |
state |
object |
The variable holding the previous state - normally the variable being computed. Missing or null on the first pass, which initialises it. |
measurement |
double |
The raw reading for this pass. A null reading leaves an existing state unchanged; the first null reading, with no state yet, creates one with o = 0. |
Returns object: The new state: o the filtered value, p the estimate covariance, ts a whole number from the engine's clock. The first reading is taken as it is: o equals it.
Examples
ctrlKalman({q: 0.01, r: 0.5}, null, LEVEL).o → 42.5
ctrlKalman({q: 0.0, r: 0.5}, {o: 40.0, p: 0.5, ts: 0}, LEVEL).o → 41.25
ctrlKalman({q: 0.01, r: 0.5}, null, null).o → 0.0
Data Orchester: available in plant formulas.
PID controller
ctrlPID · ctrlPID(settings: object, state: object, error: double)
One step of a PID control loop. It returns the whole controller state, output included, so the variable this formula feeds is the state itself and the state parameter is that same variable - that self-reference is how the loop carries its integral and derivative terms between evaluations. Read the output from the o field.
Parameters
| Name | Type | Description |
|---|---|---|
settings |
object |
The tuning, keys in lower case: p, i and d gains, plus mino and maxo bounding the output. The integral term is held inside those same bounds, which is what stops it winding up. |
state |
object |
The variable holding the previous state - normally the variable being computed. Missing or null on the first pass, which initialises it. |
error |
double |
How far the process is from its setpoint, right now. |
Returns object: The new state: o the output, a the accumulated integral, e the previous error, ts a whole number from the engine's clock. The first pass starts the loop at rest: o, a and e are 0.
Examples
ctrlPID({p: 2.0, i: 0.1, d: 0.0, mino: 0.0, maxo: 100.0}, null, 50.0 - LEVEL).o → 0.0
ctrlPID({p: 2.0, i: 0.0, d: 0.0, mino: 0.0, maxo: 100.0}, {a: 0.0, o: 0.0, e: 0.0, ts: 0}, 50.0 - LEVEL).o → 15.0
Data Orchester: available in plant formulas.
PWM controller
ctrlPWM · ctrlPWM(settings: object, state: object, input: double)
One step of a pulse-width-modulation loop, turning a continuous input into an on/off duty cycle: in each period the output is on for the input's share of it. Like ctrlPID it returns the whole state and takes its own previous state back in. It only switches when it is evaluated, so drive it with a Scheduler. Read the on/off decision from the o field.
Parameters
| Name | Type | Description |
|---|---|---|
settings |
object |
The configuration, keys in lower case: period, the cycle length in seconds; minin and maxin, the inputs that give 0 % and 100 % on; and optionally mintoggle, the fewest seconds between two switchings (0 when left out). |
state |
object |
The variable holding the previous state - normally the variable being computed. Missing or null on the first pass, which initialises it. |
input |
double |
The demand, somewhere between minin and maxin. |
Returns object: The new state: o the on/off output (a boolean), cs the cycle start and lt the last switching, both whole numbers from the engine's clock. The first pass returns o = false.
Examples
ctrlPWM({period: 60, minin: 0, maxin: 100}, null, LEVEL).o → false
ctrlPWM({period: 60, minin: 0, maxin: 100, mintoggle: 5}, {o: false, cs: 0, lt: 0}, LEVEL).o → true
Data Orchester: available in plant formulas.
This page describes Amtiri Script 5.4.1 as shipped with Data Orchester engine 6.12.1 and Site 1.22.7.