Simple way to cap a circuit signal at a maximum value?
Posted: Sat Nov 09, 2024 3:52 pm
by Mad Inventor
There's probably a very simple answer, but it's driving me crazy. How do I set a signal value to a maximum if it is above the maximum, but otherwise leave it alone?
If I use a decider combinator with "less than or equal" it will output the value if it is equal to or below the maximum, but if the value is above the max, it will output nothing, not the maximum I want.
If I add a second, parallel combinator with "greater than", I can't have it output the maximum because a decider can only output the incoming value (which is above the maximum) or 1.
If I use a different signal (such as a gray color signal when I'm trying to cap the iron ore signal) with a constant combinator for the maximum, then a decider can be set to output the "input count" of that different signal if the one I'm trying to cap is higher. And then I will need to somehow swap it back to having that value on the original channel.
With all the improvements that were made to circuits/combinators in 2.0 (or even ones before that I missed) there's got to be a way to set a maximum value without using 3-5 different combinators.
Re: Simple way to cap a circuit signal at a maximum value?
Posted: Sat Nov 09, 2024 10:37 pm
by brittlecracker
Hi! I have thought a little about it and can't find a clever way to do it. A naive way is to use two deciders and an arithmethic combinator:
First decider reads input signal, if less than max, output that signal.
Second decider reads input signal, if greater or equal to max, output 1 of that signal. Output of that connects to input of arithmetic combinator, which multiplies the value by the max and outputs it.
Join the outputs of first decider and the arithmetic combinator and you will have the input value capped at max.
Would that work for you? If so, here's a parameterized blueprint for that. It also uses a single constant combinator (on the other circuit color) that sets the max, so it's easier to update after the blueprint is placed.
Re: Simple way to cap a circuit signal at a maximum value?
Posted: Sun Nov 10, 2024 9:50 am
by BaggyK
Use a constant combinator to feed in the maximum value, then have two deciders one for less than the maximum which outputs the original item count, the other for greater or equal to the maximum which outputs the maximum input.
Re: Simple way to cap a circuit signal at a maximum value?
Posted: Sun Nov 10, 2024 10:45 am
by mergele
That also needs a translation to a help signal and a delay to keep synchronous., bringing it up to 5 combinators.
This setup does it with 4
3.png (4.35 MiB) Viewed 1270 times
You can set the maximum per constant combinator feeding a virtual signal in, making setting it up and using it multiple times easier, but then you need a decoupler on the input to prevent side effects, so since I don't know your requirements I left that off.
Re: Simple way to cap a circuit signal at a maximum value?
Posted: Tue Nov 12, 2024 3:41 pm
by Nidan
The OP got very close to the solution. Instead of putting the maximum directly into the deciders, put it into a constant combinator connected to both deciders, using the other wire color.
Decider 1: Each red <= Each green, output Each red
Decider 2: Each red > Each green, output Each green
You can replace Each with the actual signal you're interested in if you don't want nor need the vectorized version.
Re: Simple way to cap a circuit signal at a maximum value?
Posted: Fri Nov 15, 2024 5:49 pm
by arl85
If I'm interessed in capping a single signal, I just found a simply method
immagine.png (71.13 KiB) Viewed 1110 times
constant combinator with "up arrow" as maximum value (in this case DOT signal is for demo purpose, the signal I want to cap)
immagine.png (337.72 KiB) Viewed 1110 times
connected to a selector combinator outputting first signal ordered ascending (so minimum value)
immagine.png (244.31 KiB) Viewed 1110 times
plus a convertor to go back to my signal
immagine.png (301 KiB) Viewed 1110 times
Please note that both my solution and the previous blueprint work only if the signal you want to cap is > 0; in case of signal = 0, in both cases max will be returned
edit: an improved version that works even when no input signal is provided.