SR-latch

This is the place to request new mods or give ideas about what could be done.
Post Reply
Dragonling
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Sep 12, 2019 2:00 pm
Contact:

SR-latch

Post by Dragonling » Fri Sep 13, 2019 6:03 am

I have searched over the requests, and haven't found this one.

A Set-Reset Latch is a circuit network item, that starts emitting a signal when a "set" event (logical condition) occurs, and stops emitting the signal only when a "reset" event occurs. One of the obvious applications is using this contraption to turn on steam generator reserve when accumulators' energy level is 1% or less, and turn them off, when accumulators charge up to, say, 20% (this allows to avoid flickering). But it has much more uses than just that example.

It is common knowledge, that a Set-Reset Latch can be implemented with 3 combinators, as per the Cookbook. However, not every player is skilled enough to understand, how it works and is built (my personal case: coop with family). Also, not every player can understand English enough to read the Cookbook.

Would someone, please, implement SR-latch as a simple to use single item?

User avatar
brunzenstein
Filter Inserter
Filter Inserter
Posts: 899
Joined: Tue Mar 01, 2016 2:27 pm
Contact:

Re: SR-latch

Post by brunzenstein » Fri Sep 13, 2019 7:05 am

https://youtu.be/vEOXGBYR6oM
Its in plain English and easy to understand, follow and use therefore easily


User avatar
planetmaker
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Mon Jan 21, 2019 9:30 am
Contact:

Re: SR-latch

Post by planetmaker » Fri Sep 13, 2019 8:10 am

My suggestion: create a blueprint for the SR latch and share it with those people (e.g. your family).

Of course, switching on backup power, is the most obvious use, it is not common enough to warrant a special item for that in the vanilla game IMHO (maybe one can make a mod to create such item - then you could use that mod).

Dragonling
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Sep 12, 2019 2:00 pm
Contact:

Re: SR-latch

Post by Dragonling » Fri Sep 13, 2019 8:37 am

planetmaker wrote:
Fri Sep 13, 2019 8:10 am
(maybe one can make a mod to create such item - then you could use that mod).
Well, yes, let's hope for that. After all, I am posting this request in the forum branch called "Ideas and requests for mods".
I am thankful for everyone trying to help me by suggesting workarounds, but I am looking for anyone with goodwill to make the quality of life mod, which will not require additional actions or special knowledge.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2283
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: SR-latch

Post by Optera » Fri Sep 13, 2019 8:59 am

planetmaker wrote:
Fri Sep 13, 2019 8:10 am
My suggestion: create a blueprint for the SR latch and share it with those people (e.g. your family).

Of course, switching on backup power, is the most obvious use, it is not common enough to warrant a special item for that in the vanilla game IMHO (maybe one can make a mod to create such item - then you could use that mod).
Not common had me chuckle.
Every single of my production lines is behind an sr-latch, with delayed off timer to clean belts before turning off power.
Then again I'm probably the minority enjoy fine tuning automation with combinators.

Having a dedicated latch combinator instead of two could reduce my combinator count a fair bit.

User avatar
planetmaker
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Mon Jan 21, 2019 9:30 am
Contact:

Re: SR-latch

Post by planetmaker » Fri Sep 13, 2019 10:19 am

Optera wrote:
Fri Sep 13, 2019 8:59 am
planetmaker wrote:
Fri Sep 13, 2019 8:10 am
My suggestion: create a blueprint for the SR latch and share it with those people (e.g. your family).

Of course, switching on backup power, is the most obvious use, it is not common enough to warrant a special item for that in the vanilla game IMHO (maybe one can make a mod to create such item - then you could use that mod).
Not common had me chuckle.
Every single of my production lines is behind an sr-latch, with delayed off timer to clean belts before turning off power.
Then again I'm probably the minority enjoy fine tuning automation with combinators.

Having a dedicated latch combinator instead of two could reduce my combinator count a fair bit.
On the chance to have this going a bit off-topic: Agreed, yes. Arguably there are playstyles and setups where they are common (and I find them quite a commodity use them for power and situations like you describe myself). Yet... I doubt that qualifies as 'majority of players use it and need it'.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2315
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: SR-latch

Post by darkfrei » Fri Sep 13, 2019 10:34 am

Dragonling wrote:
Fri Sep 13, 2019 8:37 am
Well, yes, let's hope for that. After all, I am posting this request in the forum branch called "Ideas and requests for mods".
I am thankful for everyone trying to help me by suggesting workarounds, but I am looking for anyone with goodwill to make the quality of life mod, which will not require additional actions or special knowledge.
This entity must be at least 2x2, maybe 3x3 tiles, one edge as R, the second as S, another two edges are output values with Q and not(Q).
If any on S, then Q is same as S, nothing on not(Q) and holding this value;
when any on R then nothing on Q, but not(Q) has the value of R;
if nothing on S and R then hold the value;
if both S AND R then Q and not(Q) are nothing.

It can be done with two lamps as input, two constant combinators as output and control.lua calculations on each tick;
or as hidden arithmetic and decider combinators without control.lua on tick, just on entity placing.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2283
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: SR-latch

Post by Optera » Fri Sep 13, 2019 2:09 pm

Performance of any lua scripted combinator will be magnitudes worse than dedicated circuit logic.
Especially if all an sr latch requires is 2-3 combinators. Personally I prefer the 3 combinator variant with one decider set to if R == 0 then everything = 1 and dedicated combinators to trigger set and reset signals as those are easier to set up for multiple set and reset conditions and also easier to check remotely.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 10644
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: SR-latch

Post by ssilk » Tue Sep 24, 2019 9:54 am

Reading this through I thought of this:
A mod that packs a number of (hidden) combinators into one entity with a nice user interface.

For example the SR-Latch:
The entity you can place has three inputs: low, high and value and an output. Or instead a second variant: One value-input, and an output and a user-interface to filter the input (optional) and set low/high and the output item.
Internally - when you place that item - it places some combinators and cables them together - totally invisible. It places three combinators: one with the input and the low value to fire the R-signal, one with the input and the high value to fire S signal and one with the memory cell and input form first and second combinator. What you see is just somthing like a combinator with three inputs and one output. If you hover over the item it can explain you how it is intended to work.

Or a timer: One input with optional filter for pulse or hold, an output for current counts of items or on/off.
And again, internally the mod places 5 or 6 combinators, cables all together and sets the right values into the combinators.

Think about the possibilities: instead of creating "universal" combinator-layouts (e.g. you need to set the filtered item only once with a combinator), you can specialize the design of the circuit, because when you place it, it fills out the needed placeholders (items, numbers, sub-circuits) for you.

The advantage would be, that this uses the (fast) internal circuit logic, but enables to create really complex things. Think for example to a state machine for the recursive blueprint mod, that is able to scan revealed underground for resources and build complete outpost out of nothing.

Ahmmm... what's missing then? An editor to create circuits.
Like this: https://resources.jointjs.com/demos/logic

BTW: I looked a bit deeper into that link: fascinating how simple it should be to create a factorio circuit editor. Or if I had a wish: That would be one of those things, that could add veeeerry much game to factorio: An editor, where you can create logic circuits (as described above), and where you can test it (random input, power loss etc.) and then put them together into one circuit as a new circuit-element. It would be a bit like blueprints for circuits.

Hmmmmm. :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2315
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: SR-latch

Post by darkfrei » Tue Sep 24, 2019 10:32 am

It's something like hysteresis combinator, that works like
If input_signal is more than maximum_value than switch the output and it will be switched back only when the input_signal will be lower than minimum_value.

Internal:
One constant combinator with two virtual signals: minimum_value, maximum_value;
one lamp(?) entity as input signal placeholder. Another lamp as output signal placeholder.

DRE
Inserter
Inserter
Posts: 41
Joined: Sun Jan 25, 2015 2:30 pm
Contact:

Re: SR-latch

Post by DRE » Sun Oct 20, 2019 9:45 pm

Hi guys.

I am currently working on such mod. It is in a very rare state yet, I only wrote basic APIs and a little very crude proof of concept.

It should be very UPS friendly, just like vanilla combinators _except_ maybe during building as it involves some relatively heavy computations.

There will be API so community can create own combined combinators using Composite Combinators Core mod as a dependency.

API call to Core mode will, roughly, looks like this:

Code: Select all

function RegisterEntities()
	remote.call(
		"Composite-Combinators-Core", "registerCompositeCombinatorPrototype", "euc-distinct-constant-combinator", 2, { x = 0, y = 0 }, 
		"item-with-tags$composite-combinator-io-marker$item$constant-combinator$)1$2$4$0$in@1(3$4$44$131330$1[item@red-wire@1[item@construction-robot@2[(3$4$46$131074$1[item@green-wire@1[item@construction-robot@1[()01$131073$65537(00$196609$65537(01$65538$65537(00$65539$65537(",
		false
	)
	
end
There is a tool that generates string for components layout inside of a composite combinator.

Attachment shows the mod in its current state. Distinct Composite Constant Combinator has two connections to two very tiny constant combinators, allowing to transmit different signals on different wires, as the first and simplest Composite Combinator.
CompositeCombinatorsCore_Base.png
CompositeCombinatorsCore_Base.png (486.03 KiB) Viewed 291 times
CompositeCombinatorsCore_Base2.png
CompositeCombinatorsCore_Base2.png (650.72 KiB) Viewed 291 times
To add own component that can be placed inside of combined combinators, code is a bit more complicated
Constant combinator as a component

Code: Select all

	-- entity -> string 
	constantCombinatorSerialize = function(entity)
		if entity == nil then
            return nil
        end
		
		local beh = entity.get_control_behavior()
		
		local str = ((beh.enabled and 1) or 0)..(baseConst.strBoundary2)
		
		for _,signals in pairs(beh.parameters) do
			for _,signal in pairs(signals) do
				if signal.signal.name then
					str = str..(signal.signal.type)..(baseConst.strBoundary1)..(signal.signal.name)..(baseConst.strBoundary1)..(signal.count)..(baseConst.strBoundary2)
				end
			end
        end
		
		return str
	end,
	
	-- string -> slots 
	constantCombinatorConvert = function(str, slots, nextSlot)
		if slots == nil then
            return nil
        end
		
		local count = 0
		
		local spl = split3(str, baseConst.strBoundary2)
		local enabled = tonumber(spl[1])
		
		spl[1] = nil
		
		for _,node in pairs(spl) do 
			count = count + 1
		end
		
		local signalType
		local signalName
		local signalCount
		
		count = bit32.lshift(count, 16) + enabled
		
		slots[nextSlot] = { signal = baseConst.specialSignal, count = count, index = nextSlot }
		nextSlot = nextSlot + 1
		
		for _,node in pairs(spl) do 
			if node ~= nil then
				local subnodes = split3(node, baseConst.strBoundary1)
				signalType = subnodes[1]
				if not signalType then break end
				signalName = subnodes[2]
				if signalType == '' then
					enabled = subnodes[2]
					break
				end
				signalCount = subnodes[3]
				slots[nextSlot] = { signal = { type = signalType, name = signalName }, count = signalCount, index = nextSlot }
				nextSlot = nextSlot + 1
				-- game.players[1].print("viSig: "..signalName..' T '..signalType..' C '..count..' I '..nextSlot)
			end
		end
		
		return nextSlot
	end,

	-- slots -> spawn
    constantCombinatorOnSpawn = function(entity, slots, nextSlot, slotsToRead)
        if entity == nil then
            return nil
        end
		
        local beh = entity.get_control_behavior()
		
		if slots[nextSlot].signal.name ~= baseConst.specialSignal.name then
			error('Corrupted data')
		end
		
		local enabled = tonumber(bit32.band(slots[nextSlot].count, 0xFFFF))
		local count = tonumber(bit32.band(bit32.rshift(slots[nextSlot].count, 16), 0xFFFF))
		-- game.players[1].print("ENA~"..enabled)
		beh.enabled = enabled == 1 and true or false
        nextSlot = nextSlot + 1
		
		local i = 1
	
		local params = { }
        while i<count do 
			if slots[nextSlot].signal.name == baseConst.specialSignal.name then
				break
			end
			local ins = { count = tonumber(slots[nextSlot].count), index = i, signal = slots[nextSlot].signal }
            table.insert(params, ins)
            nextSlot = nextSlot + 1
			i = i + 1
        end
		beh.parameters = {parameters = params} 
		
		-- game.players[1].print("SIGSS: "..inspect(beh.parameters)..' to '..entity.name)
		return nextSlot
    end
    
    ...
    
        remote.call("Composite-Combinators-Core", "registerComponentPrototype", "constant-combinator", "composite-combinator-constant-component", 17, 
        { 
            defines.circuit_connector_id.constant_combinator 
        }, 
        {
            interface = "Composite-Combinators-Base",
            method = "constantCombinatorSerialize"
        },
        {
            interface = "Composite-Combinators-Base",
            method = "constantCombinatorConvert"
        },
        {
            interface = "Composite-Combinators-Base",
            method = "constantCombinatorSpawn"
        }
    )
I also plan to create APIs for editing layout and settings of existing placed composite combinators, to react on custom composite combinator GUI interaction for example.
Last edited by DRE on Sun Oct 20, 2019 10:03 pm, edited 2 times in total.

DRE
Inserter
Inserter
Posts: 41
Joined: Sun Jan 25, 2015 2:30 pm
Contact:

Re: SR-latch

Post by DRE » Sun Oct 20, 2019 9:53 pm

S-R latch would be very easy to add there, that what I meant. :D

Cribbit
Fast Inserter
Fast Inserter
Posts: 193
Joined: Mon Oct 09, 2017 9:35 pm
Contact:

Re: SR-latch

Post by Cribbit » Mon Oct 21, 2019 6:12 pm

I feel like I'm dumb. Can't you do this with a single combinator? Wire output back to input. That's how I've always done it.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2283
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: SR-latch

Post by Optera » Tue Oct 22, 2019 1:37 pm

Cribbit wrote:
Mon Oct 21, 2019 6:12 pm
I feel like I'm dumb. Can't you do this with a single combinator? Wire output back to input. That's how I've always done it.
The latch itself needs only one combinator, but you need at least another one providing the reset condition for it.

User avatar
thereaverofdarkness
Filter Inserter
Filter Inserter
Posts: 532
Joined: Wed Jun 01, 2016 5:07 am
Contact:

Re: SR-latch

Post by thereaverofdarkness » Mon Oct 28, 2019 7:52 pm

Perhaps there is something I'm not understanding, but is this not a SR-latch?

Image

https://wiki.factorio.com/Power_switch

Cribbit
Fast Inserter
Fast Inserter
Posts: 193
Joined: Mon Oct 09, 2017 9:35 pm
Contact:

Re: SR-latch

Post by Cribbit » Mon Oct 28, 2019 8:32 pm

thereaverofdarkness wrote:
Mon Oct 28, 2019 7:52 pm
Perhaps there is something I'm not understanding, but is this not a SR-latch?

https://wiki.factorio.com/Power_switch
An SR latch is a mechanism that toggles when an input crosses a threshold, and does not toggle back until crossing a separate threshold.

The common example in Factorio is steam storage for nuclear power. You want to insert fuel when the tanks go below 10k steam, but if you simply have the inserters turn on at 10k steam the delay in steam production from that fuel means many cells will be inserted before steam goes above 10k again and the inserters turn off. Instead, an SR latch means you can pulse once when steam crosses below 10k, and then do nothing until steam rises above 15k. Only after the steam rises again is the latch reset, so that the next time it drops the cycle repeats.

Post Reply

Return to “Ideas and Requests For Mods”

Who is online

Users browsing this forum: No registered users