Count-perfect flow limiter (needs review)

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.
Post Reply
grays42
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Apr 16, 2016 10:37 pm
Contact:

Count-perfect flow limiter (needs review)

Post by grays42 »

For testing some blueprints, I wanted a way to produce precise ratios of certain items, such as 2/3 of a belt of copper. I could use balancers, but I'd prefer to have a reusable method I can just plug a fraction into that doesn't require a knot of balancers every time. So, I spent a few hours building an arbitrary ratio flow limiter. I don't understand advanced circuits very well, so I'd really like for someone to look it over and let me know if I could improve it or remove some steps.

Examples of use:

1/2 yellow belt ratio

Image

For this example I have set the fraction of yellow belt to numerator=1, denominator=2, or a ratio of 1/2 yellow belt (so 1 full lane). As you can see, the input belt only activates to release enough items to fill exactly 1/2 fully compressed yellow belt.

3/2 yellow belt ratio

Image

As before, except 1.5 yellow belts instead of 1/2. It can accept any ratio, even less pretty ratios like 7/31, and will be count-perfect.

Design Principle:

The number average number of items on a fully compressed, unimpeded (free-flowing) belt is 7.1111 items/tile (or 64/9). This means that:
1. 9 tiles of contiguous compressed belt has exactly 64 items on it
2. If you count all the items on a compressed, unimpeded belt tile every tick, after 9 ticks, you'll have counted 64 items.

If you want to apply a fractional ratio N/D to a fully loaded belt:
1. Normally you'd expect 64 items every 9 ticks.
2. With the ratio, you'd expect to count 64 * N items every 9 * D ticks.
3. A flowing tile should have an average of (64 * N) / (9 * D) items per tick.
4. If you count more than this average, you need to stop the flow. If you’ve counted less than this average, you need to resume the flow.

[NOTE:] Major revision below, I now count pulses instead of entire belts. Measuring pulses, the ratio is (2 * N) / (9 * D), the rest of the mechanics work the same.

Implementation:

- Count (C) is an increasing sum of items measured per tick from the flow belt(s). Every tick, C increments by the number of items on all measured belts. (So, if you’re measuring one compressed unimpeded belt tile, C will increment by an average of 7.111 items/tick. Because we're measuring blue belts and our ratios are in terms of yellow belts, I'm measuring 3 blue belts. If my ratio was in terms of blue belts, I'd measure 1 blue belt.)

- User specifies numerator (N) and denominator (D) for the fraction to be applied to limit belt flow. N=1, D=2 represents 1/2 = 0.5.

- GREEN signal is a constant -64 * N, representing the expected number of items over a RED number of ticks. RED signal is a constant 9 * D, representing the number of ticks during which a GREEN number of items should be counted on the flow tile.

- Timer T increments 1 each second. After it reaches RED ticks, it resets to 1. Every time T = 1, pulse P=1 is sent out, so a pulse P occurs once every RED number of ticks.

- Every time pulse P occurs, a GREEN number of items is subtracted from count C. This means that for ratio 1/1, 64 items are subtracted every 9 ticks, for a perfect 7.111 average to offset a normal compressed belt.

- Flow reduction is achieved via a regulator belt tile. The regulator belt only turns ON if the number of items *expected* (subtracted) exceeds the number of items *counted* (added), meaning more items need to be added in. If too many items have been counted vs. the number expected, the belt turns OFF to limit the flow. As such, the limiter belt turns on if C < 0.

This will keep C in a constant state of fluctuation around 0. Because there is no decimal math, only items and tick counts, it will be count-perfect for whatever fraction you specify, forever.

Note for the above GIF: we're counting off of a blue belt. Since we’re expressing 1/2 in terms of a ratio of yellow belts, and blue belts have 3 times the throughput of yellow belts, we need to monitor 3 blue belts. If we want 1/2 of a blue belt, we only need to measure 1 flow blue belt. (I’m still fuzzy on the counterintuitive math on this one, I’ll figure it out later.)

Feedback:

This is by far the most complicated circuit I’ve ever made and I fumbled my way through it, so if some circuit experts could weigh in with suggestions on how to clean this thing up, I’d appreciate it.

Blueprints:

Fractional flow limiter

Handy belt compression checker, lights up if belt is compressed.
Last edited by grays42 on Fri May 12, 2017 12:41 am, edited 2 times in total.

Megatron
Inserter
Inserter
Posts: 47
Joined: Fri Apr 08, 2016 7:00 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by Megatron »

The yellow belt moves at one slot per tick. One item uses 9 slots of space on the belt. So the belt would be saturated if it receives one item every 9 ticks for each lane.

Image
Blueprint
Currently it saturates one lane of one yellow belt. By setting the black signal in the constant combinator to -2, it should saturate 2 lanes - a full yellow belt - and so on.

I'm not sure if my reasoning is absolutely correct but the constant buzzing of the combinators is driving me insane, so I gave up after it seemed to work.

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by sparr »

The smaller solution works if you want to send between 0 and 4.5 yellow belts in 0.5 belt increments.

It does not work if you want to send 1/3 of a yellow belt, or 3/7, or 11/64, etc.

OP: Good work, and I'd like to look over your design when I can. It's a neat idea.

grays42
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Apr 16, 2016 10:37 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by grays42 »

Modified the design: made it more compact and added a trigger at the beginning ("H") that only starts the rate limits when items are read into it.

I also made a discovery: for it to be count-perfect you *must* measure in multiples of the distance an item takes to cross a yellow belt. That is, if you're measuring red belts you must measure in multiples of 2, if you're measuring in blue belts you must measure in multiples of 3.
Blueprint

AndrewIRL
Fast Inserter
Fast Inserter
Posts: 240
Joined: Fri Mar 24, 2017 2:17 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by AndrewIRL »

Short version

You have a flow limiter, can you make a flow detector and hook the two together in order to limit the flow on belt A to match the flow on belt B?


So here's my problem

I have a smart furnace which smelts copper and iron both. But sometimes the consumption of one or the other isn't fast enough and the belts back up into the smelter - jamming it. Say copper gets backed up then the the iron can't be smelted and I end up with a backed up copper line and no iron at all. I "solved" this by detecting a belt backup scenario and cutting the supply [S] of ore. But this makes the copper get turned off and on essentially being PWM with really long cycles (takes time to get from ore to plate).

Code: Select all

Copper Ore [S1] ----  SMART  ---- [B2] Iron Plate
  Iron Ore [S2] ---- SMELTER ---- [B1] Copper Plate
So a backup is detected at B1 (using the splitter and circuit belt hold) and it turns off S1. Current working but poor design.

But what I would really prefer is that if B1 detects a backup then rate limit S1 instead of turning off. But not rate limit to an arbitrary half-belt etc limit - rate limit it to the rate that copper plate is being consumed. Say my copper plate belt is 10/s then I want the copper ore belt to be speed matched to deliver 10/s. Also if there's no belt backup then S1 should freeflow.

Is this doable or will it be a crazy number of combinators?


In addition to smart smelting, a flow matching contraption could also be used to limit the amount of excess on long belts which aren't fully consumed. Say for turrets:

Ammo Assembler -- [S] ------very---long---belt---out---to---wall---- -- Turret

I don't want a huge belt filled with ammo going all the way out to the wall. Once the belt gets backed up to the assembler can run production only when ammo is consumed.

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by sparr »

It would actually be much easier than OP's circuit if you just want to rate limit one belt to match the amount flowing on another belt. 4 combinators? Maybe fewer.

grays42
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Apr 16, 2016 10:37 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by grays42 »

Image

Sure, I went ahead and put one together for you. It only needs to compare lane population, it doesn't care about multiplication or timing.

An object will be counted 32 times as it crosses a yellow belt, and 16 times as it crosses a red belt. However, the regulated belt will be measured exactly the same way. So, all that's needed is a raw count. If more are counted on the reader than the regulated belt, open the regulator, otherwise leave it closed.

NOTE: This will correctly regulate yellow and red belts, but will NOT correctly regulate blue belts unless you measure belts in multiples of 3, because 32 is not divisible by 3.
Blueprint
[edit:] Actually...I feel silly for not thinking of this, but that actually works better in pulse mode rather than in hold mode. I edited the blueprint to reflect that. In fact, my original might too.
Last edited by grays42 on Thu May 11, 2017 11:47 pm, edited 1 time in total.

grays42
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Apr 16, 2016 10:37 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by grays42 »

By the way, I also just updated my belt capacity monitor to be able to measure any arbitrary quantity. It has a sensitivity of 1 unit. Remember, a fully loaded belt has 64 items on it, so I have the measurement set here to 36, and it is reporting to me that there are exactly 32 items (half of a belt) on at all times, verifying that the blueprint I just posted functions correctly.

Image
Blueprint

grays42
Burner Inserter
Burner Inserter
Posts: 14
Joined: Sat Apr 16, 2016 10:37 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by grays42 »

MAJOR REVISION:

Yes, pulse mode works MUCH better, keeps flow more consistent, and works with any belt type! New math:

- Yellow belts have a throughput of 40/3 (13.333) items/sec, or 40/(3*60) = 2/9 items/tick.
- Using the same method as previous, we can expect a fully compressed YELLOW belt to generate (2*N) pulses per (9*D) ticks.

Here is the new version with several examples:

Image
Image
Image
Image
Image
Blueprint

AndrewIRL
Fast Inserter
Fast Inserter
Posts: 240
Joined: Fri Mar 24, 2017 2:17 pm
Contact:

Re: Count-perfect flow limiter (needs review)

Post by AndrewIRL »

grays42 wrote:Image

Sure, I went ahead and put one together for you. It only needs to compare lane population, it doesn't care about multiplication or timing.
Blueprint
Nice! Thanks for this. When I get home from work I'll try it in my smelter.

Post Reply

Return to “Combinator Creations”