...
Code Block | ||||
---|---|---|---|---|
| ||||
// // Dynamic controller for 11 trains // scchart DynamicController11 { // Set of request variables for all tracks for 11 trains bool IC_JCT_0_req[11], IC_LN_0_req[11], IC_LN_1_req[11], IC_LN_2_req[11]; bool IC_LN_3_req[11], IC_LN_4_req[11], IC_LN_5_req[11], IC_ST_0_req[11]; bool IC_ST_1_req[11], IC_ST_2_req[11], IC_ST_3_req[11], IC_ST_4_req[11]; bool IO_LN_0_req[11], IO_LN_1_req[11], IO_LN_2_req[11], KH_LN_0_req[11]; bool KH_LN_1_req[11], KH_LN_2_req[11], KH_LN_3_req[11], KH_LN_4_req[11]; bool KH_LN_5_req[11], KH_LN_6_req[11], KH_LN_7_req[11], KH_LN_8_req[11]; bool KH_ST_0_req[11], KH_ST_1_req[11], KH_ST_2_req[11], KH_ST_3_req[11]; bool KH_ST_4_req[11], KH_ST_5_req[11], KH_ST_6_req[11], KIO_LN_0_req[11]; bool KIO_LN_1_req[11], OC_JCT_0_req[11], OC_LN_0_req[11], OC_LN_1_req[11]; bool OC_LN_2_req[11], OC_LN_3_req[11], OC_LN_4_req[11], OC_LN_5_req[11]; bool OC_ST_0_req[11], OC_ST_1_req[11], OC_ST_2_req[11], OC_ST_3_req[11]; bool OC_ST_4_req[11], OI_LN_0_req[11], OI_LN_1_req[11], OI_LN_2_req[11]; bool req_in_R , req_out_R , req_in_L , req_out_L; // Set of permission variables for all tracks int IC_JCT_0_perm, IC_LN_0_perm, IC_LN_1_perm, IC_LN_2_perm; int IC_LN_3_perm, IC_LN_4_perm, IC_LN_5_perm, IC_ST_0_perm; int IC_ST_1_perm, IC_ST_2_perm, IC_ST_3_perm, IC_ST_4_perm; int IO_LN_0_perm, IO_LN_1_perm, IO_LN_2_perm, KH_LN_0_perm; int KH_LN_1_perm, KH_LN_2_perm, KH_LN_3_perm, KH_LN_4_perm; int KH_LN_5_perm, KH_LN_6_perm, KH_LN_7_perm, KH_LN_8_perm; int KH_ST_0_perm, KH_ST_1_perm, KH_ST_2_perm, KH_ST_3_perm; int KH_ST_4_perm, KH_ST_5_perm, KH_ST_6_perm, KIO_LN_0_perm; int KIO_LN_1_perm, OC_JCT_0_perm, OC_LN_0_perm, OC_LN_1_perm; int OC_LN_2_perm, OC_LN_3_perm, OC_LN_4_perm, OC_LN_5_perm; int OC_ST_0_perm, OC_ST_1_perm, OC_ST_2_perm, OC_ST_3_perm; int OC_ST_4_perm, OI_LN_0_perm, OI_LN_1_perm, OI_LN_2_perm; bool perm_in_R , perm_out_R , perm_in_L , perm_out_L; // Flags needed for stable cleanup function //---------------------------------------------------------------------------------------- // Flags for trains are ready and back at home bool trainDone[11]; // Flags for trains are on their home circle bool circle[11]; // Flag for trains 0 to 7 are back at home and trains 8 to 10 are on their home circle bool mainDone; // Flag for all trains are back at home bool allDone; //---------------------------------------------------------------------------------------- // Debug flag for additional output bool debug; // Cleanup flag for halting the trains at home station tracks bool cleanup; // Variable, that gives the number of trains to C-Controller for stability check int trainCount; // Constant needed for binding to referenced SCCharts const bool c_TRUE = true; // State initializing the trains on corresponding tracks initial state init references initRailway11Trains >-> run; // State handling the train schedules state run { // Region handling the cleanup function region Abort: initial state notDone // Transition when trains 0 to 7 are back at home and trains 8 to 10 are on their home circle --> mainDone with trainDone[0] & trainDone[1] & trainDone[2] & trainDone[3] & trainDone[4] & trainDone[5] & trainDone[6] & trainDone[7] & circle[8] & circle[9] & circle[10]; // State for allowing trains 8 to 10 to halt on the home track state mainDone --> quitCircle with / mainDone = true; // State waiting for trains 8 to 10 halt and setting flag for terminate the controller state quitCircle --> done with trainDone[8] & trainDone[9] & trainDone[10] / allDone = true; final state done; // Regions handling the mutual exclusion on the track segments region Mutexes: initial state Mutexes references mutexRailway11Trains // terminates with a strong abort when all trains are at home o-> done with allDone; final state done; region KH_Mutexes: initial state KH_Mutexes references kh_mutex // terminates with a strong abort when all trains are at home o-> done with allDone; final state done; // Regions that contain the dynamic schedules for trains 0 to 7 //-------------------------------------------------------------------------------------- // Region with the dynamic schedule for train 0 region Train0: initial state Train0 { @alterHostcode const int trainNum = 0 // Variable for saving the home track int homeTrack = 1; // Variable for saving the home station int homeStation = 1; // State referenced to dynamic scheduling initial state drive references DynamicSheduling // Binding circleDone to true for halting at home if cleanup is set bind circleDone to c_TRUE // Set a flag and a light for train at home >-> done with / 'railLight(10,1)'; trainDone[0] = true; final state done; } >-> done; final state done; // ... (other regions for trains 1 to 7 such as before) //-------------------------------------------------------------------------------------- // Regions that contain the dynamic schedules for trains 8 to 10 // Differences to regions above is that the trains 8 to 10 circle at home station circle // until trains 0 to 7 are back at home station and track // For this circleDone binds mainDone flag //-------------------------------------------------------------------------------------- // Region with the dynamic schedule for train 8 region Train8: initial state Train8 { @alterHostcode const int trainNum = 8 // Variable for saving the home track int homeTrack = 5; // Variable for saving the home station int homeStation = 1; // State referenced to dynamic scheduling initial state drive references DynamicSheduling // Binding circleDone to mainDone for halting at home only if cleanup is set // and trains 0 to 7 are at home and 8 to 10 on home circle bind circleDone to mainDone // Set a flag and a light for train at home >-> done with / 'railLight(6,1)'; trainDone[8] = true; final state done; } >-> done; final state done; // ... (other regions for trains 9 and 10 such as before) //-------------------------------------------------------------------------------------- } >-> flash; // State for flashing the lights at the end of the controller state flash --> done with / 'railFlashLight()'; final state done; } |
Dynamic Scheduling
Each train has the same dynamic scheduling. The basic idea are 4 station-states (KH, KHr, IC, OC). Each time a train is one of these states, the next target station is looked up. Depending on the current station there are 4 different travel paths available each leading into in of the 4 station-states. This way the dynamic scheduling can handle every possible schedule for each train.
In addition to the travel paths each station-state has a cleanup-transition. A train can only enter cleanup mode, when he arrived at his target station. Each train has a homestation and a hometrack, which he travels to once cleanup is started. Upon arriving at their hometrack, the train shuts down. Once every train is shut down, cleanup finished and every train is back at his starting position. Every station has one track, which does not allow the train, who wants to travel to that track, to shut down. These are KH_ST_5, IC_ST_1 and OC_ST_3. The trains traveling to these stations have to drive circles at KH_LN, IC_LN or OC_LN. Once these are the only trains driving, they are allowed to shut down too. This way a station can not block trains to drive through this station by shutting down all trains in that station.