Logic Blocks Guide
Logic Blocks Guide
Contents
1 Introduction 1
2 Logic Blocks 1
2.1 Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1.1 Distance Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1.2 Altitude Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.3 Speed Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.4 Gravity Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.5 Angle Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1.6 Compass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Logic gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 Output value calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Math blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 Comparison Logic Gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.2 Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.3 Randomizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.4 Number Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.5 Arithmetics Logic Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3.6 Functions Logic Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.7 Aggregate Logic Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3.8 Hue Light Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Signals 16
5 Useful Circuits 17
5.1 Pulse generator/Rising edge detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.2 Falling edge detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.3 Latch (T-FlipFlop) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4 Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4.1 General Circuit (Base 𝑁) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4.2 Decimal (Base 10) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.4.3 Binary (Base 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
i
5.4.4 When to use each method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.5 No-Delay Signal Toggle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6 Historical Circuits 24
6.1 NOR/NOT Gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.2 Feedback Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.2.1 Clamped Feedback Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
C Tips 30
List of Figures
1 Distance Sensor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Altitude Sensor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Speed Sensor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 Gravity Sensor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5 Angle Sensor settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
6 Compass settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
7 Logic Gate settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
8 Output value calculation diagram made by Zoomah . . . . . . . . . . . . . . . . . . . . . . . 7
9 Comparator Logic Gate settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
10 Accumulator settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
11 Randomizer settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
12 Number Display settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
13 Arithmetics Logic Block settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
14 Functions Logic Block settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
15 Aggregate Logic Block settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
16 Hue Light Panel settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
17 Hue light panel color with saturation = brightness = 1 for inputs in the range [−1, 1] . . . . . 13
18 Diagram of the general method counter (logic gates implementation) . . . . . . . . . . . . . . 18
19 Diagram of the decimal method counter (logic gates implementation) . . . . . . . . . . . . . . 19
20 Diagram of the binary method counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
21 Diagram of the no-delay signal toggle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
22 Diagram of the clamped feedback loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
23 Graph of the multiplier for hinges as a function of the input value . . . . . . . . . . . . . . . 27
24 Graph of the speed for servos with hold position as a function of the input value . . . . . . . 28
List of Tables
1 Value modified by the input value for each block . . . . . . . . . . . . . . . . . . . . . . . . . 16
2 Comparison of the different counter methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3 Raw data of the input value multiplier for hinges . . . . . . . . . . . . . . . . . . . . . . . . . 27
4 Raw data of the input value speed for servos with hold position . . . . . . . . . . . . . . . . . 29
ii
1 Introduction
The goal of this document is to explain the logic system in the game Trailmakers. It also aims to act as
a comprehensive technical reference manual for all related mechanics and behaviours. This document also
contains a section about commonly used logic circuits and how to make them, to aid in the design and
understanding of more complex logic circuits.
2 Logic Blocks
Logic blocks are a group of blocks that allow to obtain and process information, which in turn can be used to
automate tasks or create more complex control schemes for creations, and more generally, perform any finite
sequence of steps (known as executing an algorithm).
All logic blocks, with the exception of distance/gravity sensors and number displays, have a display with an
arrow pointing away from the center of the block representing the value of their output signal. This arrow is
empty when there is no output (0 value), and green/red when the output is positive/negative. On gravity
sensors, this arrow is replaced with a weight icon, which has the same functionality (although it is white
when there is no output). Blocks which can take other signals as inputs (Logic gates and Math blocks),
with the exception of number displays, additionally have a second arrow pointing to the center of the block
representing the input signals, which works like the output arrow but using the value of the sum of the input
signals.
Note: due to a bug, only up to 5 characters can be used on any configurable block value. Even though the
UI rounds values 1-2 decimals, the values used are always the values that were typed, with the exception of
values in the range (−0.0001, 0.0001) which get rounded to 0.
2.1 Sensors
Sensors are a group of blocks that measure a physical property, like speed or angle, and create a boolean
output based on it.
1
– If enabled, raycast stops at the first obstacle regardless of what it is, but if it’s not a block the
output will be the same as no detection
2
Output (on) Output (off)
Speed
Trigger below
3
2.1.4 Gravity Sensor
Gravity sensors measure the gravity strength at the position of the block. They have a display which shows
the currently measured gravity as a bar indicator, which is full when the gravity is higher than or equal to
the trigger gravity and empty when the gravity is 0.
Its settings are shown in figure 4 and are as follows:
• Threshold: gravity strength threshold to trigger, relative to the normal gravity (14m/s2 )
• Output scale: multiplier of the output signal created by the block
• Output mode: type of output created by the sensor when it is activated (the output is always 0
otherwise)
– Trigger: output 1
– Measurement: output the current gravity relative to the normal gravity
– Normalized: output measurement
threshold
• Trigger: condition used to determine when to send an output
– Normal: sends an output when the gravity strength is above the configured value
– Below: sends an output when the gravity strength is below the configured value
Altitude
Trigger below
Output scale Output mode
4
– Outside: sends an output when the angle is outside the activation threshold
Direction
Trigger outside
2.1.6 Compass
Compasses measure the angle of the block relative to the closest direction to the north in the plane defined
by the square faces of the block. They have a display which shows the currently measured angle, with a red
section representing the activation threshold, and an output arrow and cardinal direction letters representing
the angle. The arrow will always try to point north no matter the orientation of the block (will point in the
direction closest to the north of the plane it is in).
Its settings are shown in figure 6 and are as follows:
• Direction: position of the middle point of the activation threshold, in degrees
• Width: size of the activation threshold, in degrees
• Output scale: multiplier of the output signal created by the block
• Output mode: type of output created by the sensor when it is activated (the output is always 0
otherwise)
– Trigger: output 1
– Measurement: output the current signed angle (positive for counterclockwise) from either the
center (normal trigger) or the closest edge (trigger outside) of the activation threshold to the output
arrow in degrees
– Normalized: output measurement
width/2
• Trigger: condition used to determine when to send an output
– Normal: sends an output when the angle is inside of the activation threshold
– Outside: sends an output when the angle is outside the activation threshold
5
Output (on) Output (off)
Direction
Trigger outside
Red keybind
6
2) The gate adds up the values of all of its inputs and clamps the result to the [−1, 1] range
• Values smaller than −1 are replaced with −1, and values bigger than 1 with 1
3) The gate multiplies the result by its Output scale setting. For NOR gates, their setting replaces the
result (which would otherwise always be 0)
4) The gate sends the result as its output scale
This process can be described with the following formula:
[Link] Example An AND gate with an output value of 0.5 has 2 inputs, one of them has an output
value of 0.8 and the other of 0.5. When at least one of them is off, it doesn’t send an output. When both of
them are on at the same time, the AND gate is able to send an output. On that case, the output values of
the inputs are first added up: 0.8 + 0.5 = 1.3. Because the sum, 1.3, is bigger than 1, the gate replaces it
with 1. Then that value is multiplied by the output value of the gate: 1 ⋅ 0.5 = 0.5. Finally, the AND gate
sends an output with the value of that multiplication, 0.5. On the steam version, if the sum of the inputs or
the output value of the gate had been 0, the resultant value of the multiplication would have also been 0, in
which case the gate wouldn’t have sent an output.
7
– When the mode is set to “greater than or equal”, the total input is rounded to 3 decimal places
before performing the comparison, using the nearest mode and rounding numbers with a fractional
part of 0.5 up
– For the “equal” and “not equal” modes, numbers are compared with a tolerance of 𝜀 = 0.0005 (the
numbers are equal if their difference is < 𝜀)
• Clamp input: whether the result of the sum of the inputs should be clamped to the [−1, 1] range or not
Output value
Red keybind
Clamp input
Green/red toggle Green keybind Timers Threshold Comparison mode
2.3.2 Accumulator
Accumulators store and output a numeric value, and allow to increment/decrement it between some bounds.
They are always initialized to the value closest to 0 within the defined bounds. They have a display which
shows the currently stored value as a bar indicator, which is full when the value is the maximum and empty
when it is the minimum. Additionally, the bar indicator is white when the value is 0, and green/red when it
is positive/negative.
Its settings are shown in figure 10 and are as follows:
• Keybinds: see Keybinds
• Toggle: see Toggle
• Timers: see Timers
• Value bounds: minimum/maximum value that can be stored, the stored value will be clamped to the
range [min(minimum, maximum), max(minimum, maximum)]
• Scale: rate of change of the stored value, used to scale the value of the input
• Use steps: whether to change the stored value continuously (in which case the scale is change per
second, achieved by using 1/60th the scale on each frame) or only once per input activation (on the
rising edge of the signal)
8
Output (on) Output (off)
Red keybind
Use steps
Green/red toggle Green keybind Timers Value bounds Scale
2.3.3 Randomizer
Randomizers generate and output random values.
Its settings are shown in figure 11 and are as follows:
• Keybinds: see Keybinds
• Toggle: see Toggle
• Timers: see Timers
• Value bounds: minimum/maximum value that can be generated, the generated values will be in the
range [min(minimum, maximum), max(minimum, maximum)]
• Random mode: mode in which the values are generated
– Output on input: outputs a random value generated on each frame when it is activated, and 0
otherwise
– Change on input: outputs a random value generated on each frame when it is activated, and the
last generated value (initialized to 0) otherwise
– Input defines range: outputs a random value generated on each frame in the intersection between
the value bounds and the range [min(inputs), max(inputs)] when the block is activated, and the
last generated value (initialized to a random value within the value bounds) otherwise
If the intersection is empty, the value bounds range is used instead if any of the inputs isn’t 0,
otherwise the output is always 0
– -Change, +Output: generates and stores a random value on each frame when the block is activated
with a negative input, and outputs the last generated value (initialized to a random value within
the value bounds) when it is activated with a positive input
Red keybind
9
2.3.4 Number Display
Number displays output the sum of their inputs, similar to how OR logic gates work (although without
clamping the sum to the [−1, 1] range), and display it with an optional rounding. They display “N/A” in
build mode.
Its settings are shown in figure 12 and are as follows:
• Keybinds: see Keybinds
• Toggle: see Toggle
• Timers: see Timers
• Rounding: rounding mode applied to the sum of the inputs, always done to an integer when enabled.
Possible values are “disabled”, “nearest”, “floor” (closest smaller integer), and “ceil” (closest bigger
integer)
– When rounding is disabled, numbers are rounded to 2 decimals using the nearest mode, rounding
numbers ending in 0.005 away from 0
– For the “nearest” mode, numbers with a fractional part of 0.5 are rounded to the closest even
integer
– If the number is outside of the [−1000, 1000] range, it’s always displayed in scientific notation with
1 decimal of precision
Red keybind
10
Output (on) Output (off)
Red keybind
Red keybind
11
2.3.7 Aggregate Logic Block
Aggregate logic blocks perform a (variadic) aggregation operation with their inputs and output the result.
They have a display which shows the currently selected operation. Note: due to a bug, when the function
isn’t sum, the output can sometimes be updated instantly without the normal signal propagation delay.
Its settings are shown in figure 15 and are as follows:
• Keybinds: see Keybinds
• Toggle: see Toggle
• Timers: see Timers
• Aggregate function: aggregate operation to perform. Possible values are sum, product, minimum, and
maximum
Red keybind
12
Green keybind
Brightness
[Link] Color Calculation The color displayed as a function of their input value can be determined
with the following formula, where 𝑆 and 𝐵 are the saturation and brightness settings respectively. Figure
17 shows an example of the resulting colors for inputs in the range [−1, 1] with saturation = brightness = 1.
Inputs smaller than −1 result in the [−1, 0] range being repeated, while inputs greater than 1 result in the
[0, 1] range being repeated.
−1 −0.83 −0.67 −0.5 −0.33 −0.17 0 0.17 0.33 0.5 0.67 0.83 1
Input value
Figure 17: Hue light panel color with saturation = brightness = 1 for inputs in the range [−1, 1]
13
3 Common block settings
These are settings shared by all blocks in the game that can be activated with input signals.
3.1 Keybinds
Keybinds are the most common input to activate a block, and all blocks that can be activated have either a
single keybind (green) or two keybinds (green and red).
• All keybinds on a single block act as a single input for each seat
– An AND gate with a green and a red keybind configured will send an output when just pressing
one of the 2 keybinds, but will require someone in each seat that has control over it pressing the
keybind to send an output
– If no keybinds are configured, the input isn’t taken into account. This only makes a difference in
AND gates, which would otherwise be impossible to trigger without keybinds
• The green keybind has a positive value while the red keybind has a negative one. For more information
about input values, see Signals
– For input methods that don’t support analog inputs (keyboards and normal buttons on controllers),
the value is always 1
– For input methods that support analog inputs (controller joysticks and triggers), the value is the
one given by the input method normalized to the range [0, 1]
3.2 Toggle
Toggle allows to make inputs alternate the activation state of a block between on and off without requiring a
continuous input signal to remain active.
• There is a toggle setting associated with positive inputs (below the green keybind) and another with
negative ones (below the red keybind)
• Toggles inputs
– When the sum of the inputs goes from 0 to a different value, multiple things happen depending on
the new value:
1) If the opposite sign of the input is toggled on, it is toggled off instantly
2) If the sign of the input has toggle enabled, it is toggled: if it was off it turns on, and if it was
on it turns off (which will happen on the falling edge of the input). Otherwise, the gate is
enabled normally
– To toggle the output instead of the inputs, make the signal go through another gate with the toggle
3.3 Timers
Timers are a group of settings that allow to automate the activation/deactivation of a block after a set
amount of time.
• Timers apply to the inputs of the block and are shared by all of them, and start as soon as the block
receives a single input. For logic blocks, this still applies even if the block doesn’t meet its conditions
to send an output
• The number will be rounded to have only 2 decimal places when shown on the menu, but the number
which will be used is the one written rounded to 8 decimal places. Due to a bug, only up to 5 characters
can be written, so depending on the exact value the number of decimals which can be used will vary
• All values are specified in seconds
• Delay: amount of time between the block receives an input and the block activates
– Note: each logic gate has an extra delay of 1/60𝑠 due to the state of all the logic gates being
updated once per physics’ frame at the same time
• Duration (previously active time): amount of time before the block automatically deactivates after it
has been activated
– A value of 0 indicates that it will never deactivate automatically
– Shortest pulse length is 1 frame (1/60𝑠), values smaller than this won’t activate the block
14
• Pause (previously inactive time): amount of time before the block reactivates and the duration timer is
restarted, after the duration timer expires
– A value of 0 indicates that the block will never reactivate automatically
– It’s ignored if the duration timer is 0
• During the delay/pause timers, the block is deactivated by overriding the input value with 0
• The order of the timers is as follows: delay → duration → pause → back to duration (if pause is 0 it
ends after the duration ends)
• In the case of the delay and duration timers, even though their values are expressed in seconds, the
game handles them as a number of frames, which can be calculated with seconds ⋅ 60
– If this number is not an integer, it will be rounded down to the nearest integer
– If this number is an integer, it will randomly either be kept as it is or be subtracted one frame
depending on the exact value used, so it’s recommended to add 0.01 to the original number to
make sure it always stays in the correct number of frames
– Pause timers aren’t subject to this, and the exact time in seconds is used for them
15
4 Signals
Signals are the method used to communicate different logic blocks between eachother and other blocks. All
block inputs, both from logic blocks and keybinds, are represented with signals.
• Input/output value: value attached to each signal, usually in the range [−1, 1].
– Math blocks are the only blocks which don’t clamp the sum of their inputs to the [−1, 1] range,
instead they use the range [−(2 − 2−23 ) ⋅ 2127 , (2 − 2−23 ) ⋅ 2127 ] ≈ [−3.403 ⋅ 1038 , 3.403 ⋅ 1038 ]
– They are represented with a standard IEEE 754 single-precision floating-point number
• Truthness value: value that determines if a signal is on or off
– A signal is on if its associated value is not 0. Additionally, for blocks with multiple inputs, the sum
of their inputs must also be non-0 in order for them to be activated
When a block receives a set of inputs, it determines how it is activated based on the value of their sum.
Blocks with a single configurable keybind, except the gyro stabilizer and hue light panels, additionally use the
absolute value before interpreting it, which makes both signs equivalent. The resulting value represents the
percentage of power that whatever it activates will use, applied to the value set in its settings as a multiplier
(if applicable). Values modified for each block are in table 1. Some important notes:
• For hinges/wings the rotation speed depends on the max angle set in their settings and not on the
angle achieved with the input value, resulting in faster speeds with fractional input values for the same
final angle
• Due to a bug, fractional inputs in hinges/wings result in angles way lower than they should be. See
appendix Input value to multiplier for hinges/wings with control surfaces for more information
• Due to a bug, close to 0 inputs in servos with hold position also result in lower speeds as well. See
appendix Input value to speed for servos with hold position for more information
• For rotating servos, an angle of “infinity” actually represents 360 degrees
• For the gyro stabilizer, it only works with disabled by default, and negative values make it stabilize in
the opposite direction
16
5 Useful Circuits
This section contains commonly used logic circuits and how to make them, to aid in the design and
understanding of more complex logic circuits.
5.4 Counter
• Stores the value of a variable with 𝑛 possible (discrete) values
• Depending on how it’s made, it can be 1 or 2 way and have cycle or not
– 1-way: the value can only be increased
– 2-way: the value can be both increased and decreased
– Cycle: determines if trying to increase/decrease the value past its maximum/minimum will result
in it cycling back to the smallest/biggest value or staying at the maximum/minimum value
– Base designs described are 1-way without cycle, with the modifications needed to implement 2-way
or cycle being explained afterwards
• The complexity of a design is the amount of logic gates used by it without counting the ones used to
create a startup pulse or always on sensors (those can be reused)
• There are 3 ways of doing it: general circuit (base 𝑁), decimal (base 10) and binary (base 2). Which
one is least complex depends on the situation
– The general circuit and decimal methods can be implemented using logic gates or accumulators.
Generally accumulator-based counters are less complex, but logic gate based designs will still be
described as they can be less complex under some circumstances (like needing a counter which
only changes its value when a function of its current value is true)
17
Cell 1 Cell 𝑘 Cell 𝑘 + 1 Cell 𝑛
Toggled OR gate Toggled OR gate Toggled OR gate Toggled OR gate
with 1 frame with 1 frame with 1 frame with 1 frame
delay (output) delay (output) delay (output) delay (output)
⋯ ⋯
1 frame pulse
generator (input)
Figure 18: Diagram of the general method counter (logic gates implementation)
• To add cycle, add an AND gate to the last cell configured in the same way as the others and using the
first cell as its next cell
• To make it 2-way, add a new AND gate to each cell configured in the same way as the other one but
going in the opposite direction and using a different pulse generator as input
• Requires a startup pulse to one of the toggled OR gates to work (achieved with a 1 frame pulse
generator)
• Complexity
– 1-way: 2𝑛
– 1-way+cycle: 2𝑛 + 1
– 2-way: 3𝑛
– 2-way+cycle: 3𝑛 + 1
• Takes 3 frames to update
• Example blueprints: 1-way, 1-way+cycle, 2-way and 2-way+cycle
18
pulse generator to get the normal input behaviour
• To add cycle, connect the comparator with the biggest threshold to an AND gate with the positive
accumulator input as its second input. Connect that AND gate to an arithmetic logic block set
to multiplication with a −1000 constant and 0.02 duration, and that arithmetic logic block to the
accumulator
– The normal input to the accumulator must come from a 1 frame pulse generator
– If using the circuit as 2-way, repeat the process with the comparator with the smallest threshold
and the negative input of the accumulator. The AND gate should have an additional −2 always on
input (which can be achieved with an arithmetic logic block set to addition with a −1000 constant).
The arithmetic logic block and input pulse generator can be reused, using negative inputs to reduce
the value
• Complexity
– 1-way: 𝑛 + 1
– 1-way+cycle: 𝑛 + 4
– 2-way: 𝑛 + 1
– 2-way+cycle: 𝑛 + 5
• Takes 2 frames to update without cycle, and 3 frames otherwise
• Example blueprints: 1-way, 1-way+cycle, 2-way and 2-way+cycle
All AND gates All AND gates All AND gates All AND gates
Input circuit
1 frame pulse
OR gate
generator (input)
Figure 19: Diagram of the decimal method counter (logic gates implementation)
• To add cycle, add cycle to the last cell and remove the OR gate from the input circuit
• To make it 2-way, duplicate the input circuit but connect all OR gates except the first from each cell to
19
the OR gate. Then, make each cell 2-way, connect the cells in the same direction using the first OR
gate of each cell rather than the last, and connect the new input circuit to all AND gates for the second
direction
• Might require a decoder (unless you want to show numbers on a screen)
– To create it, take 𝑛 AND gates and assign a different combination of 1 output gate from each cell
to each of them (if you only need to use it combined with other circuits, you can combine all of
their decoders into a single one to use less gates)
– Has a complexity of 𝑛 gates
• Requires a startup pulse to one of the toggled OR gates on each cell to work (achieved with a 1 frame
pulse generator)
• Complexity
– 1-way: 2⌈ ⌈log𝑛 𝑛⌉−1 ⌉ + 20⌈log10 𝑛⌉ − 19
10 10
– 1-way+cycle: 2⌈ 𝑛
⌉ + 20⌈log10 𝑛⌉ − 19
10⌈log10 𝑛⌉−1
– 2-way: 3⌈ 𝑛
⌉ + 30⌈log10 𝑛⌉ − 28
10⌈log10 𝑛⌉−1
– 2-way+cycle: 3⌈ ⌈log𝑛 𝑛⌉−1 ⌉ + 30⌈log10 𝑛⌉
− 28
10 10
• Takes 3 frames to update with cycle and 4 frames otherwise
• Example blueprints: 1-way, 1-way+cycle, 2-way and 2-way+cycle
– 1-way+cycle: ⌈ 𝑛
⌉ + 13⌈log10 𝑛⌉ − 9
10⌈log10 𝑛⌉−1
– 2-way: ⌈ 𝑛
⌉ + 14⌈log10 𝑛⌉ − 7
10⌈log10 𝑛⌉−1
20
– 2-way+cycle: ⌈ ⌈log𝑛 𝑛⌉−1 ⌉ + 14⌈log10 𝑛⌉ − 8
10 10
• Takes 3 frames to update
• Example blueprints: 1-way, 1-way+cycle, 2-way and 2-way+cycle
Input Circuit
1 frame pulse
NAND gate
generator (input)
• To add cycle, remove the NAND gate from the input circuit and the AND gate on the first cell, and
connect the 1 frame pulse generator directly to the OR gate in the first cell
• To make it 2-way, add a NOT gate to each cell with its OR gate as input and a new AND gate connected
in the same way as the old AND gate, but using the NOT gate of all previous cells as input instead of
the OR gates. Then replace the NAND gate on the input circuit with an OR gate and duplicate it
(with the copy being connected to the new AND gates on each cell rather than the old ones). Connect
the NOT gate of all the cells to the OR gate of the first input circuit, and the OR gate of all the cells
to the OR gate of the second input circuit
• Might require a decoder
– To create it, add a NOT gate to each cell and replace the NAND gate of the input circuit with
an OR gate like in the 2-way version (if using the 1-way versions). Then, take 𝑛 AND gates and
assign each of them a different combination of either the OR or NOT from each cell (if you only
need to use it combined with other circuits you can combine all of their decoders into a single one
to use less gates)
– Has a complexity of ⌈log2 𝑛⌉ + 𝑛 − 1 for the 1-way version, ⌈log2 𝑛⌉ + 𝑛 for the 1-way+cycle version
and 𝑛 for the 2-way versions
• Complexity
– 1-way: 2⌈log2 𝑛⌉ + 3
– 1-way+cycle: 2⌈log2 𝑛⌉
– 2-way: 4⌈log2 𝑛⌉ + 4
– 2-way+cycle: 4⌈log2 𝑛⌉
• Takes 3 frames to update for 1-way+cycle and 4 frames otherwise
• Example blueprints: 1-way, 1-way+cycle, 2-way and 2-way+cycle
21
5.4.4 When to use each method
1-way 2-way
• For 𝑛 > 10 use the binary circuit • For 𝑛 > 23 use either the binary or deci-
mal circuit
Show values directly on a screen (only numbers Show values directly on a screen (only numbers
for 𝑛 > 18): for 𝑛 > 23):
• For 𝑛 ≤ 18 use the general circuit • For 𝑛 ≤ 23 use the general circuit
• For 𝑛 > 18 use the decimal circuit • For 𝑛 > 23 use the decimal circuit
Notes:
• Calculated for 𝑛 ≥ 3, for 𝑛 = 2 a latch is always best
• All mentions of the general and decimal circuits refer to the accumulator-based implementations
• If an individual decoder is needed, the general circuit is always best
• For 2-way without an individual decoder, decimal and binary circuits are very close in terms of
complexity. Use their complexity formulas to figure out which is best for your use case. If they have
the same complexity, decimal is better due to being faster
• This is just based on the amount of logic gates each circuit uses (unless there is a tie, in which case
update speed is used). However, the amount of time it takes for the system to update might also matter
depending on the situation. In that case, refer to the circuits’ descriptions to compare the speed for the
needed use case
22
OR Gate with OR Gate with
toggle keybind toggle keybind
Input Signals
(can be multiple Output Blocks
blocks)
• Example blueprint
23
6 Historical Circuits
This section contains old circuits that were previously in Useful Circuits, but have since been superseded by
new blocks. They are kept here for historical reasons and in case they are seen in older circuits.
• Note: the input signal is reversed. This means that a negative value increases the stored value while a
positive value decreases it
• Keybinds can be added to one of the OR gates in the feedback loop to go to the max/min value. The
green keybind sets the min value while the red keybind sets the max value
• Example blueprint
• Python script to simulate the behaviour (input value is automatically reversed):
def clamp(x: float) -> float:
return min(max(x, -1), 1)
24
def update(
feedback_top: float, feedback_bottom: float, user_input: float
) -> tuple[float, float]:
return (
clamp(feedback_bottom - user_input + 1),
clamp(feedback_top - user_input - 1)
)
feedback_top, feedback_bottom = 1, 0
print_state(feedback_top, feedback_bottom)
while True:
user_input = input("Enter input (between -1 and 1, Q to quit): ")
if user_input.lower() == "q":
break
try:
user_input = float(user_input)
except ValueError:
print("Invalid input. Try again")
continue
feedback_top, feedback_bottom = update(feedback_top, feedback_bottom, user_input)
print_state(feedback_top, feedback_bottom)
• Credits to Precache for figuring out this circuit
25
A Input value to multiplier for hinges/wings with control surfaces
Due to a bug, the angle by which hinges/wings/other blocks with the “steering help” setting rotate doesn’t
scale linearly with the input value. This section contains the multipliers used for many input values, found
experimentally. Some notes about this process:
• Final angle is the resulting angle of the hinge measured with a max angle of 90 degrees and an error of
±0.005 degrees
• The multiplier was calculated with multiplier = final90angle
• A calculator using this data made by confusionextended can be found here
26
0.860 44.025 0.48916667 0.590 10.545 0.11716667 0.263 00.905 0.01005556
0.855 42.600 0.47333333 0.580 10.010 0.11122222 0.262 00.000 0.00000000
0.850 41.200 0.45777778 0.570 09.500 0.10555556 0.261 00.000 0.00000000
0.845 39.830 0.44255556 0.560 09.000 0.10000000 0.260 00.000 0.00000000
0.840 38.505 0.42783333 0.550 08.525 0.09472222 0.250 00.000 0.00000000
0.835 37.200 0.41333333 0.540 08.065 0.08961111 0.200 00.000 0.00000000
0.830 35.940 0.39933333 0.530 07.620 0.08466667 0.150 00.000 0.00000000
0.825 34.715 0.38572222 0.520 07.190 0.07988889 0.100 00.000 0.00000000
0.820 33.530 0.37255556 0.510 06.780 0.07533333 0.050 00.000 0.00000000
0.815 32.380 0.35977778 0.500 06.380 0.07088889 0.000 00.000 0.00000000
0.490 06.005 0.06672222
0.8
0.6
Multiplier
𝑦=𝑥
0.4
𝑓(𝑥)
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Input value
Figure 23: Graph of the multiplier for hinges as a function of the input value
27
B Input value to speed for servos with hold position
Due to a bug, the speed at which rotating servos with hold position rotate changes with the input value
when small values are used. This section contains the speed multipliers used for many input values, found
experimentally. Some notes about this process:
• Speed is the speed required on a servo with an input value of 1 to match the speed of a servo with a
speed being tested and the given input value, with an error of ±0.00005 speed units for speeds lower
than 1 and an error of ±0.0005 otherwise
– To compare the speeds of the servos, they were run continuously for some time and the final angle
was compared
For servos with 360 angle, they were run for 3 min
For servos with less than 360 angle, they were run for slightly less than the time required to
reach the maximum angle
– Servos with a configured speed of 1 and 2 as well as 360 and 180 angle were tested, with other
speeds/angles being checked to verify the results
• 𝑓𝑠,𝑎 (𝑥) represents the resulting speed of a servo with 𝑠 speed, 𝑎 angle, and 𝑥 input value
• The resulting speed can be approximated by 𝑓𝑠,𝑎 ̂ (𝑥) = min ( 𝑥 ⋅ 𝑎 , 𝑠)
0.0611 90
1.8
1.6 𝑥 360
𝑦= 0.0611 ⋅ 90 𝑥 180
𝑦= 0.0611 ⋅ 90
1.4
1.2
𝑓2,360 (𝑥)
Speed
1
𝑓2,180 (𝑥)
0.8
0.2
0
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05 0.055 0.06
Input value
Figure 24: Graph of the speed for servos with hold position as a function of the input value
28
Angle 180 Angle 360
Table 4: Raw data of the input value speed for servos with hold position
29
C Tips
• If you want your system to not modify the input that passes through, configure all of the logic gates to
have an output scale of 1. Then, if a gate needs to have more inputs other than the original one, make
sure the sum of the output values of those other inputs is 0. This will make the output which reaches
whatever your system activates be the output that the sensors/keybinds had
• Arithmetics logic blocks can be used to get always on signals with a constant value by using the addition
operation with the desired constant. The signal can be toggled by setting the operation to multiplication
and using a +1 input
• Organize the logic gates on a testbed while working with them before adding them to your vehicle,
having the logic gates organized as opposed to scattered across your entire vehicle will make remembering
what each gate does easier. There is no wrong way to organize them as long as they aren’t randomly
placed, but the way I do it is by splitting the gates into groups depending on function, inside each
group the arrows of logic gates point towards the outputs of that gate and away from its inputs, then I
put the groups of logic gates that a group outputs to in the direction the arrows of the logic gates that
the group uses as output are pointing, while I put the groups that group uses as input in the opposite
direction
• If you have problems figuring out how to do something with logic gates, draw it on paper first, being
able to see all connections at once helps a lot. Another method is writing it with if statements as they
translate to logic gates easily (each logic gate is an individual if statement)
• If you still have any questions or need help with something, feel free to contact me on the
official Trailmakers discord server
Made by ALVAROPING1
30