Request Stops


The following problem was posed in the online Rail3D group:

I’m modelling the line between Brig and Disentis (in Switzerland). Some of the smaller stations are request stops - ie trains only stop if there is a passenger waiting to board. In order that the driver knows if he has to stop or not, there is a signal before the station (actuated by the passenger operating a switch at the station) which tells the driver if a passenger wishes to board.
So how do I model this in Rail3D? Ie, have trains sometimes stop, sometimes not stop, and have the appropriate indication displayed on the signal as the train approaches. There are also express trains on the route which never stop at these stations.

This page describes one possible solution.

1 Sample layout

Download the sample layout packages from the Rail3D online group – they’re called “Request Stops” and “Request Stops revision”.

2 The Fakultativhaltsignale model

Since I know nothing of Swiss railway workings, I pursued the supplied link to http://web.utanet.at/smiderkr/asr/ensigchvers2.html for an idea of what the signal for a request stop (Fakultativhaltsignale) looks like.

I don’t have any photos to go by, so the model I made up will have to do. If anything the board might be a fraction too small.

I might point out that this model is essentially a distant signal. It stays unlit only for the Clear state (L.X) and shows two flashing white lights for anything worse than Clear.

3 The first solution

3.1 The test layout

To test the concept, I made a small layout with ~800m of straight, single track. There are three stations: West End, Centre, and East End. The layout has a single locomotive on it, running back and forth between West End and East End. I intend for the centre station to be the “by request only” station.

Below is a basic schematic diagram of the layout, showing the Request Stop signals before Centre. It also shows two hidden signals at Centre, the purpose of which will become clear later.

3.2 Trying the layout for yourself

When the layout opens, the loco should be just leaving West End. The script will give you some feedback via the debug window so you can see what’s going on. You can also open the signal panel “zcentre” to get an overview of the signals.

When the train leaves either West End or East End, the debug window should tell you whether the train will be required to stop at Centre. When a stop is required, the Request Stop signal will be showing two flashing white lights. When no stop is required, the Request Stop signal is unlit.

When the train is at either of the terminal stations, try changing the train’s route from “Local” to “Express”. You can also try setting the simulation time to somewhere between 11 pm and midnight.

3.3 To stop or not to stop?

So how is the decision to stop made?

As the train leaves West End it passes West End’s departure signal, which triggers the Rail3D signalling system to try to clear (hidden) signal 12 at Centre. This is where the script comes into play. It operates as follows:

  • Is the train an express train (i.e. route is “Express”)?
    • If so, allow signal 12 to clear.
  • Is the train already at the Centre platform?
    • If so, allow signal 12 to clear.
  • If the train is neither express nor already at the platform, then:
    • Assume that there’s a possibility the train might have to stop
    • Make a decision as to whether a stop is required
      • If train is then required to stop, prevent signal 12 from clearing.
      • If train is then not required to stop, allow signal 12 to clear.

3.4 The script

I began by making a signal panel of the entire layout, which looks pretty much like the diagram above. It wasn’t necessary to do the entire layout, but it was useful to see what was going on with the signals.

The intention is to have the hidden starting signal at Centre held at stop when we want to make the train stop. The Request Stop signal will then automatically act as a distant and show the appropriate aspect. To make the train stop properly at the station, we have Stop features at the platform, and the script will temporarily change the route of the train so that it stops.

I’ll go through the signal panel’s script in parts here (with debug lines and some comments removed):

	string sigid=Signal.GetID();
		return TRUE;

The above script ensures that we’re only dealing with Centre station by allowing any signals other than the signals at Centre to clear whenever they like.

	string route=Train.GetRoute();

	float Probability=0.5;
	int hr=Document.GetHour();
	int ForceStop=0;
	float x;
	int y=Document.GetSec();


The above script is the “random” passenger at the station. First we define a stopping probability: in this case it is 0.5, meaning that a train will stop there 50% of the time.

Next, we say there’s actually only a 20% chance of having to stop between 11 pm and midnight. You could also make this apply between midnight and 5 am (for example) if you were going to have passenger trains at that time.

Finally, in the absence of a random number generator, we use the seconds portion of the simulation time to introduce our ‘random’ factor of whether or not there’ll be passengers at the stop. However, be careful if you use a timetable, as the train might always arrive at the request only stop at the same time, which will cause the train to either always stop or always not stop.

	float d=Signal.GetDistance(Train);

		return TRUE;

The above script will clear the hidden starting signal if the train is express, because we don’t want it to stop. It’ll also clear the starting signal if any approaching train is within 100 metres of it, which means the train is in the platform already.

				return FALSE;
				return TRUE;
			return FALSE;

The above portion of script is executed when it is decided that there is chance that the train will stop. It then examines the ForceStop variable to see whether our random generator decided a stop was in order.

  • If a stop is required, the train’s route is changed to “Stopping” so that it will come to a stand at the platform for 15 seconds (as per the Stop feature there). When the stop is complete, the train requests a route from the starting signal as normal, and then the script will see that the train is within 100 m of the signal, and will allow it to proceed.
  • If no stop is required, the starting signal is allowed to clear.
	string sigid=Signal.GetID();
	string route=Train.GetRoute();


This final bit restores the train’s route back to “Local” once it has departed Centre.

3.5 Notes

  • There are a number of benefits of having the Request Stop signal as a distant. First, it acts by itself, so we don’t need to use scripts to make it show the required aspect. Secondly, it ensures that an approaching train sees the platform stop in time if it’s going to need it.
  • If you were modelling a single line, having intermediate stations with non-Locked Through signals like this could be a problem. You might consider having other precautions in place to prevent impasses.
  • I noticed while making this layout that the OnSignalCanClear() function is not called for any panel signal that is trying to set a route to a signal not covered by the panel. This was part of the reason for putting more of the layout on the panel than necessary. (Really only signals 4 and 12 needed to be on the panel.)

4 A revised solution

4.1 Problem with the first solution

One of the problems mentioned with the above solution is that having hidden home signals at the request station will mess around with the signalling if the station’s on a single line. This solution aims to avoid that problem.

4.2 The test layout

Open the second layout package “Request Stops 2.trp”. The main changes are:

  • the hidden home signals at Centre have been removed
  • the signal panel no longer has any control over the signals, but you can still use it to watch the signals
  • the Fakultativhaltsignale have been moved up to the ends of the platforms
  • the express route is now anything starting with “D”, and the stopping route is anything starting with “R”
  • the probability of a stopping train actually stopping at the station is set at 40%

The signal panel now looks like this:

The way this layout works is as follows.

  1. The stop features at Centre are set to catch all trains on route z*.
  2. There are speed limits set up at Centre to make all z* trains (and optionally all R* trains too) slow down to 25 km/h.
  3. When a train requests a route to the Fakultativhaltsignale, a script on the Fakultativhaltsignale itself makes all the decisions about whether or not the train stops.
  4. If the train is express (i.e. on route D*), the train is left as is, and the lamp (id = 1) on the Fakultativhaltsignale is set to rgb(0,0,0), which is off.
  5. If the train is not express (i.e. on route R*), the script calls on its ‘random’ factor again, which in this case is the simulation time, to decide whether to stop the train or not:
    • If it decides to let the train go, it’s treated like an express.
    • If it decides to stop the train, then the stopping sequence below is initiated.

The stopping sequence
When a train is to stop, the following happens:

  1. The train’s route has a z appended to the start, so a train on route R20 becomes zR20.
  2. The Fakultativhaltsignale is turned on with SetLamps().
  3. The train then becomes subject to the station speed limit, and also the Stop feature.
  4. The Fakultativhaltsignale “stop requested” aspect is cancelled when the train passes it.
  5. When the train stops at the station, its route name has the initial z* removed.

4.3 The script

The script in this layout is in two places. Each Fakultativhaltsignale has its own generic script, which is specific only with regards to the routes it selects for stopping/express, and also for the probability of stopping. There is also a short document script.

Fakultativhaltsignale script

This script is on each Fakultativhaltsignale itself.

	string r=Train.GetRoute();
	string ra=Left(r,1);
	string rn;
	int st=0;

	float Probability=0.4;
	int s=Document.GetSec();
	float z;

The above script declares the variables and gets some parameters like the train’s route and the probability of stopping.

		// potential stopping train

The above examines the first letter of the route to see what sort of train it is. If the train can potentially stop, and the ‘random’ decision is made to stop the train, the train has a z added to the start of its route name, and a stopping flag (st) is set.


	return TRUE;

This above part sets the Fakultativhaltsignale according to whether the train is stopping or not.


This final part turns the Fakultativhaltsignale off once the train has passed. I’m not sure if this is how it works in real life, but it seems a good enough approximation to me.

Document script

This is a small but necessary Document script.

	string Location;
	string r=Train.GetRoute();
	string ra=Left(r,1);
	int length=Len(r)-1;
	string rn;


If any train on route z* stops at Centre, it will have the initial z removed from its route name.

4.4 Notes

  • This revised solution of course applies only to the specific layout I’ve made. I’m not sure what would happen if you had multiple such stations in a single line section without any regular signals between. You might have to shift the location of the script - such as in an OnTrain() function on a repeater some distance before the each station.
  • Mark G is proposing a different solution, so there may well be more to this story yet!

David Morley (06 June 2008)