Two machine settings computed from sensor readings, with every sum shown.
control-system.pl · output · proof · check · try it in the playground
A controller reads sensors and decides how hard to drive its actuators (the parts that act: a valve, a motor, a heater).
This example computes commands for two actuators:
What should each command be, and how was it worked out?
measurement1(input1, [6, 11]).
measurement2(input2, true).
measurement3(disturbance1, 35766).
measurement4(output2, 24).
observation3(state3, 22).
target2(output2, 29).
% …
A pair like [6, 11] is turned into one number by a helper rule: if the first
value is smaller, use the square root of the difference (here √5); otherwise
use the first value.
control1(actuator1, C) :-
measurement10(input1, M1),
measurement2(input2, true),
measurement3(disturbance1, D1),
C1 is M1*19.6, % proportional part
C2 is log(D1)/log(10), % compensation part
C is C1-C2. % simple feedforward control
is means “calculate”. The compensation is the base-10 logarithm of the
disturbance.
control1(actuator2, C) :-
observation3(state3, P3),
measurement4(output2, M4),
target2(output2, T2),
E is T2-M4, % error
D is P3-M4, % differential error
C1 is 5.8*E, % proportional part
N is 7.3/E, % nonlinear factor
C2 is N*D, % nonlinear differential part
C is C1+C2. % PND feedback control
control1(actuator1, 39.27346198678276).
control1(actuator2, 26.08).
These are ordinary decimal (floating-point) numbers, printed in full.
Actuator 1
Actuator 2
Every one of these values is written into the proof.
The checker does not take the arithmetic on faith: it recomputes each calculation itself and compares.
Verdict: checked.
node bin/eyedia.js examples/control-system.pl # the commands
node bin/eyedia.js --proof examples/control-system.pl # with every step
Or open it in the playground.
Raise the target to target2(output2, 34). and run again: the error becomes
10, and actuator 2’s command becomes 56.54 instead of 26.08. Actuator 1 is
unchanged.
When a machine setting comes from a chain of formulas, a proof that lists and re-checks every intermediate value turns “the controller said so” into something an engineer can audit line by line.