Include file <Coal_Basin_Control2.h>
Constructor : Coal_Basin_Control2 basinCntrl; no arguments
Public Methods: void begin( );
unsigned int return_request( );
void set_LEDs(unsigned int routes);
void fire_servos(unsigned int routes);
This project is part of a larger project to control points on a model train layout known as the Coal Basin. This is illustrated below:
This project takes as input the state of buttons (Program Coal_Basin_Buttons2), performs some logic to take into account the model train layout and then sets LEDs to display (Program Coal_Basin_LED2) to an operator the chosen routes and uses servo motors to set the points (Program Coal_Basin_Servo2) in the desired direction.
The photo shows the actual control panel where the Buttons and LEDs are mounted. As explained in the text pushing a button will select the chosen route that will also control the servos driving the points. The LEDs will highlight the chosen routes. There are two control panels, one either side of the coal basin that can select the chosen routes
The project will include a number of definitions that specify a numeric value for a number of operations. For example #define SILOS 1. These are included in a file Coal_Basin_States.h file that is included in both the Coal_Basin_Buttons2.h and Coal_Basin_LED2.h files that are included in this project so there is no need to included again. However, to aid reading the following text Coal_Basin_States.h is repeated below:
The final project at a high level consists of four operations:
Reading the operator select buttons on the control panel.
Performing some manipulation of the reading.
Turning on/off LEDs on the control panel to indicate what routes are active
Setting the points for the desired routes.
For this project the *.ino code will individually call routines in the *.cpp file rather than place everything in one function.
The header file is given below.
In summary the header file includes the Coal_Basin_Buttons2, Coal_Basin_LED2 and Coal_Basin_Servo2 files. These will give a number of operations that may be used. They also include the program definitions that will be required (see previous section).
The class defines 4 public methods begin(), return_request( ), setLEDS( ) and fireServos( ); that as their names suggest perform any initialization, read buttons, drive the LEDs and the Servos.
The *.ino file is given in the collapsible box below. Some features are:
Creating an object basinCntrl of the class Coal_Basin_Control.
Creating a variable routes that has the values of the of the chosen routes. Note more than one route can be active at the same time.
In the loop function the buttons are read and the values changed the new value is used to control the LEDs and Servos.
The function route_logic( ) that combines the current route with the requested routes. The function uses the definitions defined in the included files. In principle the logic says that if a request for one of the EASTSIDE routes this will not impact of the other routes.
For this project the heavy lifting is contained in the implementation file. Some features:
Creating objects for the button (2), the LED (1) and servos (up to 16). For the buttons the arguments are the pin connection. For the LEDs the wiring is fixed so there is no choice. For every Servo object the arguments are the wiring of the PCA9685 board and the timings.
The begin( ) function that call begin routines for each object
The fire_servos, setLEDs and return_request that are effectively a channels through to the included classes. With two control panels the return_request( ) choses between button1 and button2.
A explanation of some of the detail is given in the following section.
To enable a selected route the points must be set as per the following diagram (and photo)
The track layout. Selecting the Station will require settings points 1, 2, 4, 8 and 9.
In this photo all the points shown must be set to the left to reach the station.
Point selection for route to:
Silos: 1R
Wharf1: 1L, 2R, 3R
Wharf2: 1L 2R, 3L
Siding1: 1L, 2L, 4R, 5R, 6R
Siding2: 1L, 2L, 4R, 5R, 6L
Coal1: 1L, 2L, 4R, 5L, 7R
Coal2: 1L, 2L, 4R, 5L, 7L, 13R
Coal3: 1L, 2L, 4R, 5L, 7L, 13L
Yard: 1L, 2L, 4L, 8R
Station: 1L, 2L, 4L, 8L, 9L
Turntable: 9R
Basin: 10L
Eastside1: 10R, 11L
Eastside2: 10R, 11R, 12L
Eastside3: 10R, 11R, 12R
The code will be of the form if (routes & SILOS) { servo1.do_servo(RIGHT); } etc
Not shown in the original diagram is the control button/route Basin. An explanation:
Coming out of the tunnel there are two possibilities. The trains could move to the left (in the photo) to the area known as "Lower Eastland", Alternatively the train could go to over the viaduct to the "Coal Basin"
A design question here which track has priority? It was decided that Lower Eastside would be given priority and selecting one of the three routes to Lower Eastside would also select the point coming out of the tunnel. A separate button is then required to select the route to the Coal Basin.
Once in the basin the operators would need to select what routes the trains would take.
The hard work for this project was determining the wiring definitions for the buttons and the LEDs.
The major decisions in this project were determining the design logic. For example should selecting one of the EASTSIDE routes set point 10 RIGHT or should the basin buttons set point 10 LEFT? In practice all uses appeared to be relaxed with the chosen design where EASTSIDE had priority.
Some operators came from layouts that had buttons/switches to control each individual point. This would have completely changed the hardware, and software so was decision that needed to be made at the very start of the project. In the end most operators were completely relaxed with selecting the routes..
--------------------------------