Using LTN
I'm trying to build a depot that handles trains of different lengths. And any train longer than 5 has more than one locomotive.
That means that some of the refueling inserters has to be disabeld/enabled depending on the lenght of the train.
I was certain that I could get the lenght for the refueling train from the train-stop but cant seem to figure out how....
Sorry if this is out there already. Failed to find an answer to this.
How do I obtain the lenght signal from a train?
Moderator: Optera
Re: How do I obtain the lenght signal from a train?
You want the "encoded position" signals produced by the constant combinator at the LTN stop. For example, the "Locomotive Encoded Position" signal. This is actually even better for your application, because it tells you exactly where in the train every locomotive is (as long as there are none past the 32nd rolling stock in the train).
The positions are encoded in a binary bitfield. The fuel inserter at each wagon position needs to check if its specific bit is a 1. You can do this with a single arithmetic combinator per inserter:
Arith. Comb.: "Encoded Locomotive Position" AND (&) Constant 2^N --> Signal A
Inserter: Enable if Signal A != 0
The first inserter on the track gets N=0. The inserter immediately behind it gets N=1, and so on. Each inserter will only turn on once LTN says there's a locomotive in that spot. You will also need to limit the stack size to 1, so that the inserters don't have extra fuel in their hand that could be accidentally dropped in a wagon.
The positions are encoded in a binary bitfield. The fuel inserter at each wagon position needs to check if its specific bit is a 1. You can do this with a single arithmetic combinator per inserter:
Arith. Comb.: "Encoded Locomotive Position" AND (&) Constant 2^N --> Signal A
Inserter: Enable if Signal A != 0
The first inserter on the track gets N=0. The inserter immediately behind it gets N=1, and so on. Each inserter will only turn on once LTN says there's a locomotive in that spot. You will also need to limit the stack size to 1, so that the inserters don't have extra fuel in their hand that could be accidentally dropped in a wagon.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Re: How do I obtain the lenght signal from a train?
Thanks for the reply!
I've been looking at the encoded position, but I'm having trouble realizing how to use it.
I'm adding it to the constant combinator I have added to the LTN-depot. But that only send the value I set it on. How do I make it read the refueling train.
Clearly Im missing something here....
I've been looking at the encoded position, but I'm having trouble realizing how to use it.
I'm adding it to the constant combinator I have added to the LTN-depot. But that only send the value I set it on. How do I make it read the refueling train.
Clearly Im missing something here....
Re: How do I obtain the lenght signal from a train?
"Your" constant combinator is hooked up to ltns lamp. The signal comes out of ltns constant combinator (directly next to the lamp)
Re: How do I obtain the lenght signal from a train?
Thanks! It took me a while to figure it out. Apparently your train need to be on auto for signals to be sent from the output combinator. but now I got !
Re: How do I obtain the lenght signal from a train?
This is a bad idea and usually ends up with fuel in cargo wagons. Here is why:
When a train arrives in the station you get the signal where the locomotive is and enable the fuel inserters. So they pick up a handful fuel and insert it. Now at some point the locomotive will be full and the inserter will be left with some fuel in their hand unable to insert it. The train leaves, the activation signal for the inserter goes away but the inserter remain posed over the rail waiting to drop their fuel. When the next train arrives they drop the fuel in the cargo wagon (assuming it has a locomotive at a different position).
To fix this you have 2 choices: 1) use only 1 inserter to insert fuel and override the stack size to 1. 2) have a filter inserter that removes extra fuel from the cargo wagon from the next train.
My recommendation is to always put locomotives at the same positions. Don't make the mistake of thinking locomotives have to be at the front of the train. They can be anywhere. You always start with 1 locomotive though because that cuts down on wind resistance. Then for example allow up to 4 cargo/fluid wagons. Position 6 then is a locomotive again. Then 4 more wagons and again a locomotive and so on. So you can have trains like this:
There are many patterns that will work as long as you never have a cargo wagon where another train has a locomotive. This allows you to have trains of different length and different number of locomotives while not having to worry about it. Just put fuel inserters everywhere a locomotive can be and they do the right thing.
When a train arrives in the station you get the signal where the locomotive is and enable the fuel inserters. So they pick up a handful fuel and insert it. Now at some point the locomotive will be full and the inserter will be left with some fuel in their hand unable to insert it. The train leaves, the activation signal for the inserter goes away but the inserter remain posed over the rail waiting to drop their fuel. When the next train arrives they drop the fuel in the cargo wagon (assuming it has a locomotive at a different position).
To fix this you have 2 choices: 1) use only 1 inserter to insert fuel and override the stack size to 1. 2) have a filter inserter that removes extra fuel from the cargo wagon from the next train.
My recommendation is to always put locomotives at the same positions. Don't make the mistake of thinking locomotives have to be at the front of the train. They can be anywhere. You always start with 1 locomotive though because that cuts down on wind resistance. Then for example allow up to 4 cargo/fluid wagons. Position 6 then is a locomotive again. Then 4 more wagons and again a locomotive and so on. So you can have trains like this:
Code: Select all
LC
LCC
LCCC
LCCCCL
LCCCCLCCCCL