Unloading the train at max speed

Does the train have an item loaded that we want to unload?



Is the currently stored amount of this item less than what we want?

Get the current amount of items stored and convert them to negative.



amount of items stored and convert them to negative. Get the amount of items we want stored, filtered to the identification item in the steel chest.



stored, filtered to the identification item in the steel chest. Combine both signals and activate the inserters if the item signal is greater than zero

[static3.businessinsider.com]

This section is the heart of this build. The previous three sections you read before are only required because there is no easy way (without mods, of course) to know if a train is stationed and which items it has loaded.The concept I have is the following:We have one constant combinator that is used to specify which items we unload, and how many of each item we want in storage.The conditions that we need to implement with combinator logic are:Sounds easy- right? Well, lets see:Lets get into the details.The setup has three 3 parts:Constant Combinator (C) is our source for the information of how much of each item we want to have stored (and therefore also which types of item we want to unload).It's trivial to set up: If you want 10k iron plate stored, let it emit a Signal (IRON_PLATE=10k). You can have multiple item types in here, each with a different max stored setting if you like.The Decider (G) also straight forward.You can see two wires attached to it's input.One will send the current amount of items, the other one the number of items we have stored (converted to negative).If the result is positive, it is redirected to the insertes to activated.So, it's time to get to those two signals.The first thing we need to to is filter two sets of signals to their intersection In our case, Set A is the content of the steel chest, which only contains one item. Let's say 3 Copper Plate (3 if you stack inserter bonus is maxed out).Set B is the content of the Constant Combinator (A). Let's say 1,000 Copper Plate and 1,000 Iron Plate.The filtering works like this:Normalize Set A to a value of 1 - we do this by using Combinator (A), which takes any input signals and returns the same signals with a value of 1.We then multiply each signal of Set A (only copper plate in our case, COPPER from now on) by 2M to Set A. We want to choose a number big enough to always exceed the storage limit!So the result of our example would be Signal(COPPER=1) * 2M = Signal(COPPER=2,000,000) 2,000,000. This is done in Calculator (B).This result is now added to the defined storage limits of Set B (Content of Combinator (C).The addition calculation happens automatically by attaching the output of Calculator (B) and Combinator (C) to the input of Decider (D).The result of this addion is two signals:Signal(COPPER=2,001,000) and Signal(IRON=2,000,000).To now actually filter the result to the desired Signal(COPPER), we simply take 'each' input greater than 2M and output them - see configuraiton of Decider (D).The filtered Signal is now only Signal(COPPER=2,001,000). The requirement is to have value stored in the combinator - the storage limit of copper plates.This is done by simply sending the Signal(COPPER=2,001,000) to Calculator (E) which subtracts 2M and outputs the result.We now have one of the two signals required and send it to the final Decider (G).The other signal, as already mentioned, is our current storage turned to negative - this is really easy:Connect all storage chest with wire and then connect one of them to Calculator (F).Calculator (F) simply multiplies 'each' signal by -1. That's it!All that's left is connect the output of Calculator(F) to the input of Decider (G).Calculation of the difference happens automatically, and Decider (G) will only pass on positive Signals.Here are two example calculations of the whole process:Steel Chest: 3 Copper Platte (Example A), 3 Iron Plate (Example B)Storage Limit (Constant Combinator (C)): 1K Copper Plate, 1k Iron Plate.Current Storage: 1100 Iron Plate, 500 Copper PlateExample A:As described above, we will have a Signal of Signal(COPPER=1,000) as ouput of the filtering process (Calculator (D)) - the first input to the final Decider (D).The second signal, our negative storage content is Signal(COPPER=-500) and Signal(IRON=-1,100).Combining both sets results inSignal(COPPER=1000)-Signal(COPPER=-500) = Signal(COPPER=500)and Signal(IRON=-1,100).As the Decider only passes through signals > 0, only Signal(COPPER=500) is sent to the Inserters (H) to activate them.Example B:Filtered output of Calculator (D) = Signal(IRON=1000).Negative storage content = Signal(IRON=-1,100) and Signal (COPPER=-500).Combination Result:Signal(IRON=-1,100) + Signal(IRON=1000) = Signal(IRON=-100)and SIGNAL(COPPER=-500).Both signals are negative. This means that no signal is passed to the inserters and they will be inactive.Note that the steel chest will only ever hold one item (with a stack size varying between 1 and 3, depending on your research).This means that the intersection of SteelChest and Constant Combinator(C) will also only result in a single signal - or no signal if the chest is empty.Since the current storage content always converted to negative, it will never be above zero without adding something. W are adding the filtered Constant Combinator result - only one signal. -> Either one or zero signals are sent to the inserters to activate/deactivate the unloading process.Thanks for reading this guide. I hope you were able to learn something new and that it helps you to build a glorious factory.Please leave feedback, improvement ideas (content/guide) and anything else you come up with!-- Pasukaru