Skip to content

15. Block type reference ​

Every block type built into hakkas, by family. For each: what it does, its ports, and what to know when using it. The ports are as the controller describes them; an input fed by nothing rests at 0, false or an empty text (Section 2.3). The section numbers refer to the specification, specifications/03-block-types.md, which has every detail.

Composite types, such as the standard library's schedule/WeekSchedule, are not listed here: they are described where they come from (Chapter 7).

Math ​

Arithmetic on numbers. Every input and output is a number.

math/Add4 ​

out = in1+in2+in3+in4

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
in3innumberOperand 3
in4innumberOperand 4
outoutnumberResult

math/Add2 ​

out = in1+in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutnumberResult

math/Mult2 ​

out = in1*in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutnumberResult

math/Divide ​

out = in1/in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutnumberResult

Division by 0 gives ±Infinity, or NaN for 0/0, as IEEE-754 arithmetic does.

math/Subtract ​

out = in1-in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutnumberResult

math/Modulo ​

out = in1 MOD in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutnumberResult

The floored modulo: the result has the sign of the divisor (-7 MOD 3 = 2). Compare math/Remainder.

math/Remainder ​

out = in1 REMAINDER in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutnumberResult

The truncating remainder: the result has the sign of the dividend (-7 REMAINDER 3 = -1), like C's fmod.

math/Min ​

out = the smallest connected input (03 §3.10)

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
in3innumberOperand 3
in4innumberOperand 4
outoutnumberResult

Only the inputs that are fed (by a connection, a value, a binding or a link) count; an input fed by nothing is ignored, so 2, 3 or 4 inputs can be used in any positions. None fed gives 0. A NaN in any fed input gives NaN, so a failed sensor shows.

math/Max ​

out = the largest connected input (03 §3.10)

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
in3innumberOperand 3
in4innumberOperand 4
outoutnumberResult

As math/Min: only fed inputs count; none gives 0; NaN gives NaN.

Compare ​

Comparisons of two numbers, giving a bool.

compare/Greater ​

out = in1 > in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutboolResult

compare/Less ​

out = in1 < in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutboolResult

compare/Equal ​

out = in1 == in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutboolResult

Exact comparison of numbers: compare measured values with compare/Less or compare/Greater and a margin instead.

compare/NotEqual ​

out = in1 != in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutboolResult

With a NaN operand every comparison is false except NotEqual, which is true.

compare/LessEqual ​

out = in1 <= in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutboolResult

compare/GreaterEqual ​

out = in1 >= in2

PortTypeDescription
in1innumberOperand 1
in2innumberOperand 2
outoutboolResult

Logic ​

Boolean logic. Every input and output is a bool; a number input is true when it is not 0.

logic/And ​

out = in1 AND in2 (boolean) (03 §6.2)

PortTypeDescription
in1inboolOperand 1
in2inboolOperand 2
outoutboolResult

logic/Or ​

out = in1 OR in2 (boolean)

PortTypeDescription
in1inboolOperand 1
in2inboolOperand 2
outoutboolResult

logic/Xor ​

out = in1 XOR in2 (boolean)

PortTypeDescription
in1inboolOperand 1
in2inboolOperand 2
outoutboolResult

logic/Not ​

out = NOT in (boolean)

PortTypeDescription
ininboolOperand
outoutboolResult

Process ​

The control engineer's blocks: filters, curves, limits, delays, regulators, alarms and selectors.

process/Linear ​

out = k*in+m

PortTypeDescription
ininnumberInput value
kinnumberGain
minnumberOffset
outoutnumberk*in+m

Scaling: percent to volts (k = 0.1), °C to °F (k = 1.8, m = 32), a sensor's 0–10 V to its range.

process/Deadband ​

out follows in only when it moves by at least threshold

PortTypeDescription
ininnumberInput value
thresholdinnumberSmallest change of in that moves out
outoutnumberin, held while it moves less than threshold

out follows in only when it has moved at least threshold from out. The first value after the start always passes. Use it to filter a noisy sensor more than the change threshold does, visibly in the diagram.

process/PID ​

PID regulator (03 §6.1)

PortTypeDescription
setpointinnumberDesired value of the measurement
inputinnumberMeasured value of the controlled process
kpinnumberProportional gain (0: no proportional term)
kiinnumberIntegral gain, per second (0: no integral term)
kdinnumberDerivative gain, in seconds (0: no derivative term)
max_dgaininnumberHighest gain of the derivative term (<= 0: no limit)
mininnumberLower output limit (equal limits: none)
maxinnumberUpper output limit (equal limits: none)
reverseinboolReverse acting (error = input - setpoint), e.g. cooling
autoinboolAutomatic (true) or manual (false) mode
manualinnumberOutput in manual mode (clamped to the limits)
sample_msinnumberSample period in milliseconds (<= 0: no sampling)
outputoutnumberRegulator output, within the output limits
saturatedoutbooltrue while the output is at a limit

Parallel form: out = kp·e + ki·∫e dt + D, the derivative on the measurement (no kick on a setpoint step), limited to max_dgain. Rests in manual (auto false) with output manual, unlimited and without sampling: set sample_ms, the gains and the limits. Equal limits are no limits. Switching to automatic is bumpless. The integral stops at a limit (anti-windup), so the output leaves the limit as soon as the error reverses. reverse for cooling. saturated is true at a limit. Section 12.5 explains what it needs at start-up.

process/Curve ​

output follows a curve of up to 7 points (03 §3.2)

PortTypeDescription
inputinnumberThe value to convert
x1innumberX coordinate of point 1
x2innumberX coordinate of point 2
x3innumberX coordinate of point 3
x4innumberX coordinate of point 4
x5innumberX coordinate of point 5
x6innumberX coordinate of point 6
x7innumberX coordinate of point 7
y1innumberY coordinate of point 1
y2innumberY coordinate of point 2
y3innumberY coordinate of point 3
y4innumberY coordinate of point 4
y5innumberY coordinate of point 5
y6innumberY coordinate of point 6
y7innumberY coordinate of point 7
outputoutnumberThe value on the curve at input
minoutbooltrue while input is below the first point (output is held at its Y)
maxoutbooltrue while input is above the last point (output is held at its Y)

Up to seven points; a point counts only if its x is greater than the last point used, so unused points resting at 0 drop out by themselves. Outside the points the output holds the nearest end's y, and min or max says so.

process/AutoMan ​

output = override ? manual : input (03 §3.3)

PortTypeDescription
inputinnumberThe automatic value
overrideinboolManual override: output follows manual instead of input
manualinnumberThe manual value
outputoutnumbermanual while overridden, else input

A hand switch: override true makes output follow manual. No bumpless transfer: the output jumps.

process/Alarm ​

alarm states of a condition

PortTypeDescription
inputinboolThe alarm condition: true while the alarmed situation exists
acknowledgeinboolA push button: a person has noticed the alarm (acts on its rising edge)
blockinboolBlocks the alarm: no state changes; state Blocked
disableinboolDisables the alarm: no state changes; state Disabled
categoryinstringFree text for the presentation
classinstringThe alarm class: A, B, C or D (anything else: C)
normaloutbooltrue while the alarm is Normal
activatedoutbooltrue while the alarm is Activated
deactivatedoutbooltrue while the alarm is Deactivated: gone, not acknowledged
reactivatedoutbooltrue while the alarm is Reactivated: back before acknowledged
acknowledgedoutbooltrue while the alarm is Acknowledged
disabledoutbooltrue while the alarm is Disabled
blockedoutbooltrue while the alarm is Blocked
stateoutstringThe name of the current state

States Normal, Activated, Deactivated (the condition gone, not acknowledged), Reactivated, Acknowledged, Disabled and Blocked; exactly one output is true, and state names it. acknowledge acts on its rising edge. Classes: A attend to at once, day and night; B during working hours; C soon; D of interest only. block puts a fluttering alarm aside, disable switches it off; Disabled wins. See Section 13.7.

process/Delay ​

output takes input once it has been stable for milliseconds (03 §3.4)

PortTypeDescription
inputinboolThe signal to delay
millisecondsinnumberHow long input must be stable before output takes it (<= 0: no delay)
modeinnumberThe edges delayed: 0 both, 1 rising, 2 falling; the other passes at once
outputoutboolinput, once it has been stable for milliseconds

output takes input once it has been stable for milliseconds; a shorter pulse never comes through. mode 0 delays both edges, 1 only the rising edge (an on-delay) and 2 only the falling edge (an off-delay); the other edge passes at once. At the start, mode 0 takes input at once; in modes 1 and 2 output starts false, so in mode 1 a true input waits the full time (Section 14.7), also when the time comes from other blocks. Set mode as a fixed value. timing/Hours and its siblings give the time in units.

process/Trigger ​

output false when arm rises, true when fire rises (03 §3.5)

PortTypeDescription
arminboolIts rising edge sets output to false
fireinboolIts rising edge sets output to true
outputoutboolfalse since the last rising arm, true since the last rising fire

A latch on edges: a rising fire sets output, a rising arm clears it. Levels do nothing, and an input already true at the start must go false and true again. See Section 13.3.

process/Limit ​

output = input capped to [min, max] (03 §3.6)

PortTypeDescription
inputinnumberThe value to limit
mininnumberLower limit (equal limits: none)
maxinnumberUpper limit (equal limits: none)
outputoutnumberinput, capped to [min, max]

Equal limits are no limits (both rest at 0); limits the wrong way round are swapped.

process/Hysteresis ​

Schmitt trigger: output on above threshold+hysteresis, off below threshold-hysteresis (03 §3.7)

PortTypeDescription
inputinnumberThe value compared
thresholdinnumberThe middle of the switching band
hysteresisinnumberHalf the width of the band: on above threshold + hysteresis, off below threshold - hysteresis
invertedinboolNegates output
outputoutboolThe state (on = true), negated when inverted

A comparator with a band: on above threshold + hysteresis, off below threshold − hysteresis, unchanged in between. inverted for heating (on when cold). At the start it is on only above the band.

process/Exponential ​

output = aexp(binput) (03 §3.8)

PortTypeDescription
inputinnumberInput value
ainnumberScale
binnumberRate
outputoutnumberaexp(binput)

output = a·exp(b·input).

process/Logarithmic ​

output = aln(binput) (03 §3.8)

PortTypeDescription
inputinnumberInput value
ainnumberScale
binnumberRate
outputoutnumberaln(binput)

output = a·ln(b·input), the natural logarithm.

process/Integrator ​

output = integral of input dt / divisor, within [min, max] (03 §3.9)

PortTypeDescription
inputinnumberThe value integrated
mininnumberLower limit of output (equal limits: none)
maxinnumberUpper limit of output (equal limits: none)
divisorinnumberTime scale: 1 seconds, 3600 hours, 86400 days (<= 0: 1)
resetinboolWhile true, output is 0 (within the limits) and nothing integrates
sample_msinnumberHow often output is updated, in milliseconds (<= 0: only on input changes)
outputoutnumberThe integral, within [min, max]

Adds input × seconds / divisor (divisor 3600 for hours, 86400 for days), held within the limits (equal limits: none). reset holds it at 0. sample_ms only sets how often output moves while input is constant; the result is exact either way. Running hours: integrate a bool (1 while running) with divisor 3600.

process/SelectIn ​

output = select ? in_true : in_false (03 §3.11)

PortTypeDescription
selectinboolWhich input reaches output: in_true when true, else in_false
in_falseinnumberReaches output while select is false
in_trueinnumberReaches output while select is true
outputoutnumberin_true or in_false, as select chooses

output is in_true while select is true, else in_false. Numbers only: a bool arrives as 0 or 1. IEC 61131-3's SEL.

process/SelectOut ​

input goes to out_true or out_false, as select chooses; the other is 0 (03 §3.11)

PortTypeDescription
selectinboolWhich output input reaches: out_true when true, else out_false
inputinnumberThe value passed on
out_falseoutnumberinput while select is false, else 0
out_trueoutnumberinput while select is true, else 0

input goes to out_true or out_false; the other output is 0, so nothing downstream keeps a stale value.

process/MultiplexIn ​

output = the input select chooses, 1-8 (03 §3.11)

PortTypeDescription
selectinnumberWhich input reaches output, 1-8; any other value: none (output 0)
in1innumberReaches output while select is 1
in2innumberReaches output while select is 2
in3innumberReaches output while select is 3
in4innumberReaches output while select is 4
in5innumberReaches output while select is 5
in6innumberReaches output while select is 6
in7innumberReaches output while select is 7
in8innumberReaches output while select is 8
outputoutnumberThe input select chooses, or 0

select is rounded; 1–8 chooses that input, anything else (0 when unfed) none, giving 0. IEC 61131-3's MUX, counting from 1.

process/MultiplexOut ​

input goes to the output select chooses, 1-8; the others are 0 (03 §3.11)

PortTypeDescription
selectinnumberWhich output input reaches, 1-8; any other value: none
inputinnumberThe value passed on
out1outnumberinput while select is 1, else 0
out2outnumberinput while select is 2, else 0
out3outnumberinput while select is 3, else 0
out4outnumberinput while select is 4, else 0
out5outnumberinput while select is 5, else 0
out6outnumberinput while select is 6, else 0
out7outnumberinput while select is 7, else 0
out8outnumberinput while select is 8, else 0

select 1–8 sends input to that output; every other output is 0.

Timing ​

Pulses, times in units, and the calendar. The calendar blocks use the controller's local time (Section 16.2, time_zone) and wake exactly when their output may change.

timing/Interval ​

periodic pulse generator: PWM or edge generator (03 §3.1)

PortTypeDescription
millisecondsinnumberPeriod of one full cycle, in milliseconds (<= 0: idle, out false).
duty-cycleinnumberPercentage of each period during which out is true, 0-100 (clamped to that range).
outoutboolThe generated pulse train.

A square wave: milliseconds the period, duty-cycle the percentage of it that out is true. Idle until the period is set. Changes take effect at the next period, never cutting the current one.

timing/Days ​

out = in*86400000: days to milliseconds (03 §3.12)

PortTypeDescription
ininnumberDays
outoutnumberMilliseconds

Converts days to the milliseconds that process/Delay and timing/Interval take: 2 → Days → Delay. Fractions work.

timing/Hours ​

out = in*3600000: hours to milliseconds (03 §3.12)

PortTypeDescription
ininnumberHours
outoutnumberMilliseconds

Converts hours to milliseconds: 3 → Hours → Delay. Fractions work: 1.5 is an hour and a half.

timing/Minutes ​

out = in*60000: minutes to milliseconds (03 §3.12)

PortTypeDescription
ininnumberMinutes
outoutnumberMilliseconds

Converts minutes to milliseconds: 10 → Minutes → Delay. Fractions work.

timing/Seconds ​

out = in*1000: seconds to milliseconds (03 §3.12)

PortTypeDescription
ininnumberSeconds
outoutnumberMilliseconds

Converts seconds to milliseconds: 5 → Seconds → Delay. Fractions work: 0.25 is 250 ms.

timing/MinuteRange ​

true within a time-of-day range (03 §6.2)

PortTypeDescription
rangeinstringTime of day "HH:MM-HH:MM" in local time, e.g. "12:30-15:45": start included, end excluded; wraps past midnight ("22:00-06:00"); "00:00-24:00" is all day
outoutboolTrue while the local time matches

range as HH:MM-HH:MM, the start included and the end excluded; it may wrap past midnight (22:00-06:00). All day is 00:00-24:00; an equal start and end is never.

timing/DayOfWeek ​

true on the selected weekdays (03 §6.2)

PortTypeDescription
daysinstringWeekdays, a selector such as "1-5" or "6,7": 1-7, day 1 Monday (or Sunday if sunday_first)
sunday_firstinboolDay 1 is Sunday instead of Monday
outoutboolTrue while the local time matches

days a selector of 1–7, Monday = 1 (Sunday = 1 with sunday_first).

timing/DayOfMonth ​

true on the selected days of the month (03 §6.2)

PortTypeDescription
daysinstringDays of the month, a selector such as "1" or "1-15": 1-31 (a day a month does not have never matches)
outoutboolTrue while the local time matches

days a selector of 1–31; a day a month does not have never matches.

timing/MonthOfYear ​

true during the selected months (03 §6.2)

PortTypeDescription
monthsinstringMonths, a selector such as "6-8" or "11-2": 1-12, 1 January
outoutboolTrue while the local time matches

months a selector of 1–12; 10-4 wraps over the new year.

timing/DayOfYear ​

true on the selected days of the year (03 §6.2)

PortTypeDescription
daysinstringDays of the year, a selector such as "1-31": 1-366, 1 January 1
outoutboolTrue while the local time matches

days a selector of 1–366; 60 is 1 March, or 29 February in a leap year.

timing/WeekOfYear ​

true during the selected ISO weeks (03 §6.2)

PortTypeDescription
weeksinstringISO 8601 weeks (starting on Monday), a selector such as "1-26": 1-53
outoutboolTrue while the local time matches

weeks a selector of ISO 8601 weeks 1–53, which start on Monday.