In other languages: Deutsch Русский 中文

Tutorial:Combinator tutorial: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Changed links going to the redirect Tutorial:Circuit-network_Cookbook to go to Tutorial:Circuit network cookbook.)
(formatting cleanup, removed 1 design that didnt have any explanation)
Line 7: Line 7:
Circuit wires act like a wire bus in electronics, it carries information in the connected wires, meaning that '''if there are similar signals on a wire, it will add them automatically, unless if it is a different signal, that means it will be carried in that wire as well, but as a different signal.'''
Circuit wires act like a wire bus in electronics, it carries information in the connected wires, meaning that '''if there are similar signals on a wire, it will add them automatically, unless if it is a different signal, that means it will be carried in that wire as well, but as a different signal.'''


When cross-connecting combinators '''it's good practice to use the unused color to cross-connect, this will split the input and output networks and prevent unwanted inputs from accidentally connecting to a larger circuit network.''' Combinators will sum the red &/or green inputs prior to calculation, so either color can be used when wiring the output back to the input, but in most cases, it is more useful to use the opposing colour of the wire so that it will not interfere with the resulting output and input.
When cross-connecting combinators '''it's good practice to use the unused color to cross-connect, this will split the input and output networks and prevent unwanted inputs from accidentally connecting to a larger circuit network.''' Combinators will sum the red &/or green inputs prior to calculation, so either color can be used when wiring the output back to the input, but in most cases, it is more useful to use the opposing color of the wire so that it will not interfere with the resulting output and input.


''There is also an example heavy [[Circuit-network_Cookbook|circuit network cookbook]] that you may find helpful to learn and refer to about circuit networks.''
''There is also an example heavy [[Tutorial:circuit network cookbook|circuit network cookbook]] that you may find helpful to learn and refer to about circuit networks.''


== Virtual Signals ==
== Virtual signals ==


===Everything Wildcard:===
=== Everything wildcard ===
----


This Red Wildcard serves to check all the specifed input signals.
This red wildcard serves to check all the specified input signals.


As the Decider Combinator, <br />
When used in the decider combinator
its input is used to serve if all inputs meets the specified signals or variables. <br />
* as input it checks if all inputs meet the specified condition.
its output is used to serve output every signal. <br />
* as output it serves output to every signal.


Side note: "Everything" outputs true by default even if there is no signal to guarantee if that is true. ''Everything is false when every input does not meet the condition, otherwise, output true.''
Side note: "Everything" outputs true by default even if there is no signal to guarantee that it is true. ''Everything is false when every input does not meet the condition, otherwise, output true.''


===Anything Wildcard:===
=== Anything wildcard ===
----


This Green Wildcard serves to check all the specifed input signals.
This green wildcard serves to check all the specified input signals.


As the Decider Combinator,
When used as input in the decider combinator it checks if any of the inputs meet the specified condition.
its input is used to serve if any of its inputs meets the specified signals or variables.


Side note: "Anything" outputs false by default if there is no signal to guarantee if it is true. ''Anything is false when any of inputs do not meet the condition, otherwise, it is true.''
Side note: "Anything" outputs false by default if there is no signal to guarantee that it is true. ''Anything is false when any of inputs do not meet the condition, otherwise, it is true.''


===Each Wildcard:===
=== Each wildcard ===
----


This Yellow Wildcard serves to check for each the specifed input signals.
This yellow wildcard serves to check for each the specified input signals.


As the Decider Combinator, <br />
When used in the decider combinator
its input is used to serve if any inputs meets the specified signals or variables. <br />
* as input it checks on all inputs if it meets the specified condition.
its output is used to serve output the each variable. <br />
* as output it serves output to each signal.


As the Arithmetic Combinator, <br />
When used as input in the arithmetic combinator it serves each input, then the following summations are summed and outputted, with each signal as its own respective signals.
its input is used to serve each input, then the following summations are summed and outputted, with each signal as its own respective signals.


== Input Isolator & Gate ==
== Input insulator & gate ==
An arithmetic combinator set to (In: Each + 0, Out: Each) can be used to swap wire colors and as an isolator to prevent downstream logic from backfeeding into the circuit network's inputs.
An arithmetic combinator set to (In: Each + 0, Out: Each) can be used to swap wire colors and as an insulator to prevent downstream logic from backfeeding into the circuit network's inputs.


A decider combinator set to (Out: Everything, Input-> Output) will also function as an isolator as long as the set logic condition is true. This can also selectively pass or 'gate' inputs only when desired. This could be used to sequentially poll remote train stations for their chest contents, and include only desired stations.
A decider combinator set to (Out: Everything, Input-> Output) will also function as an insulator as long as the set logic condition is true. This can also selectively pass or 'gate' inputs only when desired. This could be used to sequentially poll remote train stations for their chest contents, and include only desired stations.


== Set/Reset Latching Switch ==
== Set/Reset latching switch ==
You want something to SET a trigger at some quantity, but then STAY on until that quantity hits some other value, the RESET value. You'll need one decider combinator and one arithmetic combinator. Two decider combinators and a constant combinator can also be used for more complex multi-channel conditions.
You want something to SET a trigger at some quantity, but then STAY on until that quantity hits some other value, the RESET value. You'll need one decider combinator and one arithmetic combinator. Two decider combinators and a constant combinator can also be used for more complex multi-channel conditions.


Setup the first decider combinator to the desired set conditional and to output a 1. Then connect the output to the input of an arithmetic combinator, and configure it to multiply by the bias value, the difference between the set and reset values, and wire the arithmetic output to the input of the decider. The arithmetic output channel MUST be set the same as the decider's input channel. That's it! Whenever your set conditional is reached, the decider will output a '1', and the bias of the arithmetic combinator will be applied. This will 'hold' the output true until the value goes back below the reset point.
Setup the first decider combinator to the desired set conditional and to output a 1. Then connect the output to the input of an arithmetic combinator, and configure it to multiply by the bias value, the difference between the set and reset values, and wire the arithmetic output to the input of the decider. The arithmetic output channel MUST be set the same as the decider's input channel. That's it! Whenever your set conditional is reached, the decider will output a '1', and the bias of the arithmetic combinator will be applied. This will 'hold' the output true until the value goes back below the reset point.


Here's a more specific example :
Here's a more specific example, I want the pump to run when petrol reach 2000, and turn off when reach 200:
i want the pump to run when petrol reach 2000, and turn off when reach 200.<br>
* Tank -> in decider
only with green wire<br>
* out decider -> in arithmetic
Tank -> in decider<br>
* out arithmetic -> in decider
out decider-> in arithmetic<br>
* green wire from in decider, to pump
out arithmetic -> in decider<br>
green wire from in decider, to pump<br>


Pump have the same condition as the decider (Petrol > 2000)
Pump has the same condition as the decider (Petrol > 2000)


Decider : Petrol > 2000<br>
* Decider: Petrol > 2000
out : A = 1<br>
* out: A = 1
Arithmetic : A x 1800 (2000 - 200 )<br>
* Arithmetic: A x 1800 (2000 - 200 )
out : petrol<br>
* out: petrol
[[File:Factorio combinator switch.png|620px]]
[[File:Factorio combinator switch.png|620px]]


Backup steam power example with detailed configuration and explanation can be found here:<br />[[Tutorial:Circuit network cookbook#SR_latch_-_single_decider_version|Tutorial:Circuit-network_Cookbook#SR latch - single decider version]]
Backup steam power example with detailed configuration and explanation can be found here:<br />[[Tutorial:Circuit network cookbook#SR_latch_-_single_decider_version|Tutorial:Circuit-network_Cookbook#SR latch - single decider version]]


== Smart Train Loading ==
== Smart train loading ==
This solves the problem of loading logistics into chests, which tend to be unequal and is slower in the rate of loading logistics into the cargo of trains.
This solves the problem of loading logistics into chests, which tend to be unequal and is slower in the rate of loading logistics into the cargo of trains.


Line 90: Line 83:
Any non-zero input condition will create a basic clock; incrementing the stored value by the sum of all connected input values every cycle. A single pulse of an input will cause a single increment by the pulsed value. Reset to zero occurs whenever the set condition is no longer met, or if a negative pulse equal to the input occurs.
Any non-zero input condition will create a basic clock; incrementing the stored value by the sum of all connected input values every cycle. A single pulse of an input will cause a single increment by the pulsed value. Reset to zero occurs whenever the set condition is no longer met, or if a negative pulse equal to the input occurs.


== Basic Clocks ==
== Basic clocks ==
[[File:Timer.png|thumb|right|377px|A basic clock. 30 ticks is the ceiling for Signal 1; which is continuously added.]]
[[File:Timer.png|thumb|right|377px|A basic clock. 30 ticks is the ceiling for Signal 1; which is continuously added.]]
Clocks are constructed by having the output of a combinator tied back to its own input, such that every cycle advances its own count. Either the arithmetic combinator or the decider combinator can be used.
Clocks are constructed by having the output of a combinator tied back to its own input, such that every cycle advances its own count. Either the arithmetic combinator or the decider combinator can be used.
Line 104: Line 97:
[[File:Onetime_Clock.png|thumb|none|360px|One-time clock. Runs until T=Z+1. Reset via R>0.]]
[[File:Onetime_Clock.png|thumb|none|360px|One-time clock. Runs until T=Z+1. Reset via R>0.]]


== Pulse Generators ==
== Pulse generators ==


Connecting an additional (=) decider combinator to the output of a basic clock will create a pulse generator, and will pulse a single output every time the clock cycles through the set condition. Any output value can be used, either directly from the clock sequence (input->output), a 1, or some value on a separate logic channel on the circuit network, such as set by a constant combinator. or by the circuit network.<br />
Connecting an additional (=) decider combinator to the output of a basic clock will create a pulse generator, and will pulse a single output every time the clock cycles through the set condition. Any output value can be used, either directly from the clock sequence (input->output), a 1, or some value on a separate logic channel on the circuit network, such as set by a constant combinator. or by the circuit network.<br />
Line 114: Line 107:
A counter is used to count the number of input events, and output the sum of that count. Any pulsing input into a decider combinator configured input -> output and wired between output and input will create a counter, but this input must be zero at all other times or else the combinator will run away like a clock. A pulse generator is normally used to accomplish this. Combining several gating decider isolators set with sequential conditionals, a clock, and a pulse generator to the input of a counter will allow remote polling and counting of each isolator's contents.
A counter is used to count the number of input events, and output the sum of that count. Any pulsing input into a decider combinator configured input -> output and wired between output and input will create a counter, but this input must be zero at all other times or else the combinator will run away like a clock. A pulse generator is normally used to accomplish this. Combining several gating decider isolators set with sequential conditionals, a clock, and a pulse generator to the input of a counter will allow remote polling and counting of each isolator's contents.


== Logic Gates ==
== Logic gates ==


==='''Unary NOT'''===
==='''Unary NOT'''===
Line 287: Line 280:
|}
|}


== Memory Cells ==
== Memory cells ==


==='''Simple Latch'''===
=== Simple latch ===


When looping the combinator to itself, use a different colour of wire from your main inputs or outputs.  
When looping the combinator to itself, use a different color of wire from your main inputs or outputs.  


[[File:SimpleLatchv2.png|300px]]
[[File:SimpleLatchv2.png|300px]]
Line 322: Line 315:
''Input 1 is Set, while Input 2 is Reset.''
''Input 1 is Set, while Input 2 is Reset.''


==='''Binary Cell'''===
=== Positive cell ===
 
RS NOR Latch
[[File:RS-NOR.png|500px]]
 
 
 
==='''Positive Cell'''===


Cell for storing a positive value, with reset support:
Cell for storing a positive value, with reset support:
Line 341: Line 327:
'''Address Enable Switch'''
'''Address Enable Switch'''


==='''Positives and Negatives Cell'''===
=== Positives and negatives cell ===


This cell can store negatives or positives. Reset is done on a dedicated line. Additionally, a 1-tick burst is handled properly. [https://forums.factorio.com/viewtopic.php?f=193&t=60330&p=362377#p362377 Forum post].
This cell can store negatives or positives. Reset is done on a dedicated line. Additionally, a 1-tick burst is handled properly. [https://forums.factorio.com/viewtopic.php?f=193&t=60330&p=362377#p362377 Forum post].
Line 353: Line 339:


== See Also ==
== See Also ==
*[http://www.factorioforums.com/forum/viewtopic.php?f=18&t=14556 Combinators 101 (Tutorial)]
* [http://www.factorioforums.com/forum/viewtopic.php?f=18&t=14556 Combinators 101 (Tutorial)]
*[[Arithmetic combinator]]
* [[Tutorial:Circuit network cookbook]]
*[[Constant combinator]]
* [[Circuit network]]
*[[Decider combinator]]
* [[Arithmetic combinator]]
*[[Circuit network]]
* [[Constant combinator]]
*[[Circuit-network_Cookbook]]
* [[Decider combinator]]

Revision as of 11:35, 5 November 2018

Introduction

Combinator logic is achieved by cross-connecting outputs to inputs in such a way to achieve the desired logic. While advanced logic requires a multitude of combinators, some very useful basic logic can be achieved using only a handful of combinators. Combinator logic works because Factorio only updates at 60 times per second, such that combinators analyze their logic in a step, and then sum and/or decide the resulting output values on the next step.

When logic values are computed by combinators, the outputs are not recognized by the circuit network until the following step. So when a decider combinator is used to detect a certain input condition, it's output value will not take effect on the circuit network until the next step. This behavior is important to remember and can result in sequencing errors and significant delays when multiple combinators are connected in series.

Circuit wires act like a wire bus in electronics, it carries information in the connected wires, meaning that if there are similar signals on a wire, it will add them automatically, unless if it is a different signal, that means it will be carried in that wire as well, but as a different signal.

When cross-connecting combinators it's good practice to use the unused color to cross-connect, this will split the input and output networks and prevent unwanted inputs from accidentally connecting to a larger circuit network. Combinators will sum the red &/or green inputs prior to calculation, so either color can be used when wiring the output back to the input, but in most cases, it is more useful to use the opposing color of the wire so that it will not interfere with the resulting output and input.

There is also an example heavy circuit network cookbook that you may find helpful to learn and refer to about circuit networks.

Virtual signals

Everything wildcard

This red wildcard serves to check all the specified input signals.

When used in the decider combinator

  • as input it checks if all inputs meet the specified condition.
  • as output it serves output to every signal.

Side note: "Everything" outputs true by default even if there is no signal to guarantee that it is true. Everything is false when every input does not meet the condition, otherwise, output true.

Anything wildcard

This green wildcard serves to check all the specified input signals.

When used as input in the decider combinator it checks if any of the inputs meet the specified condition.

Side note: "Anything" outputs false by default if there is no signal to guarantee that it is true. Anything is false when any of inputs do not meet the condition, otherwise, it is true.

Each wildcard

This yellow wildcard serves to check for each the specified input signals.

When used in the decider combinator

  • as input it checks on all inputs if it meets the specified condition.
  • as output it serves output to each signal.

When used as input in the arithmetic combinator it serves each input, then the following summations are summed and outputted, with each signal as its own respective signals.

Input insulator & gate

An arithmetic combinator set to (In: Each + 0, Out: Each) can be used to swap wire colors and as an insulator to prevent downstream logic from backfeeding into the circuit network's inputs.

A decider combinator set to (Out: Everything, Input-> Output) will also function as an insulator as long as the set logic condition is true. This can also selectively pass or 'gate' inputs only when desired. This could be used to sequentially poll remote train stations for their chest contents, and include only desired stations.

Set/Reset latching switch

You want something to SET a trigger at some quantity, but then STAY on until that quantity hits some other value, the RESET value. You'll need one decider combinator and one arithmetic combinator. Two decider combinators and a constant combinator can also be used for more complex multi-channel conditions.

Setup the first decider combinator to the desired set conditional and to output a 1. Then connect the output to the input of an arithmetic combinator, and configure it to multiply by the bias value, the difference between the set and reset values, and wire the arithmetic output to the input of the decider. The arithmetic output channel MUST be set the same as the decider's input channel. That's it! Whenever your set conditional is reached, the decider will output a '1', and the bias of the arithmetic combinator will be applied. This will 'hold' the output true until the value goes back below the reset point.

Here's a more specific example, I want the pump to run when petrol reach 2000, and turn off when reach 200:

  • Tank -> in decider
  • out decider -> in arithmetic
  • out arithmetic -> in decider
  • green wire from in decider, to pump

Pump has the same condition as the decider (Petrol > 2000)

  • Decider: Petrol > 2000
  • out: A = 1
  • Arithmetic: A x 1800 (2000 - 200 )
  • out: petrol

File:Factorio combinator switch.png

Backup steam power example with detailed configuration and explanation can be found here:
Tutorial:Circuit-network_Cookbook#SR latch - single decider version

Smart train loading

This solves the problem of loading logistics into chests, which tend to be unequal and is slower in the rate of loading logistics into the cargo of trains.

To setup the design, you require an Arithmetic Combinator, as well as Red and Green wires. Wire all the chests used, to the input of the Arithmetic Combinator. Then write (Logistics Item / -Amount of chests) and as the output as the Logistics Item in the Arithmetic Combinator, this will average the amount of items within the chests. Lastly, wire all the inserters used to the output of the Arithmetic Combinator and have the other color of the wire be wired to the adjacent chest. Have the inserters enabled when Logistics Item < 1.

A more visual representation as well as questions about the design can be found in a reddit post: MadZuri's smart loading train station.

Explanation of why this works: It compares the average amount of total items within the chests and the chest adjacent to the inserter so that it activates when the average number of items is higher than the amount within the chest. The reason for why the division denominator is negative is because if the items in the chests are 0, it basically makes it so that it adds 1 to the equation.

Memory

How to store a constant value for later use, either for a basic counter or for more advanced logic. A decider combinator wired output tied to input and configured greater than zero (for positive values), input -> output will 'hold' a value, as long as all other inputs on the network are zero.

Any non-zero input condition will create a basic clock; incrementing the stored value by the sum of all connected input values every cycle. A single pulse of an input will cause a single increment by the pulsed value. Reset to zero occurs whenever the set condition is no longer met, or if a negative pulse equal to the input occurs.

Basic clocks

A basic clock. 30 ticks is the ceiling for Signal 1; which is continuously added.

Clocks are constructed by having the output of a combinator tied back to its own input, such that every cycle advances its own count. Either the arithmetic combinator or the decider combinator can be used.

An arithmetic combinator tied to itself is fun to watch and will happily run-away, but requires additional control logic to reset.

A self-resetting clock requires just a single decider combinator with output wired to input and configured with Less Than (<) and Input -> Output. When a constant combinator is then connected to the input, every cycle it will count up by the value of the Constant Combinator until the set conditional value is reached, then output a zero which will be summed with the constant combinator, and reset the process.

The clock sequence will not include zero, will begin at the value set by the constant combinator, and will include whatever value eventually causes the conditional to be false. An arithmetic combinator can modify the clock sequence but remember its outputs will occur one cycle later than the clock cycle values.

A clock that only counts once can be built using the following setup:

One-time clock. Runs until T=Z+1. Reset via R>0.

Pulse generators

Connecting an additional (=) decider combinator to the output of a basic clock will create a pulse generator, and will pulse a single output every time the clock cycles through the set condition. Any output value can be used, either directly from the clock sequence (input->output), a 1, or some value on a separate logic channel on the circuit network, such as set by a constant combinator. or by the circuit network.
PulseGen.png

  • The value 1 can be written as any positive integer, so long as it is within the cap or ceiling of your timer.
  • As an example from the above timer, this light will pulse every 1st tick after the timer reaches 30 ticks, making it pulse 1/30th of a second, as Factorio updates at 60 times per second.

Counter

A counter is used to count the number of input events, and output the sum of that count. Any pulsing input into a decider combinator configured input -> output and wired between output and input will create a counter, but this input must be zero at all other times or else the combinator will run away like a clock. A pulse generator is normally used to accomplish this. Combining several gating decider isolators set with sequential conditionals, a clock, and a pulse generator to the input of a counter will allow remote polling and counting of each isolator's contents.

Logic gates

Unary NOT


NOT.png

Truth Table:

Input Output
0 1
1 0

Binary OR


OR.png

Truth Table:

Input 1 Input 2 Output
0 0 0
0 1 1
1 0 1
1 1 1

*Note: The Arithmetic Combinator's OR option is bitwise.

Binary NOR


NOR.png

Truth Table:

Input 1 Input 2 Output
0 0 1
0 1 0
1 0 0
1 1 0


Binary XOR


XOR.png

Truth Table:

Input 1 Input 1 Output
0 0 0
0 1 1
1 0 1
1 1 0

*Note: The Arithmetic Combinator's XOR option is bitwise.

Binary AND


AND.png

Truth Table:

Input 1 Input 2 Output
0 0 0
0 1 0
1 0 0
1 1 1

*Note:The Arithmetic Combinator's AND option is bitwise.

Trinary AND


TrinaryAND.png

Truth Table:

Input 1 Input 2 Input 3 Output
0 0 0 0
0 1 0 0
0 0 1 0
0 1 1 0
1 0 0 0
1 1 0 0
1 0 1 0
1 1 1 1

Binary NAND


NAND.png

Truth Table:

Input 1 Input 2 Output
0 0 1
0 1 1
1 0 1
1 1 0

Binary XNOR/XAND


XAND.png

Truth Table:

Input 1 Input 2 Output
0 0 1
0 1 0
1 0 0
1 1 1

Memory cells

Simple latch

When looping the combinator to itself, use a different color of wire from your main inputs or outputs.

SimpleLatchv2.png

Truth Table:

Output 1 Input 1 Input 2 Output 1 (t+1)
0 0 0 0
0 1 0 1
0 0 1 0
0 1 1 0
1 0 0 1
1 1 0 1 (2)
1 0 1 0
1 1 1 1 (2)

Output 1 is the green wire loop seen in the picture, it carries the value to latch.

Input 1 is Set, while Input 2 is Reset.

Positive cell

Cell for storing a positive value, with reset support:

AdvancedMemoryCell.png

Connect the desired value as signal 3 on the right side to set the memory cell and connect a negative value as signal 3 to reset the cell. *Please note the arithmetic combinator's output should be facing the opposite direction of the decider combinators.

This particular cell design does not work properly on a one-tick burst of input. Input must be held for at least 2 ticks.

Address Enable Switch

Positives and negatives cell

This cell can store negatives or positives. Reset is done on a dedicated line. Additionally, a 1-tick burst is handled properly. Forum post.

  • The output M (memory) is the last non-zero input I (Input).
  • A non zero R (reset) signal sets the output to zero.
  • 1-tick bursts of R or I are handled properly.
  • Negatives are handled properly.

Memory cell with negatives.png

See Also