Train Contents, Reading, Loading Cargo with Inserters

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

I set up my factory so that my trains transport materials around the area. Don't know if I'm doing this right or if there is a better way to do it. I'm reading the contents of the train with either the red or green wire. Doesn't matter what color I don't think. I've got an inserter that is supposed to only load the train cargo wagon if the contents is less than a set amount. So I basically have the inserter connected to the train station. The inserter is set with an enabled condition such as "enable/disable .. Enabled condition (Iron gear wheel) < 400." Intuitively it seems like this should work. However I discovered that if the train is full (Iron gear wheel > 400), the inserter will activate one time placing one load on to the train and then shut off. So regardless of the fact that the condition is NOT TRUE, the insterer ALWAYS activates ONE TIME. Is this the way it is supposed to behave? Am I not setting this up correctly? Is this a bug?

aaargha
Filter Inserter
Filter Inserter
Posts: 330
Joined: Wed Dec 07, 2016 8:35 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by aaargha »

I have not tired this so this is mostly just me guessing.

I think the issue is that the inserter is enabled when there is no train on the station, no signal means that Iron gear wheel < 400 is true. When the train arrives the inserter sees the available inventory before the circuit signal reaches it and disables it so it always completes the first swing. Setting it up in such a way that if there is no train a 10k Iron gear wheels signal is output should fix the issue, you just have to make sure there are no gaps where the signal is 0 when switching from the dummy signal to the one from the train.

User avatar
Lav
Filter Inserter
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Lav »

Exactly.

What's needed is a small combinator setup that checks for train ID transmitted by the station AND resource amount being less than desired, and generate a signal that inserter will use to activate.

arbarbonif
Fast Inserter
Fast Inserter
Posts: 110
Joined: Fri Jul 01, 2016 2:46 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by arbarbonif »

If you are dealing with a max of a multiple of stack size, you can also just set filters and limits on the cargo wagon and then the inserter won't over load. Otherwise it sounds like a tick delay between the inserter having a valid place to put stuff and the signal of cargo size appearing to disable it. The "trainID > 0 and cargo < 400" theory should work.

Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

I thought I had this solved by using combinators to only output the train contents when the train ID > 0. It doesn't solve the problem because of the fact that I have a condition on each inserter that checks the train contents. If it cannot read the train contents, then it will assume that it is zero, and put one handful of items in the train. I've been working on this for hours now. It's a major pain in the ass. Someone suggested just limiting the stack size in the cargo wagon. However, I'm trying to set up a system where I can put in a single wagon multiple items, and limit the number of each type of item.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by DaveMcW »

viewtopic.php?f=18&t=49434

I agree this is frustrating and train station inserters should sync with the circuit network by default.

Muche
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Muche »

It seems my solution is too complicated - both train contents and desired amounts are gated via combinators (plus one delay (via OR) was needed when the train was switched from automatic to manual and stayed in the station - for one tick inserters thought the train is empty), and extra combinators for setting individual stack sizes.
screenshot
screenshot
CondLoad1.png (633.32 KiB) Viewed 19684 times
screenshot with info shown
screenshot with info shown
CondLoad2.png (677.97 KiB) Viewed 19684 times
blueprint

User avatar
Lav
Filter Inserter
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Lav »

You can do the same thing with just 3 combinators, which would support up to 18 resources (with 1 extra constant combinator per each additional 18 resource types).

1. Station: read train contents, read stopped train (signal "T"). Example: iron=120, copper=230, T=53
2. Arithmetic combinator: multiply Each by -1, output Each. Inverts station's output. Example: iron=-120, copper=-230, T=-53
3. Constant combinator: contains the target amounts of resources that you want to load onto the train. Example: iron=150, copper=150
4. Both combinators output to the final decider combinator's input, so their outputs are summed up. Example: iron=30, copper=-80, T=-53
5. Decider combinator: check that T < 0, output "Everything/input signal". Example: iron=30, copper=-80, T=-53
6. Inserters are connected to decider combinator's output and each handle their own resource. Example: activate on Iron>0 = ACTIVE, activate on Copper>0 = INACTIVE.

You can put up to 18 different signals in a single constant combinator, so 3 combinators are enough to handle 18 different resources.

Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

Thanks for this post with the combinators, etc. I will build this from the blueprint just as a study of combinators so I can understand them better. But as I get more into this, it becomes clear that the solution is not simple. There's something blatantly wrong with the basic game mechanics when it comes to reading the contents of the train and controlling inserters to respond to that information, I think. The solution with all the combinators is not only complex but it takes up a massive amount of space on the map at each train station. That's just ridiculous beyond all comprehension. I've thought of a workaround that is simpler, but still requires a good amount of map space. I could set up one train station that does nothing except act as an overflow depot. Inserters would remove product off of the train that is over my desired amount. The products would then be transported to the other side of the wagons where they would then be loaded on to the wagons if the quantity is less than the desired amount. This would not stop unnecessary amounts of products from being created, but at least it would keep the cargo wagons from being overloaded.

Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

Obviously I didn't see the post by LAV. My eyes skipped over it I guess because it looked like it was part of the previous post. Yep, LAV's solution works and doesn't take up much real estate on the map. I think I saw this solution before but I didn't understand it probably because I hadn't run up against this problem before. I needed to knock my head against it first. What this solution does is take my previous solution and reverse the values and reverse some of the logic. Instead of my inserters checking for the contents being less than the max value, they check for what is needed to reach the max value. Somehow this works, not sure exactly why. I had a decider combinator that outputted the input values from the station when "T" signal > 0, but that did not work. Not exactly sure why LAV's solution works. Something about reversing the logic and values, maybe? Anyhow I'm attaching screen shots for further clarification.
Clip0005.jpg
Clip0005.jpg (159.04 KiB) Viewed 19637 times
Clip0006.jpg
Clip0006.jpg (14.06 KiB) Viewed 19637 times
Clip0003.jpg
Clip0003.jpg (17.1 KiB) Viewed 19637 times
Clip0002.jpg
Clip0002.jpg (13.8 KiB) Viewed 19637 times

User avatar
Lav
Filter Inserter
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Lav »

When you have multiple sources of signals in your circuit network, those sources are added up. This "implicit" addition is what allows to perform bulk operations over multiple signals.

In this case, there's a separate small circuit network that connects outputs of constant/arithmetic combinator and input of decider combinator. First two are signal generators, and their values are added up. And since arithmetic combinator inverts the value of train contents, the network effectively contains values for ResourceDesired - ResourceLoaded for all resources.

After that, decider combinator simply functions as a logic gate: it only transmits those values further if there's a T signal present in the network. And it checks for negative T signal because arithmetic combinator inverts it together with all other resource signals.

Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

I understand HOW it all works. I just don't understand why it works as opposed to the first way I tried, which was with a simple decider combinator that checks for the train signal and then passed the train contents through to the inserters. It's like saying that to move forward one step, you have to walk forward 3 steps and then take 2 steps back. Why can't I just take one step forward? Nope, can't do that. OK why?

User avatar
Lav
Filter Inserter
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Lav »

Cauled wrote:I understand HOW it all works. I just don't understand why it works as opposed to the first way I tried, which was with a simple decider combinator that checks for the train signal and then passed the train contents through to the inserters. It's like saying that to move forward one step, you have to walk forward 3 steps and then take 2 steps back. Why can't I just take one step forward? Nope, can't do that. OK why?
If I understand the first method you tried correctly, the reason was quite simple: if there's no train, then your decider combinator didn't pass the signals further, but it doesn't mean that no signals are transferred. It means all signals are zero. And zero is definitely less than 400 or whatever your inserter condition is.

That's I guess what you missed: all circuit networks always transmit all signals. It's only their UI that's suppressing all zero signals for readability's sake.

Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

If that logic is right, then the decider combinator can't prevent a zero value for the contents from being transmitted to the inserters, even if you put a condition on it. So then the solution with the constant combinator and the arithmetic combinator works because the inserters are checkng for a value greater than or less than zero, which will never be true by that quirk. A value of less than zero is product that is less than the desired amount, and a positive value is more than the desired amount. If it is zero, then it is the exact desired amount, in which case the inserters would do nothing because the condition would be false. So basically it sets it up so that a zero value of the train contents does not affect the inserters, whether that zero value is the actual value of the contents or a quirk in the mechanics of the train's circuit network. Got it, thanks.

arbarbonif
Fast Inserter
Fast Inserter
Posts: 110
Joined: Fri Jul 01, 2016 2:46 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by arbarbonif »

Cauled wrote:I thought I had this solved by using combinators to only output the train contents when the train ID > 0. It doesn't solve the problem because of the fact that I have a condition on each inserter that checks the train contents. If it cannot read the train contents, then it will assume that it is zero, and put one handful of items in the train. I've been working on this for hours now. It's a major pain in the ass. Someone suggested just limiting the stack size in the cargo wagon. However, I'm trying to set up a system where I can put in a single wagon multiple items, and limit the number of each type of item.
You do realize that you can set filters on slots in the train wagon right? So if you want to have 400 iron gear wheels you can set 4 of the slots to only accept iron gear wheels (and not have any slots without a filter) and the wagon will only be loaded with 400 gear wheels. It won't work if you want only 345 gear wheels or if you want to have slots that will accept anything in the same wagon, but you can set independent filters on each slot.

Cauled
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Jun 08, 2017 11:51 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by Cauled »

Cauled wrote:If that logic is right, then the decider combinator can't prevent a zero value for the contents from being transmitted to the inserters, even if you put a condition on it. So then the solution with the constant combinator and the arithmetic combinator works because the inserters are checkng for a value greater than or less than zero, which will never be true by that quirk. A value of less than zero is product that is less than the desired amount, and a positive value is more than the desired amount. If it is zero, then it is the exact desired amount, in which case the inserters would do nothing because the condition would be false. So basically it sets it up so that a zero value of the train contents does not affect the inserters, whether that zero value is the actual value of the contents or a quirk in the mechanics of the train's circuit network. Got it, thanks.
I knew that you could limit the number of useable slots within the cargo wagon like as with the chests, but I didn't realize that you could filter each slot for particular items. It would make the setup simpler if the amounts matched what I wanted to load. I'll see if it works better. Thanks for the tip.

forrey
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Dec 19, 2020 8:33 am
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by forrey »

I'm referring to the 3-component setup above, with an arithmetic combinator's input connected to the station (with 'read contents; read train'), and its output, along with that of a constant combinator, is connected to the input of a decider combinator.

Instead of, in the decider combinator, checking T<0, use a slot in the constant combinator to store T=<trainid>, and then change the decider combinator's condition to T=0. Then, the decider combinator will only output the items to be loaded when the train sitting at the station is the one with the same ID as is present in the constant combinator.

While this uses one of the constant combinator's slots, it gives you the power to select precisely (stack size notwithstanding) how much of each resource to put into one specific train, and only that train. By adding further copies of these 3 components, each linked to the station at one end, and a pole wired to all the inserters at the other, you can configure how each of multiple trains is loaded.

xplycyt
Burner Inserter
Burner Inserter
Posts: 9
Joined: Wed Apr 18, 2018 2:59 pm
Contact:

Re: Train Contents, Reading, Loading Cargo with Inserters

Post by xplycyt »

I solved this by setting up a power switch controlling the inserters that enables when train is at stop. Dont know if it creates a delay or inserters cant read contents without power.

Post Reply

Return to “Gameplay Help”