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
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
in3 | in | number | Operand 3 |
in4 | in | number | Operand 4 |
out | out | number | Result |
math/Add2
out = in1+in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | number | Result |
math/Mult2
out = in1*in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | number | Result |
math/Divide
out = in1/in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | number | Result |
Division by 0 gives ±Infinity, or NaN for 0/0, as IEEE-754 arithmetic does.
math/Subtract
out = in1-in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | number | Result |
math/Modulo
out = in1 MOD in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | number | Result |
The floored modulo: the result has the sign of the divisor (-7 MOD 3 = 2). Compare math/Remainder.
math/Remainder
out = in1 REMAINDER in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | number | Result |
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)
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
in3 | in | number | Operand 3 |
in4 | in | number | Operand 4 |
out | out | number | Result |
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)
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
in3 | in | number | Operand 3 |
in4 | in | number | Operand 4 |
out | out | number | Result |
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
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | bool | Result |
compare/Less
out = in1 < in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | bool | Result |
compare/Equal
out = in1 == in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | bool | Result |
Exact comparison of numbers: compare measured values with compare/Less or compare/Greater and a margin instead.
compare/NotEqual
out = in1 != in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | bool | Result |
With a NaN operand every comparison is false except NotEqual, which is true.
compare/LessEqual
out = in1 <= in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | bool | Result |
compare/GreaterEqual
out = in1 >= in2
| Port | Type | Description | |
|---|---|---|---|
in1 | in | number | Operand 1 |
in2 | in | number | Operand 2 |
out | out | bool | Result |
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)
| Port | Type | Description | |
|---|---|---|---|
in1 | in | bool | Operand 1 |
in2 | in | bool | Operand 2 |
out | out | bool | Result |
logic/Or
out = in1 OR in2 (boolean)
| Port | Type | Description | |
|---|---|---|---|
in1 | in | bool | Operand 1 |
in2 | in | bool | Operand 2 |
out | out | bool | Result |
logic/Xor
out = in1 XOR in2 (boolean)
| Port | Type | Description | |
|---|---|---|---|
in1 | in | bool | Operand 1 |
in2 | in | bool | Operand 2 |
out | out | bool | Result |
logic/Not
out = NOT in (boolean)
| Port | Type | Description | |
|---|---|---|---|
in | in | bool | Operand |
out | out | bool | Result |
Process
The control engineer's blocks: filters, curves, limits, delays, regulators, alarms and selectors.
process/Linear
out = k*in+m
| Port | Type | Description | |
|---|---|---|---|
in | in | number | Input value |
k | in | number | Gain |
m | in | number | Offset |
out | out | number | k*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
| Port | Type | Description | |
|---|---|---|---|
in | in | number | Input value |
threshold | in | number | Smallest change of in that moves out |
out | out | number | in, 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)
| Port | Type | Description | |
|---|---|---|---|
setpoint | in | number | Desired value of the measurement |
input | in | number | Measured value of the controlled process |
kp | in | number | Proportional gain (0: no proportional term) |
ki | in | number | Integral gain, per second (0: no integral term) |
kd | in | number | Derivative gain, in seconds (0: no derivative term) |
max_dgain | in | number | Highest gain of the derivative term (<= 0: no limit) |
min | in | number | Lower output limit (equal limits: none) |
max | in | number | Upper output limit (equal limits: none) |
reverse | in | bool | Reverse acting (error = input - setpoint), e.g. cooling |
auto | in | bool | Automatic (true) or manual (false) mode |
manual | in | number | Output in manual mode (clamped to the limits) |
sample_ms | in | number | Sample period in milliseconds (<= 0: no sampling) |
output | out | number | Regulator output, within the output limits |
saturated | out | bool | true 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)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | The value to convert |
x1 | in | number | X coordinate of point 1 |
x2 | in | number | X coordinate of point 2 |
x3 | in | number | X coordinate of point 3 |
x4 | in | number | X coordinate of point 4 |
x5 | in | number | X coordinate of point 5 |
x6 | in | number | X coordinate of point 6 |
x7 | in | number | X coordinate of point 7 |
y1 | in | number | Y coordinate of point 1 |
y2 | in | number | Y coordinate of point 2 |
y3 | in | number | Y coordinate of point 3 |
y4 | in | number | Y coordinate of point 4 |
y5 | in | number | Y coordinate of point 5 |
y6 | in | number | Y coordinate of point 6 |
y7 | in | number | Y coordinate of point 7 |
output | out | number | The value on the curve at input |
min | out | bool | true while input is below the first point (output is held at its Y) |
max | out | bool | true 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)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | The automatic value |
override | in | bool | Manual override: output follows manual instead of input |
manual | in | number | The manual value |
output | out | number | manual 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
| Port | Type | Description | |
|---|---|---|---|
input | in | bool | The alarm condition: true while the alarmed situation exists |
acknowledge | in | bool | A push button: a person has noticed the alarm (acts on its rising edge) |
block | in | bool | Blocks the alarm: no state changes; state Blocked |
disable | in | bool | Disables the alarm: no state changes; state Disabled |
category | in | string | Free text for the presentation |
class | in | string | The alarm class: A, B, C or D (anything else: C) |
normal | out | bool | true while the alarm is Normal |
activated | out | bool | true while the alarm is Activated |
deactivated | out | bool | true while the alarm is Deactivated: gone, not acknowledged |
reactivated | out | bool | true while the alarm is Reactivated: back before acknowledged |
acknowledged | out | bool | true while the alarm is Acknowledged |
disabled | out | bool | true while the alarm is Disabled |
blocked | out | bool | true while the alarm is Blocked |
state | out | string | The 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)
| Port | Type | Description | |
|---|---|---|---|
input | in | bool | The signal to delay |
milliseconds | in | number | How long input must be stable before output takes it (<= 0: no delay) |
mode | in | number | The edges delayed: 0 both, 1 rising, 2 falling; the other passes at once |
output | out | bool | input, 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)
| Port | Type | Description | |
|---|---|---|---|
arm | in | bool | Its rising edge sets output to false |
fire | in | bool | Its rising edge sets output to true |
output | out | bool | false 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)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | The value to limit |
min | in | number | Lower limit (equal limits: none) |
max | in | number | Upper limit (equal limits: none) |
output | out | number | input, 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)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | The value compared |
threshold | in | number | The middle of the switching band |
hysteresis | in | number | Half the width of the band: on above threshold + hysteresis, off below threshold - hysteresis |
inverted | in | bool | Negates output |
output | out | bool | The 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)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | Input value |
a | in | number | Scale |
b | in | number | Rate |
output | out | number | aexp(binput) |
output = a·exp(b·input).
process/Logarithmic
output = aln(binput) (03 §3.8)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | Input value |
a | in | number | Scale |
b | in | number | Rate |
output | out | number | aln(binput) |
output = a·ln(b·input), the natural logarithm.
process/Integrator
output = integral of input dt / divisor, within [min, max] (03 §3.9)
| Port | Type | Description | |
|---|---|---|---|
input | in | number | The value integrated |
min | in | number | Lower limit of output (equal limits: none) |
max | in | number | Upper limit of output (equal limits: none) |
divisor | in | number | Time scale: 1 seconds, 3600 hours, 86400 days (<= 0: 1) |
reset | in | bool | While true, output is 0 (within the limits) and nothing integrates |
sample_ms | in | number | How often output is updated, in milliseconds (<= 0: only on input changes) |
output | out | number | The 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)
| Port | Type | Description | |
|---|---|---|---|
select | in | bool | Which input reaches output: in_true when true, else in_false |
in_false | in | number | Reaches output while select is false |
in_true | in | number | Reaches output while select is true |
output | out | number | in_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)
| Port | Type | Description | |
|---|---|---|---|
select | in | bool | Which output input reaches: out_true when true, else out_false |
input | in | number | The value passed on |
out_false | out | number | input while select is false, else 0 |
out_true | out | number | input 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)
| Port | Type | Description | |
|---|---|---|---|
select | in | number | Which input reaches output, 1-8; any other value: none (output 0) |
in1 | in | number | Reaches output while select is 1 |
in2 | in | number | Reaches output while select is 2 |
in3 | in | number | Reaches output while select is 3 |
in4 | in | number | Reaches output while select is 4 |
in5 | in | number | Reaches output while select is 5 |
in6 | in | number | Reaches output while select is 6 |
in7 | in | number | Reaches output while select is 7 |
in8 | in | number | Reaches output while select is 8 |
output | out | number | The 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)
| Port | Type | Description | |
|---|---|---|---|
select | in | number | Which output input reaches, 1-8; any other value: none |
input | in | number | The value passed on |
out1 | out | number | input while select is 1, else 0 |
out2 | out | number | input while select is 2, else 0 |
out3 | out | number | input while select is 3, else 0 |
out4 | out | number | input while select is 4, else 0 |
out5 | out | number | input while select is 5, else 0 |
out6 | out | number | input while select is 6, else 0 |
out7 | out | number | input while select is 7, else 0 |
out8 | out | number | input 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)
| Port | Type | Description | |
|---|---|---|---|
milliseconds | in | number | Period of one full cycle, in milliseconds (<= 0: idle, out false). |
duty-cycle | in | number | Percentage of each period during which out is true, 0-100 (clamped to that range). |
out | out | bool | The 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)
| Port | Type | Description | |
|---|---|---|---|
in | in | number | Days |
out | out | number | Milliseconds |
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)
| Port | Type | Description | |
|---|---|---|---|
in | in | number | Hours |
out | out | number | Milliseconds |
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)
| Port | Type | Description | |
|---|---|---|---|
in | in | number | Minutes |
out | out | number | Milliseconds |
Converts minutes to milliseconds: 10 → Minutes → Delay. Fractions work.
timing/Seconds
out = in*1000: seconds to milliseconds (03 §3.12)
| Port | Type | Description | |
|---|---|---|---|
in | in | number | Seconds |
out | out | number | Milliseconds |
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)
| Port | Type | Description | |
|---|---|---|---|
range | in | string | Time 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 |
out | out | bool | True 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)
| Port | Type | Description | |
|---|---|---|---|
days | in | string | Weekdays, a selector such as "1-5" or "6,7": 1-7, day 1 Monday (or Sunday if sunday_first) |
sunday_first | in | bool | Day 1 is Sunday instead of Monday |
out | out | bool | True 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)
| Port | Type | Description | |
|---|---|---|---|
days | in | string | Days of the month, a selector such as "1" or "1-15": 1-31 (a day a month does not have never matches) |
out | out | bool | True 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)
| Port | Type | Description | |
|---|---|---|---|
months | in | string | Months, a selector such as "6-8" or "11-2": 1-12, 1 January |
out | out | bool | True 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)
| Port | Type | Description | |
|---|---|---|---|
days | in | string | Days of the year, a selector such as "1-31": 1-366, 1 January 1 |
out | out | bool | True 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)
| Port | Type | Description | |
|---|---|---|---|
weeks | in | string | ISO 8601 weeks (starting on Monday), a selector such as "1-26": 1-53 |
out | out | bool | True while the local time matches |
weeks a selector of ISO 8601 weeks 1–53, which start on Monday.