[MOD 0.15] SmartTrains 2.0.5

Topics and discussion about specific mods
Dark Matter
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue May 24, 2016 6:53 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Dark Matter »

I am interested in learning the inner workings of signals and train stops. I cannot tell from the code how the new signals get set/cleared when a train stops at the smart-train-stop. Can you provide guidance as to how I should explore the script?

Regards,

Dark Matter

Update: I found the code to update the signal in Train.lua. I am new to lua so I am still figuring out how it works but this seems to be where I should be reading. Is there another location that covers at the code level how signals work in factorio?
Last edited by Dark Matter on Tue May 24, 2016 7:20 pm, edited 1 time in total.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Choumiko »

It starts with the train arriving at a station: https://github.com/Choumiko/SmartTrains ... l.lua#L521
then checking if it's a smart trainstop: https://github.com/Choumiko/SmartTrains ... n.lua#L163
and finally setting the signals: https://github.com/Choumiko/SmartTrains ... n.lua#L193

Hope this helps, if not just keep asking
Dark Matter
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue May 24, 2016 6:53 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Dark Matter »

Thanks. I was writing my last update while you were sending your reply. I will study your reply before asking further.

Thanks for the prompt response.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

I have another (small) request for a useful feature:

Can the combinator at the train stop output a signal for "cargo full"? Just a binary condition on a fixed signal, the signal type should not depend on cargo type and it should work with mixed loads.

Basically the exact same condition that can be set in the line configuration "leave when full/empty".

It would be useful to have that condition in the combinator, because it's difficult to calculate in a circuit (especially if you don't even know the size of the cargo wagon, since it might be modded and not necessarly 1500 units). It's also very difficult if you don't know the type of content, or if it's a mixed content wagon.

Currently it's not even straightforward if you want the signal to trigger on "cargo full" (you have to use the signal if you want to set the next stop in the line configuration). Connecting the signal to the combinator and then doing something like "anything > x" is not possible because of the "fuel" value, which can be a large number.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Choumiko »

Dark Matter wrote:Update: I found the code to update the signal in Train.lua. I am new to lua so I am still figuring out how it works but this seems to be where I should be reading. Is there another location that covers at the code level how signals work in factorio?
Yoou might want to look at http://lua-api.factorio.com/0.12.33/Lua ... _condition to see what's availabel. Though right now you might be better off waiting until 0.13 is released, as that will bring changes to the circuit network and the API.
siggboy wrote:Can the combinator at the train stop output a signal for "cargo full"? Just a binary condition on a fixed signal, the signal type should not depend on cargo type and it should work with mixed loads.
Currently it's not even straightforward if you want the signal to trigger on "cargo full" (you have to use the signal if you want to set the next stop in the line configuration). Connecting the signal to the combinator and then doing something like "anything > x" is not possible because of the "fuel" value, which can be a large number.
It sure could, but if all you need it for is so that you can send the train to the signal value: the next version will have full/empty work with go to signal/ go to station: Beginnings of a readme for the next version
Last edited by Choumiko on Tue May 24, 2016 11:04 pm, edited 1 time in total.
User avatar
UntouchedWagons
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Thu Jan 01, 2015 6:16 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by UntouchedWagons »

I have an L-CC-L train with the two wagons being two Rail Tankers from the RailTankers (v1.3.0) mod and the train is set to refuel when it has less than 25 coal, but instead of going to "Refuel L-CC-L" it tries to go to the Refuel station which doesn't work. I updated Smart Trains to 0.3.82 to see if that fixed it but it doesn't. What do?
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

OK, short answer, since I tend to ramble:

Being able to send the train to the signal value is NOT the reason why I'd like this feature.

It's because it would allow for more power circuits directing the train, and it would NOT require the player to set up the train line in a specific way. The "full" condition could be a part of the circuit, and it could be something that you could disable dynamically.

To give an example:

Usually we want only "full" trains to leave an outpost. In a high demand situation, however, we might decide that we want to pick up everything that's currently available, so we'd skip the "full" condition. We send the trains away, have them load what's available and then leave as soon as the buffer chests dry up.

This is currently not possible if you use the "FULL" condition in the train line setup, and it's very difficult to work around if you try to emulate the "full" condition, for the reasons mentioned in my feature request.

(BTW I can't wait for the next version, when will you release it?) :P
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Xeteth
Fast Inserter
Fast Inserter
Posts: 158
Joined: Tue Feb 17, 2015 6:06 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Xeteth »

siggboy wrote: I have to admit that I don't really understand the point behind the unloading concept. As far as I can see, the trains (waiting on the stacker before the unload) are basically buffer chests. Why not unload them as quickly as possible, maybe balanced among the unloading stations?

If there are several trains (with ore in them) waiting on the stacker, that means you've picked up too many goods from the outposts, and now you've effectively reduced your total train bandwidth because those trains are forced to idle; and you need infrastructure (such as the stacker) to handle the situation.
The main reason why I built this unloader was to address the (kind of) stupid train pathfinding that we currently have. Trains will always try to path to the nearest station and if they cannot get there sometimes wait in a stacker even if another free unloading station appears. This is because once trains cannot get to a station they actually more-or-less go to sleep for 30 seconds. There's some intricate stuff at play with it - some of which I've talked to HanziQ about and he plans to improve the pathfinding in the future. This is not commonly seen on small scale unloading areas with 2 stations, but can become quite problematic when you have 4+ unloading stations as I currently have.

The other reason is that I do direct ore -> steel smelting and as such the smart stacker is able to allocate the resources to where they are needed.
Why are you buffering the resources in trains, in a stacker? So they are closer to the unload when you finally need them? Is that even a problem with a large enough buffer at the unload? The buffer can't suddenly run dry, prompting an "emergency" train delivery, can it?
I usually don't like buffers in general - mainly because once you store a ton of items in chests they are a complete pain to move (even with lots of bots), however since this buffer is through the trains I could potentially divert it elsewhere if I needed. The other benefit of doing it in this manner is that you can have resources build up as you are busy elsewhere in the world and once you launch a bunch of rockets there's a whole lot ready to go.

In future (once we get v13 and all the circuit network goodies) I will probably create a completely dynamic factory that requests exactly what it needs and have it all delivered by the trains based on resource demand :)
There's another player here on the forums, kann_, he's actually made a system that does train requests and deliveries much like the robot logistic network (reddit post is here: https://www.reddit.com/r/factorio/comme ... _provider/). I want to make my own system work like that as well.

Yep! I am basically holding off until v13 to do this :D

Does that mean you use 1 memory cell per outpost? So your outpost count is limited by the amount of memory at the base?
This is correct, at the moment there is 5 cells (5 outposts) for iron, copper and coal. Stone only has two as the demands for stone are usually substantially lower than the others. It must be noted that this is certainly a drawback of this system, however I don't think I've ever had more than 5 outposts of the one resource type going at any time. If I do find this to be an issue I could quite easily expand it :)
It helps to know some concepts, such as signal buses, multiplexing, that will make it easier to come up with practical solutions, but beyond that it won't help much.

There are some areas that are arcane enough that you basically have no chance to figure it out unless you have a solid CS background. For example, if you know how signed integers work in low-level computer programming, and if you are aware of the fact that this is exposed in the arithmetic combinators, it opens up possibilities for advanced designs.
This is very true! I was lucky enough to have a few members of the community teach me a few of these concepts (plus a heap of googling too!) and I learned things like data bus', using binary (and decoders), bit shift etc etc.


Looking back at my system now I can already see quite a few changes I want to make to optimise it, it will most likely be completely rebuilt in version 13 :) Really looking forward to the circuit network changes!
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Choumiko »

UntouchedWagons wrote:I have an L-CC-L train with the two wagons being two Rail Tankers from the RailTankers (v1.3.0) mod and the train is set to refuel when it has less than 25 coal, but instead of going to "Refuel L-CC-L" it tries to go to the Refuel station which doesn't work. I updated Smart Trains to 0.3.82 to see if that fixed it but it doesn't. What do?
I think we resolved it in irc? For the others: In that case mine the station, place it again and rename it.
siggboy wrote:Usually we want only "full" trains to leave an outpost. In a high demand situation, however, we might decide that we want to pick up everything that's currently available, so we'd skip the "full" condition. We send the trains away, have them load what's available and then leave as soon as the buffer chests dry up.

This is currently not possible if you use the "FULL" condition in the train line setup, and it's very difficult to work around if you try to emulate the "full" condition, for the reasons mentioned in my feature request.

(BTW I can't wait for the next version, when will you release it?) :P
The plan was to release weeks ago.. :roll: But somehow i keep adding/changing things. If i don't get too distracted i might make a prerelease in the next 24hours (i think i said something similar a few weeks ago :D )

I'm more or less sold on the idea of emitting full (and empty?) condition as a signal. But then: next version will allow "full" or "signal" (currently only and is possible), this should work for your example i guess, since your circuit setup needs to know whether it's in "high-demand mode" or not? Anyways, i'll probably add it in the version that will fix SmartTrains for 0.13.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

Choumiko wrote:I'm more or less sold on the idea of emitting full (and empty?) condition as a signal. But then: next version will allow "full" or "signal" (currently only and is possible), this should work for your example i guess, since your circuit setup needs to know whether it's in "high-demand mode" or not? Anyways, i'll probably add it in the version that will fix SmartTrains for 0.13.
I know about the change in the "full/empty" logic in conjuction with signals (good change), so that really wasn't the motivation at all for suggesting the change.

As a general rule I'd like to suggest the following with regards to which signals to emit from the combinator:

If a piece of information is used by the mod to direct trains, then it should be accessible in the game-world, by the circuit logic, as well (as long as it makes sense at all). In other words, the circuit should -- at least in principle -- know everything that the smart train stop "knows".

Here's an incomplete list of what I'm thinking of here:
  • Train full/empty (can be used as a condition in the UI, but not available in a circuit) -- as suggested.
  • Next stop of the train, when it leaves. The target station can be configured statically, but in the game this information is completely hidden and cannot even be deduced -- that's why I've suggested to have a "train-has-left" pulsed signal that informs about the next destination.
  • Train is set to "auto-depart" or not.
  • Train will move to refuel. Somewhat related to the previous, but it could be a "hold" signal while a train is at the station, indicating that the next destination will be a refueling stop. This could be deduced from the current fuel level, but only if the circuit knew what minimum fuel level is configured in the UI (but that's not exposed either).
  • There's probably more...
Now I'd completely understand if you didn't want to go all the way with that, in order to keep the number of signals manageable and not to overcomplicate things. On the other hand, we already have some exotic signals (fuel value in MJ, train line number), and missing others that are more important (IMHO).

It happens very quickly that you simply can not implement something because a crucial bit of information is unobtainable (e.g. the train leaves to refuel, and therefore does take a non-standard route -- there's currently absolutely no way to find out about that, but it's a perfectly legitimate feature you must expect the player/yourself to use).

I really hope I don't come across as nitpicking or overly demanding, by the way. I very much appreciate all the work you put into SmartTrains and FARL, and would probably not be playing the game anymore if it wasn't for these mods.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

Xeteth wrote:The main reason why I built this unloader was to address the (kind of) stupid train pathfinding that we currently have. Trains will always try to path to the nearest station and if they cannot get there sometimes wait in a stacker even if another free unloading station appears.
Ah, OK, I guess that's something that can only happen if you have several stations with the same name, and then let the game to pick either of those.

I want to eventually have the circuit pick the unloading stations explicitely (by station number), and never have more than one station with the same name; that's confusing anyway and it does hide information from SmartTrains/the circuit logic.
In future (once we get v13 and all the circuit network goodies) I will probably create a completely dynamic factory that requests exactly what it needs and have it all delivered by the trains based on resource demand :)
"Lean manufacturing" (the Japanese way). That's actually really interesting and poses so many interesting problems to solve in a factory. Such a scenario actually requires all sorts of precise bookkeeping regarding the train deliveries (so what you currently have or plan to do is certainly not over-engineered then any longer).
This is correct, at the moment there is 5 cells (5 outposts) for iron, copper and coal. Stone only has two as the demands for stone are usually substantially lower than the others. It must be noted that this is certainly a drawback of this system, however I don't think I've ever had more than 5 outposts of the one resource type going at any time. If I do find this to be an issue I could quite easily expand it :)
I use the following design rule: if an element is needed because of a new outpost, or new unloader, then the element needs to go into the outpost or unloader circuit, never into the depot. After the depot is built, that circuit is done and I'm not going to touch it anymore.

I want this for the simple reason that it makes expanding straightforward and less prone to errors. If adding an outpost potentially means to add a circuit to the depot, then not only does the player need to keep track of the number of outposts ("has my limit been reached?") but also, after setting up the outpost, needs to return all the way to the depot, to put down an additional circuit there, wire it up correctly, before the outpost can even work. It's too complicated for me :).
I learned things like data bus', using binary (and decoders), bit shift etc etc.
Using binary would be so much better if we did have bitwise operations (bitwise OR, AND, XOR). The only bitwise operation that's easy is "NOT", flipping all bits (multiply by -1 then subtract 1).
Looking back at my system now I can already see quite a few changes I want to make to optimise it, it will most likely be completely rebuilt in version 13 :) Really looking forward to the circuit network changes!
Yeah, it never ends. I need to set myself an upper limit for the number of combinators that I'm going to use, or I'll never stop adding features :).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Choumiko »

You're coming across just fine,no worries.
My thoughts/plans for your suggestions:
  • Train full/empty/no cargo change: sold
  • Next stop of the train, when it leaves: sold
  • Train is set to "auto-depart" or not: sold
  • Train will move to refuel. : Refuel is giving me a headache right now, since with setups like yours, Xeteths and the other freaks :D, it won't work if the station is added last in the schedule and the train never goes to the second last station or always uses goto X at that station. But for these advanced setups i think it's more or less trivial to add a few combinators to the depot station and check for the fuel value, replicating the auto refuel option in circuitry
siggboy wrote: If a piece of information is used by the mod to direct trains, then it should be accessible in the game-world, by the circuit logic, as well (as long as it makes sense at all). In other words, the circuit should -- at least in principle -- know everything that the smart train stop "knows".
Now I'd completely understand if you didn't want to go all the way with that, in order to keep the number of signals manageable and not to overcomplicate things. On the other hand, we already have some exotic signals (fuel value in MJ, train line number), and missing others that are more important (IMHO).
Maybe it would be easiest to add an advanced smart train stop that outputs all of these signals. Or even try to mash a second combinator in, one would only output the actual cargo, the other one would output those "meta signals"? Or a combination, or.. :D
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

Choumiko wrote:Train will move to refuel. : Refuel is giving me a headache right now, since with setups like yours, Xeteths and the other freaks :D, it won't work if the station is added last in the schedule and the train never goes to the second last station or always uses goto X at that station. But for these advanced setups i think it's more or less trivial to add a few combinators to the depot station and check for the fuel value, replicating the auto refuel option in circuitry
Yes, refuel is a non-issue with a central depot, because why wouldn't you just refuel at the depot if all the trains are passing through there anyway. I've already suspected that the SmartTrains refuel probably doesn't work in my setup, so never even tested if it does.

Also, I simply refuel my trains to the limit, coal or even solid fuel is not exactly Unobtainium in Factorio, so no harm is done by simply having the inserter shove it in mindlessly when it can.

The Refuel feature in SmartTrains is great if you do NOT have an advanced train scheduler, because it frees you of the pain of having to put refueling stations at every single unload. I think you should just leave the feature as it is, seems perfectly fine to me.

Please don't make it "override" the signal, just so it would then somehow work with dynamic scheduling. That would be a major pain point.
siggboy wrote:Maybe it would be easiest to add an advanced smart train stop that outputs all of these signals. Or even try to mash a second combinator in, one would only output the actual cargo, the other one would output those "meta signals"? Or a combination, or.. :D
Well, the "Logistic Combinator" mod by GopherAtl (soon to be obsolete), allows the player to set any number of "constants" in the combinator, but the combinator ignores the values, but uses it as a "filter". So the combinator only forwards the signals from the logistic network that have a corresponding signal in the combinator.

You could do something like this as well with SmartTrains, but to be honest, why would you? It's not a problem if the Smart Train Station outputs 10 or more signals. The list of signals would have to be come really long for this to become an issue.

I'd rather have one or two signals too many, than missing a signal that could be legitimately provided and would be needed to realize a feature.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Choumiko »

siggboy wrote:Please don't make it "override" the signal, just so it would then somehow work with dynamic scheduling. That would be a major pain point.
Yeah, i won't. Leaving refuel as is for now.
siggboy wrote:You could do something like this as well with SmartTrains, but to be honest, why would you? It's not a problem if the Smart Train Station outputs 10 or more signals. The list of signals would have to be come really long for this to become an issue.
I'm mostly thinking about performance, since right now, SmartTrains only checks full/empty etc.. if a train has it set as a rule. Making it available via combinator would require making the check regardless of the line/train has it actually set. I'll give it a try once 0.13 is out.

Sneaking in a prerelease (Back up your saves :) ) Readme (Tried it with Siggboys Demo V2, upgrading didn't seem to cause any issues)
Xeteth
Fast Inserter
Fast Inserter
Posts: 158
Joined: Tue Feb 17, 2015 6:06 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Xeteth »

Awesome! Thanks Choui!

I am trying to set it up on my world and I'm running into an issue with the station mapping GUI. It works fine for the first page of the mapping but when I scroll to the second page it comes up blank like this:

Image

I'll send you a PM with the map download so you can try it. Cheers!
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

Xeteth wrote:I'll send you a PM with the map download so you can try it. Cheers!
1.2 GB save file incoming kkthxbai!!1
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by Choumiko »

Xeteth wrote:I am trying to set it up on my world and I'm running into an issue with the station mapping GUI. It works fine for the first page of the mapping but when I scroll to the second page it comes up blank like this:
Fixed: https://github.com/Choumiko/SmartTrains ... ag/v0.3.92
siggboy wrote:1.2 GB save file incoming kkthxbai!!1
Only 2.3 MB, am a bit disappointed :D
nmid
Inserter
Inserter
Posts: 44
Joined: Tue Jul 08, 2014 9:21 pm
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by nmid »

The demo save is giving an error..
Unknown key:"Error while running the on_init: __actuator__/control.lua:30: Force already exists"

and the mod requirements seems to need base 0.12.4.
flabort
Inserter
Inserter
Posts: 25
Joined: Wed May 11, 2016 2:57 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by flabort »

I'm guessing by the fact that the OP was last edited today, and the DemoSave was apparently "not downloaded yet", the demo save has been updated and you should try the new version. :D
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: [MOD 0.12.30+] SmartTrains 0.3.82

Post by siggboy »

I have found a bug (that unfortunately screws over my scheduler big time :)):

Sometimes, when a train arrives at a Smart Station, then the combinator will output a Train=1 signal more than once.

It looks like it pulses the Train=1 signal once and then it will hold at Train=1 (as if the train arrives for 1 tick, immediately leaves, then arrives again; or as if the train stops twice). I could observe this in the game and also from the animation/sound that the train makes it appears as if it actually stops twice (or several times) at the station.

This behaviour makes my currect train detection method completely unreliable (because I wait for a single falling edge Train=1 > Train=0 and that means the train has left). Currently, because of this behaviour, the circuit is sometimes fooled into believing the train has left, because it sees the falling edge on the Train signal.

Sorry I cannot reliably reproduce it, it seems to be random (often it works fine, and then it doesn't). I've seen the behaviour on the demo map, too.

It was also there before the new version so I don't think it's something that got introduced with the new version (I've confirmed the bug with the current version, but saw the problem before on my demo map with the old version as well).

All my settings are at the default (12 ticks for checks etc., I haven't changed any of this because I want my scheduler to work with the defaults).

1. Can be get a bugfix for this?
2. Alternatively, if you implement the feature that actually outputs a (single) pulse when the train leaves, then this bug won't be a problem anymore because we could use the pulse directly and won't have to add an edge detection.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
Post Reply

Return to “Mods”