Schematics (Unloader) - rain9441/factorio-tls GitHub Wiki

https://github.com/rain9441/factorio-tls/blob/master/screenshots/10-unloader-schematics.png Link to Image

The unloader logic works on the basic idea of determining unique resources that exist on the train, and whose quantity stored in the logistic network are less than the quantity desired by the configuration of the station itself. It's fairly easy to break that down into different parts.

To read the contents of the logistic network, we use two roboports. One roboport (P19) is configured to read logistic network contents into G5, the other (P20), reads robot statistics (But only total construction and logistics bots, as their respective signal) into R4. We also connect R4 to the two stack inserters that fill the roboports (I17 and I18) which are configured to Read hand contents with mode Hold. Additionally, R4 is connected to the two steel chests (B15 and B16) that hold any additional bots that are in queue to be inserted into the roboport. This gives us the number of bots in the roboports plus the number held by the inserters plus the number in the temporary steel chest storage which is a pin point accurate number of bots we will have available.

The G5 wire which contains the contents of the logistic storage is fed into a decider combinator (D7) that filters out any negative values and outputs that into G3. This eliminates errors that can occur when bots are retrieving many resources from chests and the logistic network reports negative numbers (this happens very frequently). Without this filter, those negative values would be considered additional requests by the unloader, which is bad. The D7 filter also includes a bot filter (C9 into R5) that ensures that construction bots and logistics bots that are in logistic storage don't count towards are total number of bots. This is important because those bots are not actually in the roboport system, nor queued to be inserted into it, so they are essentially useless. Note that there shouldn't be any bots in the logistic storage - if there is, it is due to unforseen circumstances or the player trashed them from his/her inventory. Those bots will be recycled by the trash system.

We combine G3 and R4 in the A6 arithmetic combinator which multiples the value by -1. This is a simple substraction support combinator which sets us up to subtract out the total number of items in our current system. The output of this is R1. R1 now contains the negative value of the total number of bots and items in logistics storage.

The R2 wire contains all of the items requested by the TLS Unloader (C10, configurable). This is a summation of all train stops' requests and lives on the Alpha Network (The Alpha Network is the set of wires that are connected via the northern substations). This value is pushed through D2 which is a decider combinator which does nothing other than to transfer the values of the signal from a red wire (R2) to a green wire (G1). This is required due to the complex connections of wires that cannot connect to each other. The items requested by the TLS Unloader (G1) is combined with R1, giving us the number of items we want minus the number of items in our system. That is processed by D1, which normalizes any positive signals into R3 with an output count of exactly 1.

We now have a value of 1 on R3 for every item we would take more of.

The other side of this logic is to determine what is on the train stop (T11). This value is put into G2, which is also on the Alpha Network. G2 is run through a decider combinator (D4) which outputs any positive signals into R3 with an output count of exactly 1.

We now have a value of 1 on R3 for every item that exists on the train.

R3 is then fed into decider combinator (D5) which outputs only signals with a value of 2. The signals outputted are (with one exception listed below) going to be all items of which we would take more of and are also on the train. This is output into G4. The G4 signal connects to decider combinator D3, which determines if the train should depart. D3 will output D=1 if and only if all input are zero, which means there are no items on the train that we would take more of. The D=1 signal is put on G2, which gets sent to the train to suggest departure. The G4 signal also connects to all of the filter stack inserters (F12, there are 8 of them in total, as well as F13 and F14 which unload logistics bots and construction bots) to indicate which resources those stack inserters should take from the train. The bot filter (C9 into R5), which contains -1000000 construction/logistic bots, is joined to each filter stack inserter (F12) to ensure they do not unload bots into the logistic storage chests. Only the stack filter inserters designated to direct insertion (F13 and F14) will pull bots from the cargo wagon.

There is one exception to the logic which can cause significant problems. Due to the fact that combinators have at least one tick of delay before they are run, it is possible for trains who are setup to depart when D=1 to inadvertantly depart the moment they arrive at the station. This can happen if the default state of the unloader sends D=1 to the train when no train is at the train stop (T11). For this reason, we added C8, a constant conbinator which always adds T=2 to the R3 signal. This effectively causes D5 to output T=1 by default, which causes the D3 to not send a D=1 departure signal to the train stop (T11) by default. When a train arrives, the train number (T) is normalized in D4 and sends an additional T=1 signal to R3, causing R3 to have T=3. Because R3 now has T=3, then D5 will no longer output the T=1 signal it did before.

That is everything that the unloader logic does. In addition to the logic it does, it also integrates with other aspects of the TLS Unloader through the Alpha and Beta Networks. There are four unique wires that need to be connected to the train stop systems and trash systems: Alpha Red, Alpha Green, Beta Red, and Beta Green.

Alpha Red contains all the items requested by the TLS Unloader. Each additional train stop that is added will have an additional constant combinator that lists the items requested. Those items are all joined in on Alpha Red.

Alpha Green contains the train contents and depart conditions. This green wire connects to all of the train stops in the TLS Unloader (except trash). This wire contains the contents of whatever train is being unloaded as well as tells that train when to depart.

Beta Red contains the number of bots and items in storage, in negative form. This value is used by all of the train stop enabler systems to determine whether or not a train should be called to the TLS Unloader.

Beta Green contains the signal that is reported by the incoming rail signal as well as the pump placement check. These signals are used in the Train Stop system (see below).