Automated Train stock delivery system
Posted: Thu May 05, 2016 3:48 am
At last I have finally done something I haven't seen on Factorio anywhere else, I have created a train delivery system that will only take the supplies that a consumer needs, thus keeping your train's cargo wagons to a minimum and to stop them being over stocked and stored in your wagons.
I have spent hours on this working out the math and the wiring to get it to work and I have finally got it working automatically without any intervention whatsoever, and I want to share this with you Factorio fans. I have saved this as a simple blueprint for you to follow if you need to, so you can use it with the blueprint mod and copy from.
I'm going to do a simple version with one type of good to give you the idea but it can be achieved with multiple stops and multiple types of items. If you would like me to give you a tutorial on those let me know and I'll get on it. Despite it being a simple version I have had to post it in 2 parts as you can't upload more than 10 images at a time.
Setting up the stations
I am going to start simply with a train going in a loop and have one pick up and drop off station. Obviously your trains may not be in a loop like this but I will give you a list of the parts I used for this tutorial.
You will need;
• 38 Straight track rails
• 8 Curved track rails
• 1 Locomotive
• 1 Cargo wagon
• 2 Train Stops
• 24 Smart inserters
• 9 Fast inserters
• 18 smart chests
• 5 Medium electric poles
• 3 Large electric poles
I'll assume some of you will want to build it onto your currently existing stations so skip to the next step if you want to just build it onto a ready built one. Otherwise build a loop of track but make it long enough to fit the locomotive and wagons on the straights. Place down your stations as well making sure to allow space for the train.
Once you have your stations placed you will want a fast inserters coming in and out both of the stations (in for the pickup, out for the drop off) followed by a smart chests, then another set of smart inserters. The pickup station is now done but the drop off station will need another set of smart chests and inserters. (Once the Devs allow the wires to connect to stations and signals and such then you won't need these and you can set it up like the pickup station). Once this is done you can like them with belts as per usual.
(Ignore the fact the good coming and going to chests, that's just for tutorial purposes)
Now that is done the stations are complete now is time to set up where the combinators are going.
The program setup
You will need;
• 2 arithmetic combinators
• 1 decider combinator
• 1 constant combinator
• 5 Smart chests
• 6 Smart inserters
• 2 Fast inserters
• 1 chest (any type)
• 4 transport belts
Honestly you can place these pieces anywhere you like but the closer to the stations, the better as it will cost you less wire and electric poles.
The first thing we will start with the pickup station. We will need to place is a set 4 smart chests and inserters to make a “switch” mechanism. “Coincidently” I have already made a tutorial on this, take a look here viewtopic.php?f=8&t=24868 to take a look as you may need to know how it works to continue. Preferably build this close to the row of chests at the pickup station as it may help with wiring in the next part.
Next place down a decider combinator below the switch, then place an arithmetic combinator below and to the side, (this is better placed to the side furthest from the station as it won't be linked directly to it) of the decider, and finally a constant combinator next to the 2nd arithmetic combinator.
At the drop off you will only need another “Switch” but not like the one we used at the other station. Again this switch is also on my other post I mentioned above. Place down a smart chest and any chest next to it. Then put a smart inserter coming out of both of the chests and adjacent to them, fast inserters going into the chests. Then put a couple transport belts (I recommend basic ones as it will cost less resources and actually help the process) I front of the inserters to make a loop.
That's it for the program set up. Now it's time for the difficult bit.
Programming and wiring
You will need;
• Red wires
• Green wires
• 3 of any same item (I recommend what your transporting)
• To closely follow this guide
Don't worry about getting too confused with what I'm doing; I'll explain what a lot of the math does as we go forward. We will start at the pickup station as it’s where the magic happens. First you want to get something clear, I'm using red wires as it's easier to see in the images so I'll be referencing to that when using the “Main” wire as you will need both colours. I'll be calling them by colour so make sure you don't get confused and muddle them up as it will mess up the signals and may not work.
So the first thing you will want to know is how much stock you have of the certain item you have at one point in time. I am going to use “coal” to make it easier. I have put 50 coal in the storages at the Drop off station, which are the SECOND SET of smart chests that the coal will go into as it comes off the wagon, as I have 6 I have a total of 300 coal in storage. You will need to get some red wire and connect all of these chests together and send it along the electric cables to the pickup station and connect it to the arithmetic combinator furthest away from the station. Remember that the slanted edge is the input side of the combinators.
As you can see, if it is wired correctly you will be able the see the signals being sent through the electric poles with the colour of the wire you used. The combinator will have this too but it may not be coloured.
Now you’ll want to set up the maximum of stock you want at the drop off station. To do that you will want to go onto the constant combinator and set an output signal of the amount you want. MAKE SURE IT’S A SIGNAL not something from another category. I am using signal “A” and I'm going to say I want 1,000 coal stored in the smart chests at the other station. If you want a specific amount, don't forget to consider the about of items that will be on the belts and chests after the storages.
Now it's time for math. First link the constant combinator to the arithmetic combinator before. You can use the same colour wire because the signals are different. After that you'll want to go into the arithmetic combinator and set it as [Signal A – Coal] (that's a minus sign, just to be safe) (Remember to use the signal and stock you used). And set the output signal to any signal you haven't just used (I'm using Signal B). If it's done correctly you will see when you hover over the arithmetic combinator that it will have two Input signals and an output signal and they should have numbers in them too. If you do the math you should work out right, if not then something has gone wrong somewhere. This is how much stock the system will NEED to load to send over.
The next signal you will need is the one to count how much is GOING to be sent over. Like on the other side, connect all the smart chests with your main colour wire and connect it to the arithmetic combinator that we haven't yet used. Open it up and set the input as [Coal * 1] (again the asterisk symbolises multiply) and set the output as another signal you haven't already used, I'll use Signal C. You won't see an output in the info panel as it's not getting a signal but if you put some stock into any of the chests you should have one come up.
Now it's time to mix the signals. Cable both of the arithmetic combinators to the decider combinator on the input side. Again you can use your main wire for this. Now in the decider combinator set the parameters as [Signal C > Signal B] and your output as any signal you haven't used and check the 1 circle at the side of it (I'm using Blue Signal). That is the calculations done. Now just link the first set of smart inserters to the decider combinator and set all of the inserters to [Blue Signal = 0] and it should all work.
Now, if all is done correctly, put some of your stock in the chests (mix them up oddly if you like, the combinator adds them up together automatically) and you should see that it the signals will register. Also if you set up the smart inserters to filter your stock then you actually see it in action and it will stop inserting your stock when the limit is reached. It may go one or two over, if so just lower the total stock you want by that amount, but it shouldn't matter that much.
That's the basic concept all done, but where not finished yet, sorry, you will have to read on. Unfortunately, if we was to let it run everything now it wouldn't work, simply because as the next set of inserters takes the coal and puts it into the cargo wagon the combinator will register less in the chests and thus make the first set put more in, and then you have a cycle and we're back to where we started. This is what the switch is for.
!!!!! SPLIT POST, FOLLOW NEXT POST !!!!!
I have spent hours on this working out the math and the wiring to get it to work and I have finally got it working automatically without any intervention whatsoever, and I want to share this with you Factorio fans. I have saved this as a simple blueprint for you to follow if you need to, so you can use it with the blueprint mod and copy from.
I'm going to do a simple version with one type of good to give you the idea but it can be achieved with multiple stops and multiple types of items. If you would like me to give you a tutorial on those let me know and I'll get on it. Despite it being a simple version I have had to post it in 2 parts as you can't upload more than 10 images at a time.
Setting up the stations
I am going to start simply with a train going in a loop and have one pick up and drop off station. Obviously your trains may not be in a loop like this but I will give you a list of the parts I used for this tutorial.
You will need;
• 38 Straight track rails
• 8 Curved track rails
• 1 Locomotive
• 1 Cargo wagon
• 2 Train Stops
• 24 Smart inserters
• 9 Fast inserters
• 18 smart chests
• 5 Medium electric poles
• 3 Large electric poles
I'll assume some of you will want to build it onto your currently existing stations so skip to the next step if you want to just build it onto a ready built one. Otherwise build a loop of track but make it long enough to fit the locomotive and wagons on the straights. Place down your stations as well making sure to allow space for the train.
Once you have your stations placed you will want a fast inserters coming in and out both of the stations (in for the pickup, out for the drop off) followed by a smart chests, then another set of smart inserters. The pickup station is now done but the drop off station will need another set of smart chests and inserters. (Once the Devs allow the wires to connect to stations and signals and such then you won't need these and you can set it up like the pickup station). Once this is done you can like them with belts as per usual.
(Ignore the fact the good coming and going to chests, that's just for tutorial purposes)
Now that is done the stations are complete now is time to set up where the combinators are going.
The program setup
You will need;
• 2 arithmetic combinators
• 1 decider combinator
• 1 constant combinator
• 5 Smart chests
• 6 Smart inserters
• 2 Fast inserters
• 1 chest (any type)
• 4 transport belts
Honestly you can place these pieces anywhere you like but the closer to the stations, the better as it will cost you less wire and electric poles.
The first thing we will start with the pickup station. We will need to place is a set 4 smart chests and inserters to make a “switch” mechanism. “Coincidently” I have already made a tutorial on this, take a look here viewtopic.php?f=8&t=24868 to take a look as you may need to know how it works to continue. Preferably build this close to the row of chests at the pickup station as it may help with wiring in the next part.
Next place down a decider combinator below the switch, then place an arithmetic combinator below and to the side, (this is better placed to the side furthest from the station as it won't be linked directly to it) of the decider, and finally a constant combinator next to the 2nd arithmetic combinator.
At the drop off you will only need another “Switch” but not like the one we used at the other station. Again this switch is also on my other post I mentioned above. Place down a smart chest and any chest next to it. Then put a smart inserter coming out of both of the chests and adjacent to them, fast inserters going into the chests. Then put a couple transport belts (I recommend basic ones as it will cost less resources and actually help the process) I front of the inserters to make a loop.
That's it for the program set up. Now it's time for the difficult bit.
Programming and wiring
You will need;
• Red wires
• Green wires
• 3 of any same item (I recommend what your transporting)
• To closely follow this guide
Don't worry about getting too confused with what I'm doing; I'll explain what a lot of the math does as we go forward. We will start at the pickup station as it’s where the magic happens. First you want to get something clear, I'm using red wires as it's easier to see in the images so I'll be referencing to that when using the “Main” wire as you will need both colours. I'll be calling them by colour so make sure you don't get confused and muddle them up as it will mess up the signals and may not work.
So the first thing you will want to know is how much stock you have of the certain item you have at one point in time. I am going to use “coal” to make it easier. I have put 50 coal in the storages at the Drop off station, which are the SECOND SET of smart chests that the coal will go into as it comes off the wagon, as I have 6 I have a total of 300 coal in storage. You will need to get some red wire and connect all of these chests together and send it along the electric cables to the pickup station and connect it to the arithmetic combinator furthest away from the station. Remember that the slanted edge is the input side of the combinators.
As you can see, if it is wired correctly you will be able the see the signals being sent through the electric poles with the colour of the wire you used. The combinator will have this too but it may not be coloured.
Now you’ll want to set up the maximum of stock you want at the drop off station. To do that you will want to go onto the constant combinator and set an output signal of the amount you want. MAKE SURE IT’S A SIGNAL not something from another category. I am using signal “A” and I'm going to say I want 1,000 coal stored in the smart chests at the other station. If you want a specific amount, don't forget to consider the about of items that will be on the belts and chests after the storages.
Now it's time for math. First link the constant combinator to the arithmetic combinator before. You can use the same colour wire because the signals are different. After that you'll want to go into the arithmetic combinator and set it as [Signal A – Coal] (that's a minus sign, just to be safe) (Remember to use the signal and stock you used). And set the output signal to any signal you haven't just used (I'm using Signal B). If it's done correctly you will see when you hover over the arithmetic combinator that it will have two Input signals and an output signal and they should have numbers in them too. If you do the math you should work out right, if not then something has gone wrong somewhere. This is how much stock the system will NEED to load to send over.
The next signal you will need is the one to count how much is GOING to be sent over. Like on the other side, connect all the smart chests with your main colour wire and connect it to the arithmetic combinator that we haven't yet used. Open it up and set the input as [Coal * 1] (again the asterisk symbolises multiply) and set the output as another signal you haven't already used, I'll use Signal C. You won't see an output in the info panel as it's not getting a signal but if you put some stock into any of the chests you should have one come up.
Now it's time to mix the signals. Cable both of the arithmetic combinators to the decider combinator on the input side. Again you can use your main wire for this. Now in the decider combinator set the parameters as [Signal C > Signal B] and your output as any signal you haven't used and check the 1 circle at the side of it (I'm using Blue Signal). That is the calculations done. Now just link the first set of smart inserters to the decider combinator and set all of the inserters to [Blue Signal = 0] and it should all work.
Now, if all is done correctly, put some of your stock in the chests (mix them up oddly if you like, the combinator adds them up together automatically) and you should see that it the signals will register. Also if you set up the smart inserters to filter your stock then you actually see it in action and it will stop inserting your stock when the limit is reached. It may go one or two over, if so just lower the total stock you want by that amount, but it shouldn't matter that much.
That's the basic concept all done, but where not finished yet, sorry, you will have to read on. Unfortunately, if we was to let it run everything now it wouldn't work, simply because as the next set of inserters takes the coal and puts it into the cargo wagon the combinator will register less in the chests and thus make the first set put more in, and then you have a cycle and we're back to where we started. This is what the switch is for.
!!!!! SPLIT POST, FOLLOW NEXT POST !!!!!