Model Railroad System  2.2.2
Block Abstract Types (Classes)

This folder contains a collection of Tcl code to implement block occupancy detection, using various methods. At the very least, block detection results in signal aspect updates. Code for managing signals is in in the Signals folder.

There are two main ways to detect trains: using optical sensors or using current sensors. Optical sensors generally work via reflection (bouncing a light beam off the bottom of the train), although an across-the-tracks type is possible too. Current sensors work by sensing a current flow when a locomotive, lighted passenger car, or a freight car with resistors installed on its wheelsets passes onto an electrically isolated section of track. In any case, the sensor is connected to the computer somehow, either via USB or via a direct or indirect I/O bit or port.

Source Files

There are several Tcl source files in this directory. Each contains a SNIT Abstract data type (also known as a Class). This abstract data type encapsulates a single block. All of these abstract data types include a method named occupiedp, which returns a true or false result indicating whether or not the block is occupied. The constructor for these types include options or arguments that define the I/O device(s) that connect to whatever sensors are being used to detect block occupancy.

MRD2U Sensor (USB connected optical sensor)

MRD2_Block.tcl contains an abstract data type (MRD2_Block) that implements blocks using one Azatrax MRD2U Sensor for each block.

Circuits4Tracks Quad Occupancy Detector with a SR4 (USB connected I/O board)

C4TSR4_Block.tcl contains an abstract data type (C4TSR4_Block) that implements blocks using Circuits4Tracks Quad Occupancy Detectors connected to Azatrax SR4 modules using SSRs. One Circuits4Tracks Quad Occupancy Detector and one SR4 will handle 4 blocks.

Circuits4Tracks Quad Occupancy Detector connected to a C/MRI SMINI board

C4TSMINI_Block.tcl contains an abstract data type (C4TSMINI_Block) that implements blocks using Circuits4Tracks Quad Occupancy Detectors connected to input pins of a Bruce Chubb C/MRI Super Mini (SMINI) board. A Bruce Chubb C/MRI Super Mini (SMINI) board has enough inputs to handle a number of Circuits4Tracks Quad Occupancy Detectors.

Circuits4Tracks Quad Occupancy Detector connected to a CTI Train Brain

C4TTB_Block.tcl contains an abstract data type (C4TTB_Block) that implements blocks using Circuits4Tracks Quad Occupancy Detectors connected to the sensor inputs of a CTI Train Brain, Watchman, or Sentry board.Circuits4Tracks Quad Occupancy Detector connected to a

Common methods and functionality

All three types have a common structure. The constructors take the form:

typename objectname [optional options]

Eg:

MRD2_Block block2 -previousblock block1 -sensorsn 020001234 \
-forwardsignalobj signal2
Block occupation detection using Azatrax MRD2Us.
Definition: MRD2_Block.tcl:51

There are a pair of common options, -previousblock and -nextblock, which are the names of the previous block in the forward direction and the name of the previous block in the reverse direction. Another pair of common options, -forwardsignalobj and -reversesignalobj, are the names of signal objects. Also there is the option, -direction with sets the current operating direction for the block and can be forward or reverse. For blocks that only support traffic in one direction, use only the -previousblock and -forwardsignalobj options. The -direction defaults to forward. There are other object specific options that define how the sensor is accessed by the block object.

There are four common methods, two public and two private (the private methods should not be used by external code). The public methods are occupiedp and propagate. The occupiedp method returns a true or false (logical) value that indicates whether the block is occupied or not. The propagate method takes a signal aspect to 'propagate' to the previous block. The occupiedp method is typically called from the occupied command script associated with a piece of track work.

The two private methods, _entering and _exiting are used to implement special handling when entering or leaving a block. Presently, the _entering method sets the signal aspect and propagates signal aspects down to previous blocks and the _exiting method does nothing. These methods can be extended to add additional functionality, as needed.