Run TrainThing
Skipping down the list of things to-do to running TrainThing and graphics.
The diagram below show the direction of program control between modules. All modules uses constants and variables in module "Globals" and change those variables to reflect the state of the hardware and to control the process.
- Client
- Creates two asynchronous processes to send and receive commands and status from the micro-controllers embedded in the TrainThing Hardware.
- Status messages from the Arduino and Raspberry Pi reporting changes in sensors are passed to a process in module Globals to update the status of blocks of track and turnouts.
- Asynchronous messages from other modules are added to a buffer and then asynchronously send via a Wi-Fi connection to the Raspberry Pi (and then on to the Arduino).
- Globals
- Defines all system wide variables which describe the changing state of the software/hardware system.
- Defines constants used with system variables.
- Describes a function to adjust system variables based on messages received by the Client module.
- Defines a function to restart the TrainThing system.
- Layout
- Defines the elements necessary to display a schematic of the TrainThing hardware.
- Creates an asynchronous process to:
- Based on system variables adjust the display elements to reflect the state of the system.
- Monitor user controls to start/control/stop the software.
- Defines a function called by module Signals to change the graphical representation of each TrainThing signal.
- Defines a function called by module Trains to change the current paths being followed by each train.
- Signals
- Contains the requirements and logic to set each of the system 64 signals based on the state of blocks of track, turnouts and the crossover.
- Sends commands to the Raspberry Pi, through module Client, to set the physical signals.
- Calls module Layout to set the schematic signal state.
- Receives notice from modules Turnouts, and Trains when changes may affect signal aspect.
- Trains
- An asynchronous instance of module Trains is created for each train running in TrainThing.
- Each instance contains the logic to move a train from, the staging yard in the beginning, to its assigned path, follow its assigned path, and then back to the assigned parking spot in the staging yard based on the current state of the TrainThing System.
- Calls module Turnouts when turnouts are needed for the train to move from one block on its path to the next.
- Calls module Signals when the train moves from one block to another.
- Calls module Signals when the train requires the crossover to move from one block the next.
- TT4
- This top level module, initializes each of the other modules and creates an instance of module Trains for each of the trains running in the system.
- Sets global variables and sends commands to modules Signals and Turnouts to initialize the system.
- Monitors the state of each (1-4) train(s) changing the system state when appropriate.
- Turnouts
- Based on which blocks of track a train is moving between,
- Checks the current status of each required turnout.
- If a change is required, updates the global status of each turnout, passes the change to module Signals.
- Identifies the appropriate command to send to the Arduino through module Client to change 1-3 turnouts.
- When directed by module TT4, sets all 12 turnouts to the clear condition and informs module Signals of the change.