Page 1 of 1

Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 11:58 am
by Steff7744
Hi there, I was wondering for a week now how could I make my idea true. I was looking through youtube but I couldn't find something similar.

So... I've got an idea about train stop circuit network/combinators stopping. I want to make my train stop to activate when my chest warehouse have requested items BELOW certain threshold then stay activated until it reaches upper limit and after that activate only when it reaches lower limit, for example:

We have upper threshold 10k, lower threshold 1k
1) If we are below 1k we activate train stop until we hit 10k
2) After that we deactivate train stop
3) We wait until we are below 1k and then activate train stop
4) Repeat

I don't know if it's even possible to do something like this , I am really new to circuit network and combinators. If you could tell me how to do it I would be really happy!

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 1:01 pm
by Nosferatu
What you need for that is a SR latch
https://wiki.factorio.com/Tutorial:Circ ... er_version

But before we go into details:
Why?
Deactivating and activating is not recommend.
It's better to calculate how many train loads are missing and set the train limit through that.
If it's full it will be 0 and no more train will be summoned.

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 1:29 pm
by FuryoftheStars
Nosferatu wrote: Thu Nov 30, 2023 1:01 pm Deactivating and activating is not recommend.
To add onto this, I believe one of the devs said something a while back about removing this ability with 2.0.

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 2:13 pm
by mmmPI
I agree with what was said, that for the described purpose, maybe using dynamic limit based on the missing material quantity and room available to unload would be more appropriate than activating/deactivating based on threshold value. This would require using an arithmetic combinator to divide the material quantity and 1 train capacity, so that the result is 1 or 2 or 3 depending on how many trains are needed, and then use this number as the "limit".

For deactivating/activating a SR-latch as linked from the cookbook would do but if you are really new to combinator, there are simpler setup that achieve the logic you describe that may be easier to begin with : if you use 2 connected inserters to pass a fish either "right" or "left" if iron is missing at the warehouse or not you can then read on belts on which side is the fish, and enable the station if the fish is one the side that means the warehouse need iron.



Why it's not recommended is when you have several trains that try to unload iron to this station, if you have 9500 iron, and 5 trains going to that station, when the first train has unload, the station will "disable" and leave the 4 other incoming train potentially stuck in unwanted places. Whereas reducing the limit allows trains already moving to complete their trip instead of getting stuck as when the station disable itself.

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 3:28 pm
by aka13
FuryoftheStars wrote: Thu Nov 30, 2023 1:29 pm
Nosferatu wrote: Thu Nov 30, 2023 1:01 pm Deactivating and activating is not recommend.
To add onto this, I believe one of the devs said something a while back about removing this ability with 2.0.
Yeah, I also remember, that it is going to be removed. I hope that a train manager is coming with 2.0 though.

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 3:39 pm
by Tertius
Steff7744 wrote: Thu Nov 30, 2023 11:58 amI want to make my train stop to activate when my chest warehouse have requested items BELOW certain threshold then stay activated until it reaches upper limit and after that activate only when it reaches lower limit
Is this really what you want? Why do you want to wait for the refill until the station is almost empty? You have a problem if the train is late and the station runs empty, for example.
  • you want trains unloading as fast as possible
  • you want your warehouse as full as possible
  • and you don't want trains waiting in front of a full station, congesting the tracks
  • and you don't want a train halting on a station, but the chests are already full, so the almost empty train stands there and does nothing
May be you didn't think enough about the most simple solution: a simple threshold. The crucial point is to choose the correct threshold! And the train limit feature of the station.

To avoid trains halting half empty on a full station, you need to allow trains only if there is enough empty space in the station chests for a full train. So a full train can be emptied into the chests completely.

To achieve this, first compute the train capacity. For an ore train with 4 wagons, this is: 4 * 40 * 50 = 8000.
We can fit a whole train into the station chests, if there is at least 8000 free space in our station.

Then there is the station capacity. An ore station for 4 wagons and 4 chests per wagon has a capacity of 4 * 4 * 48 * 50 = 38400.
To avoid combinators, we don't check the "free space" but instead check station content: If we have below 38400 - 8000 = 30400 ore in our station, we can receive a full train. If we have above 30400 ore, we cannot store another full train. So that's our threshold: 30400.
So connect all your ore chests in your station with a wire to add up their content, connect the station as well, and set this as activation condition in the station: [material] < 30400
If you have a different number of wagons or station chests, this number needs to be changed accordingly.

Additionally, we need to avoid multiple trains heading to the station at the same time and pile up in front of it. So additionally, set the train limit of the station to 1. This way we only ever have 1 train heading to that station. One train if the station is active. This way we also avoid additional trains currently heading to the station are suddenly halting in the middle of nowhere and congest the rails the moment the station is deactivated.

If this concept is working for you in general, you can think about optimizing and add dynamic station limits. This requires combinators. And I would still not recommend using 2 thresholds and apply a hysteresis. But don't take the second step before the first step. In many cases, the most simple solution is perfectly enough.

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 4:29 pm
by Steff7744
Thank you, you are right! I will try to get this one done!

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 8:43 pm
by Qon
aka13 wrote: Thu Nov 30, 2023 3:28 pm
FuryoftheStars wrote: Thu Nov 30, 2023 1:29 pm
Nosferatu wrote: Thu Nov 30, 2023 1:01 pm Deactivating and activating is not recommend.
To add onto this, I believe one of the devs said something a while back about removing this ability with 2.0.
Yeah, I also remember, that it is going to be removed. I hope that a train manager is coming with 2.0 though.
FuryoftheStars wrote: Thu Nov 30, 2023 1:29 pm
Source?

There are use cases that disabling solves that the limit option can't handle, I think. Trains can skip disabled stations, but waits for limited ones to open. So if they remove this then we need new features to replace disabling to make advanced combinator contraptions possible. Trains are one of the few things actually possible to really influence with combinators as it is now, so it would be sad if we lose something like this.

Re: Dynamic Train Stop activation/deactivation

Posted: Thu Nov 30, 2023 8:48 pm
by FuryoftheStars
Qon wrote: Thu Nov 30, 2023 8:43 pm
aka13 wrote: Thu Nov 30, 2023 3:28 pm
FuryoftheStars wrote: Thu Nov 30, 2023 1:29 pm
Nosferatu wrote: Thu Nov 30, 2023 1:01 pm Deactivating and activating is not recommend.
To add onto this, I believe one of the devs said something a while back about removing this ability with 2.0.
Yeah, I also remember, that it is going to be removed. I hope that a train manager is coming with 2.0 though.
FuryoftheStars wrote: Thu Nov 30, 2023 1:29 pm
Source?

There are use cases that disabling solves that the limit option can't handle, I think. Trains can skip disabled stations, but waits for limited ones to open. So if they remove this then we need new features to replace disabling to make advanced combinator contraptions possible. Trains are one of the few things actually possible to really influence with combinators as it is now, so it would be sad if we lose something like this.
viewtopic.php?f=18&t=103536&p=574563&hi ... le#p574563

Re: Dynamic Train Stop activation/deactivation

Posted: Fri Dec 01, 2023 8:00 am
by mmmPI
Qon wrote: Thu Nov 30, 2023 8:43 pm There are use cases that disabling solves that the limit option can't handle, I think. Trains can skip disabled stations, but waits for limited ones to open. So if they remove this then we need new features to replace disabling to make advanced combinator contraptions possible. Trains are one of the few things actually possible to really influence with combinators as it is now, so it would be sad if we lose something like this.
Yes ! without disabling trains there would be no way of skipping station in current state of the game, but also limit were added on top of existing system, and since then there was always some players complaining that some situations were difficult to understand or not getting the interactions, so i hope the relation between combinators and trains was reworked in a way that would keep both of the possibilities offered by disabling or reducing limit to 0, but in a way that is made easier to understand for players. Although i still expect players asking for help to understand some situations me including :)