Combinator Contraptions

This board is to show, discuss and archive useful combinator- and logic-creations.
Smart triggering, counters and sensors, useful circuitry, switching as an art :), computers.
Please provide if possible always a blueprint of your creation.
XKnight
Filter Inserter
Filter Inserter
Posts: 329
Joined: Thu May 28, 2015 10:40 pm
Contact:

Re: Combinator Contraptions

Post by XKnight »

Lupoviridae wrote:I came up with my own register, capable of storing any value for any given items. For example, it could store 512 iron plates, 210 copper, and 123 coal, all in one register. It essentially takes a snapshot of everything currently on the red circuit.
A couple things to keep in mind:
iE means output Everything (input count)
In implementation, the wires labled red and green would all be connected to a main bus. I ommitted this in the diagram to make it easier to read.
Input for each box is on the left, output is on the right.

Here's the wiring diagram:
EPSON004.JPG
Combinator 6 in the diagram is what does the heavy lifting, and it works by using "pulsed" (single tick length) signals. For this reason I call it a "Pulsed-Value Register" or "PVR".

In this setup, the green wire carries the read ("0") and write ("1") signals as well as the address ("A"), while the red wire carries data.

The first pulse of a green signal to that combinator causes it to remember all current input values. The next clears the memory. This does mean that before it can be used, the register must fist be initialized with a single green pulse, which can be done by disconnecting one of the combinators labeled 4 and performing a dummy write.

Here's the breakdown of what each component does:
1) If the address signal ("A" == 5) and write ("1" == 1) are both enabled, outputs "Blue" == 2

2) If "Blue" == 2, outputs "Red" == 1. This gets added to the constant combinator for a total signal of "Red" == 0 and "Green" == 1.

3) While "Red" == 0, initiates a counter that counts up until "Red" =/= 0, at which point it resets. This is what allows the pulsed signals in the next step

4) When "green" from the counter hits 1 and 2, pulses green signals into the next cell.

5) Passes the input signal from the red wire to the memory component when the green pulses occur.

6) This is the memory component. First green pulse causes it to store all input values into memory. The next green pulse erases memory. Once initialized, this happens in reverse, so when a write occurs, it first erases the old memory, then writes the new values.

8) When the address ("A" == 5) and read ("0" == 1) are both enabled, passes "Blue" == 2 to combinator 7.

9) Filters out the "Blue" == 2 and "Green" == 1 signals from the read output.

7) When "Blue" == 0 (a read occurs), passes the value of combinator 6 onto the red wire.

PS. I will post an in-game picture later.

Perhaps, the same system can be done in more compact and simple way:
Image
This build remembers all values from first constant combinator if ("0" signal = 1).
And these values can be taken from output in any time.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

@XKnight: Does this actually work? I would think the top left combinator would end up as double your original input signal. If it does work could you explain it a bit please? Is it supposed to be ROM? I see that your "0" signal is up at 3.8k
Last edited by Lupoviridae on Fri Jul 24, 2015 7:11 pm, edited 1 time in total.
XKnight
Filter Inserter
Filter Inserter
Posts: 329
Joined: Thu May 28, 2015 10:40 pm
Contact:

Re: Combinator Contraptions

Post by XKnight »

This setup is only for storing values, without any address checking (you can add one address check in input and one in output:)).

"0 signal" is increasing while the system has "0 signal = 1" in input, and it also can be removed (but who cares?).
ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Combinator Contraptions

Post by ratchetfreak »

XKnight wrote:This setup is only for storing values, without any address checking (you can add one address check in input and one in output:)).

"0 signal" is increasing while the system has "0 signal = 1" in input, and it also can be removed (but who cares?).
I have one: https://forums.factorio.com/forum/vie ... 706#p92314

Image

green is the flags red is the data

in this design the result data on red will get fouled with the input on the green line so if you have separate read/write flag signal you'll need to filter out the just address of the green line into the decider.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

Here's what my PVR looks like in game. Tested it and it works as advertised. It can be compressed down to a tilable 4x6 footprint.
Register.PNG
Register.PNG (419.74 KiB) Viewed 19636 times

@Xknight, I have to give it to you, your register does work, and I never would have thought of it. It flickers a ton during the write, but once the "0"==1 dignal drops out, it steadies out and outputs the right value.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

@Xknight: Been think about it, and it turns out if a pair down my design to just the parts labeled 3, 4, and 6, it performs the same function your design does with the same amount of combinators.
Edit: Actually it would take an additional constant and decider com. But it would generate a steady output with no runaway signals
XKnight
Filter Inserter
Filter Inserter
Posts: 329
Joined: Thu May 28, 2015 10:40 pm
Contact:

Re: Combinator Contraptions

Post by XKnight »

Today I rewatched my previous memory cell, and I found that it is also complex and not optimal.
This is improved version of memory cell:
Image
Behaviour is same as above (just simple memory cell), when ["0" signal = 1] it performs write operation.
It is hard to explain why it works in written form, so it is better to see once than hear a hundered times.

Update:
if ["0" signal = 1] it remembers input value
if ["0" signal > 1] it clears the stored value
So, you can use it only with ["0" signal = 0 or 1] as a memory cell.
User avatar
Tallinu
Fast Inserter
Fast Inserter
Posts: 143
Joined: Sun Jun 14, 2015 8:14 am
Contact:

Re: Combinator Contraptions

Post by Tallinu »

Somewhere on the list of "Obvious Combinator Applications", one can surely find "Smart Furnace Control Circuit". And this is one where combinators can definitely do a better job of it. So today I finally took a crack at it.

I've always been unsatisfied with smart furnace designs. The control circuit idea seemed to add nothing that you couldn't do simply by directly using logistics net storage values on the smart inserters instead of number of pickaxes, science packs, or other token items. With or without a control circuit, all the designs I've seen had particular limitations: If you need a ton of both iron and copper smelted, the division of labor breaks down and it tries to load both ores into all furnaces. And if you want to expand the smart furnace, you have to either extend existing rows (not necessarily ideal) or you have to re-assign the threshold values to half of the inserters on all the existing rows, no matter which end you expand from.

(The row that runs when you need any amount of iron only runs when you need a large amount of copper, and vice versa. When adding another 10 rows to a 10 row furnace, you can leave iron ore running when less than 1 to 10 iron picks or 1000 to 10,000 iron plates are in the system, and add rows that run when less than 11 to 20 picks or 11,000 to 20,000 iron plates are in the system, and having the last added row run when 1 science pack or 1000 copper plates are in the system, counting upward back in the other direction, but then you have to renumber the first ten rows for 11 to 20 science packs or 11k to 20k copper plates.)

Combinators can solve both of these problems.

While the fact that you have to wire up the storage chests does mean that you can't read the entire logistics network, not relying on the logistics system for your counting does have benefits as well as drawbacks. And it's not too hard to wire up the output passive providers while you're wiring up the inserters anyway. It's even easier to wire up an array of storage chests if you prefer active providers.

The biggest benefit is that you aren't forced to use logistics bots. I'm currently working on a belt-fed smart furnace layout which I plan to post screenshots of once complete. The input and output will both be via train, and the idea is that whatever amount a train takes away out of the loading buffer chests will get quickly replaced, regardless of which type of plate was shipped out (as long as sufficient ore is present on the input buffer and ore belts).

Another benefit is that you can set up a wired smart furnace like this long before you finish all the research for logistics bots, much less build a logistics network with enough roboports, bots, and power to handle the input and output requirements of any smart furnace large enough to be useful.

But we're here for the combinators, and that's the part that I've just completed work on!

Image
Imgur Album


The images and their descriptions in the album have the details of wiring and configuration, but to understand what's going on I'd recommend reading the explanation below.

The desired logic for optimal smart furnace control uses the following math, in simplest form:
IronNeeded = IronStored - IronDesired
CopperNeeded = CopperStored - CopperDesired
Divisor = IronNeeded + CopperNeeded
IronRows = FurnaceRows * IronNeeded / Divisor
CopperRows = FurnaceRows * CopperNeeded / Divisor

FurnaceRows, IronDesired, and CopperDesired will be set as constants. IronStored and CopperStored will be read from storage. The rest will be calculated. Ideally, we should avoid a divide by zero condition when no iron or copper needs to be smelted. And we also want our output signals to be readable in such a way that we can simply number our furnace rows from 1 to N and set both the copper and iron input conditions to match the row number. With combinators, that's a simple one-step calculation after everything else is done!

Additionally, because doing division with combinators always rounds down, we need to add in another step to finesse the numbers so it will effectively round to the nearest integer instead. This can often done by adding 0.5 before rounding, but combinators can't handle fractions. We can work around this by adding half of the divisor to the numerator before performing the division, which has the same effect. Taking all that into account, the first three lines remain the same, and the rest becomes:

If Divisor < 1, Add 1
RoundingFactor = Divisor / 2
IronRows = (RoundingFactor + FurnaceRows * IronNeeded) / Divisor
CopperRows = (RoundingFactor + FurnaceRows * CopperNeeded) / Divisor

IronControl = IronRows + 1
CopperControl = FurnaceRows - CopperRows

I'll transmit the IronControl value on Signal A, and CopperControl on Signal B. (You could use different signal choices, but I'd recommend not using an item type for these, especially not iron and copper, because any quantity of that item somehow making its way into the wired-up storage area would interfere.)

The final math step done for each of these control signals allows for very easy smart inserter configuration, both when initially building and when expanding the smart furnace, and no reconfiguration of old rows will ever be required. The first row is set to load iron when A > 1, and copper when B < 1. Row 2 loads iron when A > 2, and copper when B < 2. Row 3: A > 3, B < 3. And so on.

Additionally, thanks to all that math, there should (theoretically) never be a situation in which both inserters are allowed to load different ores simultaneously into the same row - but even if there is, it will only affect a single row and only for extremely precise ratios of copper to iron in storage, so the situation would be very fleeting.
Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: Combinator Contraptions

Post by Peter34 »

Lupoviridae wrote:
Peter34 wrote:
ratchetfreak wrote:or the amount of ore going through a belt.
I'd love to see a Sensor to measure Belt throughput, but I don't know that the devs have any such plans.
This can be done with some smart chests, though its a little bulky. You can measure how many pass through the chests in a certain amount of time.
The problem with that is that it involves Inserters, and Inserters will slow the throughput down, relative to if the stuff is just moving along a Belt and getting counted by a Sensor on or next to the Belt. I want something I can put on my Iron Ore/Iron Plate Belts, and those are - I hope this is obvious - high-throughout Belts.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

Peter34 wrote:
Lupoviridae wrote:
Peter34 wrote:
ratchetfreak wrote:or the amount of ore going through a belt.
I'd love to see a Sensor to measure Belt throughput, but I don't know that the devs have any such plans.
This can be done with some smart chests, though its a little bulky. You can measure how many pass through the chests in a certain amount of time.
The problem with that is that it involves Inserters, and Inserters will slow the throughput down, relative to if the stuff is just moving along a Belt and getting counted by a Sensor on or next to the Belt. I want something I can put on my Iron Ore/Iron Plate Belts, and those are - I hope this is obvious - high-throughout Belts.
The one possibility is to measure throughput at the spot where stuff comes out of the furnace, which would double as a buffer.
User avatar
vampiricdust
Filter Inserter
Filter Inserter
Posts: 317
Joined: Wed Jan 14, 2015 1:31 am
Contact:

Re: Combinator Contraptions

Post by vampiricdust »

I wish I could play a multiplayer with you guys... shit I got a lot to go over.

Anyways, Lupoviridae's miner is awesome & easy to use, but since you have to change the two equal combinators every time you place on an ore different than your blueprint, I decided to add in a fourth combinator that makes universal and can easily handle mixed yields. While I've had to break the neat looker's symmetry, for one extra combinator it is a blueprint & forget combinator setup. I've made a new one where I have the deciders along one side & a medium pole in the space that was opened by pulling the center decider to the side.

Image
The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Combinator Contraptions

Post by The Lone Wolfling »

I've been trying to build a stable / fast detector for when a chest is getting filled up with items with a fast inserter - any ideas? I can get a pulse every time the inserter inserts something by comparing the number of items in the chest with the same signal delayed by a dummy comparator, but I can't figure out how to get it to output a stable signal in a reasonable manner - is there an adjustable retriggerable monostable that works with one-tick input pulses? (In other words, a circuit that will output only when a certain configurable amount of time has passed since the last time the input was triggered.)

I've come up with something that sort of works, but is clunky, to put it mildly. Take an arithmetic comparator and feed its output back to itself, setting it to subtract 1. So it counts down really quickly. Have each of the input pulses set it to zero (by taking the counter's output, negating it, and feeding that back to the system multiplied by the pulse). Then the output is "is the negated output < 29" (or alternatively, "is the output > -29", but that's clunkier). Additionally, you want a decider combinator to check if the negated input is >28, and if so, feed +1 back to the counter, to stop it from counting all the time. This is 6 combinators, and does a whole lot of unnecessary work. It's also a couple ticks slower than it needs to be.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

The Lone Wolfling wrote:I've been trying to build a stable / fast detector for when a chest is getting filled up with items with a fast inserter - any ideas? I can get a pulse every time the inserter inserts something by comparing the number of items in the chest with the same signal delayed by a dummy comparator, but I can't figure out how to get it to output a stable signal in a reasonable manner - is there an adjustable retriggerable monostable that works with one-tick input pulses? (In other words, a circuit that will output only when a certain configurable amount of time has passed since the last time the input was triggered.)

I've come up with something that sort of works, but is clunky, to put it mildly. Take an arithmetic comparator and feed its output back to itself, setting it to subtract 1. So it counts down really quickly. Have each of the input pulses set it to zero (by taking the counter's output, negating it, and feeding that back to the system multiplied by the pulse). Then the output is "is the negated output < 29" (or alternatively, "is the output > -29", but that's clunkier). Additionally, you want a decider combinator to check if the negated input is >28, and if so, feed +1 back to the counter, to stop it from counting all the time. This is 6 combinators, and does a whole lot of unnecessary work. It's also a couple ticks slower than it needs to be.
Could you rephrase what you are aiming to accomplish? You want it to output a pulse when an item is added to the chest, but only if x amount of time has passed since the last addition? Or do you want it so every x seconds, it checks if the chest contents have increased or decreased?
The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Combinator Contraptions

Post by The Lone Wolfling »

I want a line that is "on" (for some definition of on") for the entire time items are being added to a chest, and off otherwise.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

The Lone Wolfling wrote:I want a line that is "on" (for some definition of on") for the entire time items are being added to a chest, and off otherwise.
Check the smart mining drill setup (also in this thread). It currently only produces a signal if x amount of time (configurable) has passed since an item was added to the chest. The setup can be easily inverted to produce a signal only if an item has been added recently. It works by introducing a unidirectional clock element. The count is reset to 0 each time an item is added. If the count ever goes over x, a signal is produced (or in your case, shut off). The leading edge of the signal shows instantaneous response to something placed in the chest, through the falling edge will have a slight time delay.

Are you expecting the chest to be filled rather irregularly in short bursts? Such as items delivered by train or some such?
The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Combinator Contraptions

Post by The Lone Wolfling »

I saw the smart mining drill, but it doesn't do what you think it does:
Lupoviridae wrote: Together, this setup outputs a green signal when the box has remained empty for more than 5 seconds (aka both drills are dry).
I want an output indicating when the number of items is increasing.

And yes, this is part of a smart train station.

(Actually, ideally what I want is a signal that changes as soon as possible after either the chest is full or the number of items isn't increasing, while remaining steady while items are being added by a fast inserter. The other edge isn't as critical.)
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

The Lone Wolfling wrote:I saw the smart mining drill, but it doesn't do what you think it does:

I want an output indicating when the number of items is increasing.

And yes, this is part of a smart train station.

(Actually, ideally what I want is a signal that changes as soon as possible after either the chest is full or the number of items isn't increasing, while remaining steady while items are being added by a fast inserter. The other edge isn't as critical.)
As it is formulated for the drills, no it doesn't do what you are looking for, but it can with a few additional elements.

If I can figure out exactly what you are trying to do I can provide the template. Basically you want signal A to be output while the train is being unloaded, and a quick switch to signal B when the train is empty (or leaves) or the chest is full; is this correct?

Edit: If this is right, check out this thread about belt counters.
https://forums.factorio.com/forum/vie ... =8&t=15014
Basically what I would suggest is set up a counter (which produces a pulse of signal each time a NEW item is added to the associated chest) for items coming directly out of the train. Have this chest feed into your storage chest instead of onto a belt. Instead of using the pulsed signal to count the items, make a unidirectional counter (similar to the smart mining drill setup) that resets each time it receives that pulsed signal. Basically, if you look at u/DOSorDIE's post showing the combinator layout on the first page, the only thing that needs to be changed is the top left combinators.

1) Change the decider from [If Blue == 0, output everything (input count)] to [If green == 0, output everything (input count)].
2) Change the constant combinator just right of this decider to output a constant Blue == 1.
Now the decider will count up the blue signal ad infinitum, until it receives a pulse of green signal, which only occurs if a new item is placed in the counter chest.
3) Attach another decider's input to the output of this counter, with [If Blue > 60, output Yellow == 1]
Yellow signal should only be output if the chest is full or not currently being filled, with about a 1s delay behind real-time. I believe this is what you want. You can probably even drop the delay down a little bit (maybe to if blue > 40), since your pulsed signals should be coming every .5s (30 ticks) or so.

Furthermore, since the items will be drawn form a cargo wagon the inserter movements should be concerted, meaning you should only need one "line" of the combinators shown in the counter setup, so long as you connect the counter chests together by red and green wire, and the secondary smart inserters together by green wire. This means a total of about 7 combinators for the whole setup. Sorry if this is confusing, let me know if you'd like me to build it in-game to show you what I mean.
The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Combinator Contraptions

Post by The Lone Wolfling »

That's basically what I have now, only slower and bulkier. I was hoping to streamline it and/or make it faster.

Yes, that's essentially what I want. An interesting twist, however, is that the "are chests being filled" part has to wait for signal A to be high (coming from a train detector) - and that's on the critical latency path. Otherwise the train will arrive and immediately leave before the detector has a chance to trigger.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

The Lone Wolfling wrote:That's basically what I have now, only slower and bulkier. I was hoping to streamline it and/or make it faster.

Yes, that's essentially what I want. An interesting twist, however, is that the "are chests being filled" part has to wait for signal A to be high (coming from a train detector) - and that's on the critical latency path. Otherwise the train will arrive and immediately leave before the detector has a chance to trigger.
What I outlined above can turn the signal on immediately on arrival of the train, and shut off 0.6s after the train leaves or the chest fills. You aren't going to get much faster. Fast inserters take about .5s to complete a turn, so you need to wait at least that long before the signal can shut off. If you really want you can probably cut out a few combinators by using XKnight'sflow counter design I think.
Last edited by Lupoviridae on Tue Oct 20, 2015 1:38 am, edited 1 time in total.
Lupoviridae
Fast Inserter
Fast Inserter
Posts: 155
Joined: Mon Apr 20, 2015 6:26 pm
Contact:

Re: Combinator Contraptions

Post by Lupoviridae »

Just tested this, and it works perfectly.
Capture.PNG
Capture.PNG (724.3 KiB) Viewed 20200 times
Managed to get the falling edge of the signal 0.5s after the last item was removed from the train. A full rotation of an inserter is actually 0.426 seconds i believe, so this is pretty literally as responsive as possible. Check out the save.
Keith5.zip
(4.26 MiB) Downloaded 409 times
Dump a bunch of items into the cargo wagon and watch the light turn on instantly. The moment the cargo wagon is empty, the light shuts off. The same also occurs if the iron chest fills up or the train leaves.

Have I met the challenge?
Post Reply

Return to “Combinator Creations”