In the initial state you wait for the outer detector for any of the lines to be triggered. When you detect a trigger, set that the signal for that line green, wait for the train to trigger the inner detector and then set the signal red again.
I'd suggest for the inner detector that you wait for it to be triggered, then wait until it's not detecting before releasing other trains. Indeed to be really safe, I'd prefer the second detector to be on the far side of the crossing, not before it.
Me too. Given the indeterminate speed and length of the trains, there
must be a detection of the crossing having been cleared. Then he'll have to consider a following train or a train coming from the opposite direction before allowing any crossing movements on the other railroad.
Before the outer detector can set the signal to green, he'll have to check that the crossing is clear and that no train on the other railroad is about to cross.
Coding wouldn't be too difficult, just loads of If statements