Changes for page Basic design

Last modified by nfl on 2025/01/30 12:05

From version 10.1
edited by sna
on 2014/08/06 03:46
Change comment: There is no comment for this version
To version 19.1
edited by sna
on 2014/08/20 23:21
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -34,7 +34,7 @@
34 34  
35 35  == Train controller ==
36 36  
37 -Each train controller is set in a separate region with a referenced state. This state has the following interface
37 +Each train controller is set in a separate region with a referenced state. This state has the following interface:
38 38  
39 39  
40 40  \\\\\\\\
... ... @@ -41,888 +41,696 @@
41 41  
42 42  {{{    input int *_perm;         # All permission variables (Tracks) input bool *_perm # KH permission variables   input int trainNum;    input bool cleanup; input bool debug; output bool *_req[]; # All request variables}}}
43 43  
44 -The train controller is composed of several //Station-2-Station// controllers. These are combined to form a complete schedule. Additionally the cleanup signal has to be watched to abort the schedule and return back to the initial position.
44 +The train controller is composed of several //Station-2-Station// controllers. These are combined to form a complete schedule. Additionally, the cleanup signal has to be watched to abort the schedule and return back to the initial position.
45 45  
46 -== Station-2-Station controller ==
47 -
48 -Each station-2-station controller realizes the movement from one of the stations (IC,OC,KH) to a second station. All controllers using IC or OC parts have to respect the traveling directions. For the Kicking Horse Pass two separate controllers, forwards and backwards, are used.
49 -
50 -The controllers starting from Kicking Horse Pass Station make an assumption of the direction of the train. These are dependent of the directions of the inner or outer circle, e.g. the KHIC controller starts backwards because this is the only valid direction to travel this path. To drive a train from the Kicking Horse Station (facing forward) to the Inner Circle we have to combine the KHOC and OCIC controllers.
51 -
52 -[[image:attach:ICIC.png]]
53 -
54 -When arriving on a station the train controller **must** first call the function //void railArrival(int train, int station)//. This starts the waiting timer for the train.
55 -Next the train **must** wait for// int railDeparture(int train)// to return 1.
56 -After the waiting has finished the controller can reach a final state and pass the control back to the train controller.
57 -
58 58  === Structure ===
59 59  
60 -----
48 +{{code linenumbers="true" language="sct"}}
49 +//
50 +// Structure of a train controller based on test case 2
51 +//
52 +scchart Test2 "Test of IC_JCT" {
53 +  // Set of request variables for all tracks for 11 trains
54 + bool IC_JCT_0_req[11], IC_LN_0_req[11], IC_LN_1_req[11], IC_LN_2_req[11];
55 + bool IC_LN_3_req[11], IC_LN_4_req[11], IC_LN_5_req[11], IC_ST_0_req[11];
56 + bool IC_ST_1_req[11], IC_ST_2_req[11], IC_ST_3_req[11], IC_ST_4_req[11];
57 + bool IO_LN_0_req[11], IO_LN_1_req[11], IO_LN_2_req[11], KH_LN_0_req[11];
58 + bool KH_LN_1_req[11], KH_LN_2_req[11], KH_LN_3_req[11], KH_LN_4_req[11];
59 + bool KH_LN_5_req[11], KH_LN_6_req[11], KH_LN_7_req[11], KH_LN_8_req[11];
60 + bool KH_ST_0_req[11], KH_ST_1_req[11], KH_ST_2_req[11], KH_ST_3_req[11];
61 + bool KH_ST_4_req[11], KH_ST_5_req[11], KH_ST_6_req[11], KIO_LN_0_req[11];
62 + bool KIO_LN_1_req[11], OC_JCT_0_req[11], OC_LN_0_req[11], OC_LN_1_req[11];
63 + bool OC_LN_2_req[11], OC_LN_3_req[11], OC_LN_4_req[11], OC_LN_5_req[11];
64 + bool OC_ST_0_req[11], OC_ST_1_req[11], OC_ST_2_req[11], OC_ST_3_req[11];
65 + bool OC_ST_4_req[11], OI_LN_0_req[11], OI_LN_1_req[11], OI_LN_2_req[11];
66 + bool req_in_R, req_out_R, req_in_L, req_out_L;
61 61  
68 +  // Set of permission variables for all tracks
69 + int IC_JCT_0_perm, IC_LN_0_perm, IC_LN_1_perm, IC_LN_2_perm;
70 + int IC_LN_3_perm, IC_LN_4_perm, IC_LN_5_perm, IC_ST_0_perm;
71 + int IC_ST_1_perm, IC_ST_2_perm, IC_ST_3_perm, IC_ST_4_perm;
72 + int IO_LN_0_perm, IO_LN_1_perm, IO_LN_2_perm, KH_LN_0_perm;
73 + int KH_LN_1_perm, KH_LN_2_perm, KH_LN_3_perm, KH_LN_4_perm;
74 + int KH_LN_5_perm, KH_LN_6_perm, KH_LN_7_perm, KH_LN_8_perm;
75 + int KH_ST_0_perm, KH_ST_1_perm, KH_ST_2_perm, KH_ST_3_perm;
76 + int KH_ST_4_perm, KH_ST_5_perm, KH_ST_6_perm, KIO_LN_0_perm;
77 + int KIO_LN_1_perm, OC_JCT_0_perm, OC_LN_0_perm, OC_LN_1_perm;
78 + int OC_LN_2_perm, OC_LN_3_perm, OC_LN_4_perm, OC_LN_5_perm;
79 + int OC_ST_0_perm, OC_ST_1_perm, OC_ST_2_perm, OC_ST_3_perm;
80 + int OC_ST_4_perm, OI_LN_0_perm, OI_LN_1_perm, OI_LN_2_perm;
81 +  bool perm_in_R, perm_out_R, perm_in_L, perm_out_L;
82 +
83 + // Debug flag for additional output
84 + bool debug = false;
85 + // Cleanup flag for halting the trains at home station tracks
86 +  bool cleanup = false;
87 +  // Variable, that gives the number of trains to C-Controller for stability check
88 + int trainCount;
89 +
90 + // Set of constants for binding to referenced SCCharts
91 + const int c_EINS = 1;
92 + const int c_ZWEI = 2;
93 + const int c_DREI = 3;
94 + const int c_VIER = 4;
95 + const int c_FUENF = 5;
96 +
97 + // State initializing the trains on corresponding tracks
98 + initial state init references initRailway11Trains
99 + --> run;
100 +
101 + // State handling the train schedules
102 + state run {
103 + // Regions handling the mutual exclusion on the track segments
104 + region Mutexes:
105 +  // State referenced to the MutexController for 11 Trains
106 + initial state Mutexes references mutexRailway11Trains;
107 +
108 + region KH_Mutexes:
109 +  // State referenced to additional MutexController for KH
110 + initial state KH_Mutexes references kh_mutex;
111 +
112 + // Regions that contain the schedules for individual trains
113 + //--------------------------------------------------------------------------------------
62 62  
63 -
115 + // Region with schedule for train 4
116 + region Train4 :
117 +  // State with the schedule for train 4
118 + initial state train4 {
119 +
120 + // Annotation for replacing following constant in the hostcode of referenced SCChart
121 + @alterHostcode
122 + // Number of the train for identifying on track segments
123 + const int trainNum = 4;
124 +  // Variable specifying the track, where the train arrives at,
125 + // and for transmitting the track number to next Station-2-Station controller
126 + int arrivalTrack = 3;
127 +
128 + // Schedule of train 4: train drives only in the IC, should use station track 3
129 + // State Round referenced to ICIC Station-2-Station controller
130 + initial state Round references ICIC
131 + bind depTrack to arrivalTrack,
132 + destTrack to c_DREI,
133 + arrTrack to arrivalTrack
134 +  // Transition to checking state
135 + >-> Choice;
136 +
137 + // State for checking, when the train should halt and if the train is on corresponding track
138 + state Choice
139 + // Transition for driving additional circle, if cleanup = false or wrong track used
140 + --> Round with !cleanup | !(arrivalTrack == 3)
141 + // Transition to final state
142 + --> Done;
143 +
144 + final state Done;
145 + };
64 64  
65 -|=(((
66 -{{{input int *_perm;}}}
67 67  
68 -{{{output bool *_req[11];}}}
148 + // Region with schedule for train 5, identical to region above
149 +  region Train5 :
150 + initial state train5 {
151 +
152 + @alterHostcode
153 + const int trainNum = 5;
154 + int arrivalTrack = 2;
155 +
156 + initial state Round references ICIC
157 + bind depTrack to arrivalTrack,
158 + destTrack to c_ZWEI,
159 + arrTrack to arrivalTrack
160 + >-> Choice;
161 +
162 + state Choice
163 + --> Round with !cleanup | !(arrivalTrack == 2)
164 + --> Done;
165 +
166 + final state Done;
167 +
168 + };
169 +
69 69  
70 -{{{input int trainNum;}}}
171 + // Region with schedule for train 9, identical to region above
172 + region Train9 :
173 + initial state train9 {
174 +
175 + @alterHostcode
176 + const int trainNum = 9;
177 + int arrivalTrack = 1;
178 +
179 + initial state Round references ICIC
180 + bind depTrack to arrivalTrack,
181 + destTrack to c_EINS,
182 + arrTrack to arrivalTrack
183 + >-> Choice;
184 +
185 + state Choice
186 + --> Round with !cleanup | !(arrivalTrack == 1)
187 + --> Done;
188 +
189 + final state Done;
190 + };
71 71  
72 -{{{input int depTrack;}}}
73 73  
74 -{{{input int destTrack;}}}
193 + // Region with schedule for train 7
194 + region Train7 :
195 + initial state train7 {
196 +
197 + @alterHostcode
198 + const int trainNum = 7;
199 + int arrivalTrack = 1;
200 +
201 + // Schedule of train 7: train drives from OC-Station track 1 to IC-Station track 2 and back
202 + // arrivalTrack used for transmitting the number of station track where train arrived on
203 + // to next controller where the train starts on
204 + initial state OCtoIC references OCIC
205 + bind depTrack to arrivalTrack,
206 + destTrack to c_ZWEI,
207 + arrTrack to arrivalTrack
208 +  // Transition to next Station-2-Station controller
209 + >-> ICtoOC;
210 +
211 + state ICtoOC references ICOC
212 + bind depTrack to arrivalTrack,
213 + destTrack to c_EINS,
214 + arrTrack to arrivalTrack
215 +  // Transition to checking state because train at home station
216 + >-> Choice;
217 +
218 + // State for checking, when the train should halt and if the train is on corresponding track
219 + state Choice
220 + // Transition for driving additional circle, if cleanup = false or wrong track used
221 +  --> OCtoIC with !cleanup | !(arrivalTrack == 1)
222 + // Transition to final state
223 + --> Done;
224 +
225 + final state Done;
226 + };
227 + };
228 +}
229 +{{/code}}
75 75  
76 -{{{input bool cleanup;}}}
77 -
78 -{{{input bool debug;}}}
79 -
80 -{{{output int arrTrack;}}}
81 -
82 -{{{int i_arrOnTrack;}}}
83 -
84 -{{{ }}}
85 -
86 -{{{initial state *_ST {}}}
87 -
88 -{{{    entry debug / 'println([trainNum][ST-ST] ... )';}}}
89 -
90 -{{{ }}}
91 -
92 -{{{    initial state waitForPerm {}}}
93 -
94 -{{{        entry / *_ST_4_req[trainNum] = true;}}}
95 -
96 -{{{        entry / *_LN_0_req[trainNum] = true;}}}
97 -
98 -{{{    }}}}
99 -
100 -{{{    --> gotPerm with (*_ST_4_perm == trainNum) & (*_LN_0_perm == trainNum)}}}
101 -
102 -{{{    --> backOff with (*_ST_4_perm == trainNum) | (*_LN_0_perm == trainNum);}}}
103 -
104 -{{{ }}}
105 -
106 -{{{    state backOff}}}
107 -
108 -{{{    --> backOff1;}}}
109 -
110 -{{{ }}}
111 -
112 -{{{    state backOff1 {}}}
113 -
114 -{{{entry / *_ST_4_req[trainNum] = false;}}}
115 -
116 -{{{entry / *_LN_0_req[trainNum] = false;}}}
117 -
118 -{{{    }}}}
119 -
120 -{{{    --> waitForPerm;}}}
121 -
122 -{{{ }}}
123 -
124 -{{{final state gotPerm;}}}
125 -
126 -{{{}}}}
127 -
128 -{{{>-> Dep_*_ST;}}}
129 -
130 -{{{ }}}
131 -
132 -{{{state Dep_IC_ST {}}}
133 -
134 -{{{    entry / 'railPoint(*,STRAIGHT)';}}}
135 -
136 -{{{    entry / 'railSignal(*_LN_0, FWD, RED)';}}}
137 -
138 -{{{    entry / 'railTrack(*_LN_0,FWD,trainNum,NORMAL)';}}}
139 -
140 -{{{    entry / 'railTrack(*_ST_4,FWD,trainNum,NORMAL)';}}}
141 -
142 -{{{    entry depTrack == 1 / 'railSignal(*_ST_1, FWD, GREEN)';}}}
143 -
144 -{{{    entry depTrack == 2 / 'railSignal(*_ST_2, FWD, GREEN)';}}}
145 -
146 -{{{    entry depTrack == 3 / 'railSignal(*_ST_3, FWD, GREEN)';}}}
147 -
148 -{{{    ..........}}}
149 -
150 -{{{  } --> *_LN_0 with 'railContact(*_LN_0,0)';}}}
151 -
152 -{{{ }}}
153 -
154 -{{{  state *_LN_0 {}}}
155 -
156 -{{{    entry / 'println("[trainNum][ST-ST] Entering *_LN_0")';}}}
157 -
158 -{{{    entry debug / 'println("[trainNum][ST-ST] Requesting permission for *_LN_1")';}}}
159 -
160 -{{{    entry depTrack == 1 / 'railSignal(*_ST_1, FWD, RED)';}}}
161 -
162 -{{{    entry depTrack == 2 / 'railSignal(*_ST_2, FWD, RED)';}}}
163 -
164 -{{{    entry depTrack == 3 / 'railSignal(*_ST_3, FWD, RED)';}}}
165 -
166 -{{{    entry / *_LN_1_req[trainNum] = true;}}}
167 -
168 -{{{ }}}
169 -
170 -{{{    region Travel:}}}
171 -
172 -{{{      initial state Entry}}}
173 -
174 -{{{      --> Continue with 'railContact(*_LN_0,0)' & (*_LN_1_perm == trainNum)}}}
175 -
176 -{{{      --> Slowdown with 'railContact(*_LN_0,0)';}}}
177 -
178 -{{{ }}}
179 -
180 -{{{      state Slowdown {}}}
181 -
182 -{{{        entry debug / 'println("[trainNum][ST-ST] Slowing down on *_LN_0")';}}}
183 -
184 -{{{        entry / 'railTrack(*_LN_0,FWD,trainNum,CAUTION)';}}}
185 -
186 -{{{      }}}}
187 -
188 -{{{      --> Waiting with 'railContact(*_LN_0,1)'}}}
189 -
190 -{{{      --> Continue with *_LN_1_perm == trainNum;}}}
191 -
192 -{{{ }}}
193 -
194 -{{{      state Waiting {}}}
195 -
196 -{{{        entry debug / 'println("[trainNum][ST-ST] Stopping on *_LN_0")';}}}
197 -
198 -{{{        entry / 'railTrackBrake(*_LN_0)';}}}
199 -
200 -{{{      }}}}
201 -
202 -{{{      --> Continue with *_LN_1_perm == trainNum;}}}
203 -
204 -{{{ }}}
205 -
206 -{{{      final state Continue {}}}
207 -
208 -{{{        entry debug / 'println("[trainNum][ST-ST] Continuing on *_LN_0")';}}}
209 -
210 -{{{        entry / 'railSignal(*_LN_0,FWD,GREEN)';}}}
211 -
212 -{{{        entry / 'railTrack(*_LN_0,FWD,trainNum,NORMAL)';}}}
213 -
214 -{{{        entry / 'railTrack(*_LN_1,FWD,trainNum,NORMAL)';}}}
215 -
216 -{{{        entry / 'railSignal(*_LN_1, FWD, RED)';}}}
217 -
218 -{{{      };}}}
219 -
220 -{{{ }}}
221 -
222 -{{{    region Cleanup:}}}
223 -
224 -{{{      initial state Entry}}}
225 -
226 -{{{      --> cleanup with 'railContact(*_LN_0,0)';}}}
227 -
228 -{{{ }}}
229 -
230 -{{{      final state cleanup {}}}
231 -
232 -{{{      entry debug / 'println("[trainNum][ST-ST] Entered *_LN_0 completely")';}}}
233 -
234 -{{{      entry / 'railTrackOff(*_ST_4)';}}}
235 -
236 -{{{      entry / *_ST_4_req[trainNum] = false;}}}
237 -
238 -{{{      };}}}
239 -
240 -{{{  }>-> *_LN_0_*_LN_1;}}}
241 -
242 -{{{ }}}
243 -
244 -{{{  state IC_LN_0_IC_LN_1}}}
245 -
246 -{{{  --> IC_LN_1 with 'railContact(IC_LN_1,0)';}}}
247 -
248 -{{{ }}}
249 -
250 -{{{// ...................}}}
251 -
252 -{{{// Set of track segment controlling states such as before}}}
253 -
254 -{{{// ...................}}}
255 -
256 -{{{ }}}
257 -
258 -{{{state *_LN_5 {}}}
259 -
260 -{{{    int perm_all_next_segments = false;}}}
261 -
262 -{{{    entry / 'println("[trainNum][ST-ST] Entering *_LN_5")';}}}
263 -
264 -{{{    entry / 'railSignal(*_LN_4, FWD, RED)';}}}
265 -
266 -{{{ }}}
267 -
268 -{{{    region Travel:}}}
269 -
270 -{{{      initial state Entry}}}
271 -
272 -{{{      --> Continue with 'railContact(*_LN_5,0)' & perm_all_next_segments}}}
273 -
274 -{{{      --> Slowdown with 'railContact(*_LN_5,0)';}}}
275 -
276 -{{{ }}}
277 -
278 -{{{      state Slowdown {}}}
279 -
280 -{{{        entry debug / 'println("[trainNum][ST-ST] Slowing down on *_LN_5")';}}}
281 -
282 -{{{        entry / 'railTrack(*_LN_5,FWD,trainNum,CAUTION)';}}}
283 -
284 -{{{      }}}}
285 -
286 -{{{      --> Waiting with 'railContact(*_LN_5,1)'}}}
287 -
288 -{{{      --> Continue with perm_all_next_segments;}}}
289 -
290 -{{{ }}}
291 -
292 -{{{      state Waiting {}}}
293 -
294 -{{{        entry debug / 'println("[trainNum][ST-ST] Stopping on *_LN_5")';}}}
295 -
296 -{{{        entry / 'railTrackBrake(*_LN_5)';}}}
297 -
298 -{{{      }}}}
299 -
300 -{{{      --> Continue with perm_all_next_segments;}}}
301 -
302 -{{{ }}}
303 -
304 -{{{      final state Continue {}}}
305 -
306 -{{{        entry debug / 'println("[trainNum][ST-ST] Continuing on *_LN_5")';        }}}
307 -
308 -{{{        entry i_arrOnTrack == 1 / 'railTrack(*_ST_1,FWD,trainNum,NORMAL)';}}}
309 -
310 -{{{        entry i_arrOnTrack == 2 / 'railTrack(*_ST_2,FWD,trainNum,NORMAL)';}}}
311 -
312 -{{{        entry i_arrOnTrack == 3 / 'railTrack(*_ST_3,FWD,trainNum,NORMAL)';}}}
313 -
314 -{{{        ----------}}}
315 -
316 -{{{        entry / arrTrack = i_arrOnTrack;}}}
317 -
318 -{{{      };}}}
319 -
320 -{{{ }}}
321 -
322 -{{{    region Cleanup:}}}
323 -
324 -{{{      initial state Entry}}}
325 -
326 -{{{      --> cleanup with 'railContact(*_LN_5,0)';}}}
327 -
328 -{{{ }}}
329 -
330 -{{{      final state cleanup {}}}
331 -
332 -{{{        entry debug / 'println("[trainNum][ST-ST] Entered *_LN_5 completely")';}}}
333 -
334 -{{{        entry / 'railTrackOff(*_LN_4)';}}}
335 -
336 -{{{        entry / *_LN_4_req[trainNum] = false;}}}
337 -
338 -{{{      };}}}
339 -
340 -{{{ }}}
341 -
342 -{{{    region Permissions:}}}
343 -
344 -{{{      initial state checking {}}}
345 -
346 -{{{        entry / *_ST_0_req[trainNum] = true;}}}
347 -
348 -{{{        entry destTrack == 1 | !cleanup / *_ST_1_req[trainNum] = true;}}}
349 -
350 -{{{        entry destTrack == 2 | !cleanup / *_ST_2_req[trainNum] = true;}}}
351 -
352 -{{{        entry destTrack == 3 | !cleanup / *_ST_3_req[trainNum] = true;}}}
353 -
354 -{{{      }}}}
355 -
356 -{{{      --> success with destTrack == 1 & *_ST_0_perm == trainNum & *_ST_1_perm == trainNum / i_arrOnTrack = 1}}}
357 -
358 -{{{      --> success with destTrack == 2 & *_ST_0_perm == trainNum & *_ST_2_perm == trainNum / i_arrOnTrack = 2}}}
359 -
360 -{{{      --> success with destTrack == 3 & *_ST_0_perm == trainNum & *_ST_3_perm == trainNum / i_arrOnTrack = 3}}}
361 -
362 -{{{      --> success with *_ST_0_perm == trainNum & *_ST_1_perm == trainNum / i_arrOnTrack = 1}}}
363 -
364 -{{{      --> success with *_ST_0_perm == trainNum & *_ST_2_perm == trainNum / i_arrOnTrack = 2}}}
365 -
366 -{{{      --> success with *_ST_0_perm == trainNum & *_ST_3_perm == trainNum / i_arrOnTrack = 3}}}
367 -
368 -{{{      --> resolving with *_ST_0_perm == trainNum | *_ST_3_perm == trainNum | *_ST_2_perm == trainNum | *_ST_1_perm == trainNum;}}}
369 -
370 -{{{ }}}
371 -
372 -{{{      state resolving}}}
373 -
374 -{{{      --> resolving1;}}}
375 -
376 -{{{ }}}
377 -
378 -{{{      state resolving1 {}}}
379 -
380 -{{{        entry / *_ST_0_req[trainNum] = false;}}}
381 -
382 -{{{        entry / *_ST_1_req[trainNum] = false;}}}
383 -
384 -{{{        entry / *_ST_2_req[trainNum] = false;}}}
385 -
386 -{{{        entry / *_ST_3_req[trainNum] = false;}}}
387 -
388 -{{{      }}}}
389 -
390 -{{{      --> checking;}}}
391 -
392 -{{{ }}}
393 -
394 -{{{      state success}}}
395 -
396 -{{{      --> success1;}}}
397 -
398 -{{{ }}}
399 -
400 -{{{      final state success1 {}}}
401 -
402 -{{{        entry !(i_arrOnTrack == 1) / *_ST_1_req[trainNum] = false;      }}}
403 -
404 -{{{        entry !(i_arrOnTrack == 2) / *_ST_2_req[trainNum] = false;}}}
405 -
406 -{{{        entry !(i_arrOnTrack == 3) / *_ST_3_req[trainNum] = false;}}}
407 -
408 -{{{        entry / perm_all_next_segments = true;}}}
409 -
410 -{{{      };}}}
411 -
412 -{{{  }>-> *_LN_5_*_ST;}}}
413 -
414 -{{{ }}}
415 -
416 -{{{  state *_LN_5_*_ST}}}
417 -
418 -{{{  --> Arr_*_ST with i_arrOnTrack == 1 & 'railContact(*_ST_1,0)'}}}
419 -
420 -{{{  --> Arr_*_ST with i_arrOnTrack == 2 & 'railContact(*_ST_2,0)'}}}
421 -
422 -{{{  --> Arr_*_ST with i_arrOnTrack == 3 & 'railContact(*_ST_3,0)';}}}
423 -
424 -{{{ }}}
425 -
426 -{{{  state Arr_*_ST {}}}
427 -
428 -{{{    entry / 'railSignal(*_LN_5, FWD, RED)';}}}
429 -
430 -{{{    entry / 'railTrackOff(*C_LN_5)';}}}
431 -
432 -{{{    entry / 'railTrack(*_ST_0,FWD,trainNum,SLOW)';}}}
433 -
434 -{{{    entry i_arrOnTrack == 1 / 'railTrack(*_ST_1,FWD,trainNum,SLOW)';}}}
435 -
436 -{{{    entry i_arrOnTrack == 2 / 'railTrack(*_ST_2,FWD,trainNum,SLOW)';}}}
437 -
438 -{{{    entry i_arrOnTrack == 3 / 'railTrack(*_ST_3,FWD,trainNum,SLOW)';}}}
439 -
440 -{{{    entry / *_LN_5_req[trainNum] = false;}}}
441 -
442 -{{{ }}}
443 -
444 -{{{    initial state SlowEntry}}}
445 -
446 -{{{    --> Slow with i_arrOnTrack == 1 & 'railContact(*_ST_1,0)'}}}
447 -
448 -{{{    --> Slow with i_arrOnTrack == 2 & 'railContact(*_ST_2,0)'}}}
449 -
450 -{{{    --> Slow with i_arrOnTrack == 3 & 'railContact(*_ST_3,0)';}}}
451 -
452 -{{{ }}}
453 -
454 -{{{    state Slow {}}}
455 -
456 -{{{      entry / 'railTrackOff(*_ST_0)';}}}
457 -
458 -{{{      entry / *_ST_0_req[trainNum] = false;}}}
459 -
460 -{{{    }}}}
461 -
462 -{{{    --> Halt with i_arrOnTrack == 1 & 'railContact(*_ST_1,1)'}}}
463 -
464 -{{{    --> Halt with i_arrOnTrack == 2 & 'railContact(*_ST_2,1)'}}}
465 -
466 -{{{    --> Halt with i_arrOnTrack == 3 & 'railContact(*_ST_3,1)';}}}
467 -
468 -{{{ }}}
469 -
470 -{{{    final state Halt {}}}
471 -
472 -{{{      entry i_arrOnTrack == 1 / 'railTrackBrake(*_ST_1)';}}}
473 -
474 -{{{      entry i_arrOnTrack == 2 / 'railTrackBrake(*_ST_2)';}}}
475 -
476 -{{{      entry i_arrOnTrack == 3 / 'railTrackBrake(*_ST_3)';}}}
477 -
478 -{{{      entry i_arrOnTrack == 1 / 'railArrival(trainNum, *_ST_1)';}}}
479 -
480 -{{{      entry i_arrOnTrack == 2 / 'railArrival(trainNum, *_ST_2)';}}}
481 -
482 -{{{      entry i_arrOnTrack == 3 / 'railArrival(trainNum, *_ST_3)';}}}
483 -
484 -{{{    };}}}
485 -
486 -{{{  }}}}
487 -
488 -{{{  >-> done;}}}
489 -
490 -{{{ }}}
491 -
492 -{{{  state done}}}
493 -
494 -{{{  --> reallyDone with 'railDeparture(trainNum)';}}}
495 -
496 -{{{ }}}
497 -
498 -{{{  final state reallyDone;}}}
499 -)))|=(((
500 -~/~/ All permissiions variables
501 -
502 -~/~/ All request variables
503 -
504 -~/~/ Train number
505 -
506 -~/~/ Departure track number
507 -
508 -~/~/ Destination track number
509 -
510 -~/~/ Cleanup flag for selecting the track of destination
511 -
512 -~/~/ Debug flag for additional output
513 -
514 -~/~/ Arrival track
515 -
516 -~/~/ Variable (arrival track) for selecting correct station elements
517 -
518 518  
519 519  
520 -~/~/ Handles departing from a station
233 +== Station-2-Station controller ==
521 521  
522 -~/~/ Additional output for debugging
235 +Each Station-2-Station controller realizes the movement from one of the stations (IC,OC,KH) to another station. All controllers using IC or OC parts have to respect the traveling directions. For the Kicking Horse Pass two separate controllers, forwards and backwards, are used.
523 523  
524 -
237 +The controllers starting from Kicking Horse Pass Station make an assumption of the direction of the train. These are dependent on the directions of the inner or outer circle, e.g. the KHIC controller starts backwards because this is the only valid direction to travel this path. To drive a train from the Kicking Horse Station (facing forward) to the Inner Circle we have to combine the KHOC and OCIC controllers.
525 525  
526 -~/~/ State, which set requests for needed tracks
239 +[[image:attach:ICIC.png]]
527 527  
528 -
241 +When arriving on a station the train controller **must** first call the function //void railArrival(int train, int station)//. This starts the waiting timer for the train.
242 +Next the train **must** wait for// int railDeparture(int train)// to return 1.
243 +After the waiting has finished the controller can reach a final state and pass the control back to the train controller.
529 529  
530 -
245 +=== Structure  ===
531 531  
532 -
247 +{{code linenumbers="true" language="sct"}}
248 +//
249 +// Structure of a Station-2-Station controller from Station * to Station *
250 +//
251 +scchart STST " * to * Controller " {
533 533  
534 -~/~/ Transition for received **all** needed permissions
253 + // Set of permission variables for required tracks
254 + input int *_perm;
535 535  
536 -~/~/ Tranisition for received **some** needed permissions
256 + // Set of request variables for required tracks for 11 trains
257 + output bool *_req[11];
537 537  
538 -
259 + // Train number
260 + input int trainNum;
539 539  
540 -~/~/ State for waiting an additional Tick
262 + // Number of the departure track in a station
263 + input int depTrack;
541 541  
542 -
265 + // Number of the destination track in a station
266 + input int destTrack;
543 543  
544 -
268 + // Cleanup flag for selecting the destination track
269 + input bool cleanup;
545 545  
546 -~/~/ State, which releases the requests for needed tracks
271 + // Debug flag for additional output
272 + input bool debug;
547 547  
548 -
274 + // Arrival track
275 + output int arrTrack;
549 549  
277 + // Variable with value for arrTrack for selecting correct station elements
278 + int i_arrOnTrack;
550 550  
551 -
280 + // Handles departing from a station *
281 + initial state *_ST {
282 + // hostcode call for additional output when debug
283 + entry debug / 'println([trainNum][ST-ST] ... )';
552 552  
553 -
554 -~/~/ Transition to trying the requesting again
555 -
285 + // State, which sets requests for needed tracks
286 + initial state waitForPerm {
287 + entry / *_ST_4_req[trainNum] = true;
288 + entry / *_LN_0_req[trainNum] = true;
289 + }
290 + // Transition is taken, if all permissions are received
291 + --> gotPerm with (*_ST_4_perm == trainNum) & (*_LN_0_perm == trainNum)
292 + // Transition is taken, if some (not all) permissions are received
293 + --> backOff with (*_ST_4_perm == trainNum) | (*_LN_0_perm == trainNum);
556 556  
557 -
295 + // State for waiting an additional tick when not all permissions are received
296 + state backOff
297 + --> backOff1;
558 558  
559 -
299 + // State, which releases the requests for needed tracks
300 + state backOff1 {
301 + entry / *_ST_4_req[trainNum] = false;
302 + entry / *_LN_0_req[trainNum] = false;
303 + }
304 + // Transition to repeat requesting permissions procedure
305 + --> waitForPerm;
560 560  
561 -
562 -~/~/ Transition to the departure state
563 -
307 + final state gotPerm;
308 + }
309 + // Transition to the departure state
310 + >-> Dep_*_ST;
564 564  
565 -
566 -~/~/ State, which handles the train departure
567 -
568 -~/~/ Set of entry-Actions to set tracks, points and signals according to depTrack
569 -
312 + // State, which handles the departure of a train
313 + state Dep_*_ST {
314 + // Set of entry-Actions with hostcode calls to set tracks, points and signals according to depTrack
315 + entry / 'railPoint(*,STRAIGHT)';
316 + entry / 'railSignal(*_LN_0, FWD, RED)';
317 + entry / 'railTrack(*_LN_0,FWD,trainNum,NORMAL)';
318 + entry / 'railTrack(*_ST_4,FWD,trainNum,NORMAL)';
319 + entry depTrack == 1 / 'railSignal(*_ST_1, FWD, GREEN)';
320 + entry depTrack == 2 / 'railSignal(*_ST_2, FWD, GREEN)';
321 + entry depTrack == 3 / 'railSignal(*_ST_3, FWD, GREEN)';
322 + //...
323 + // Transition to next track segment, if contact is triggered
324 + } --> *_LN_0 with 'railContact(*_LN_0,0)';
570 570  
571 571  
572 572  
328 + // ----------------------------------------------------------------------------------------------------------------
329 + // Set of track segment controlling states such as follows
330 + // ----------------------------------------------------------------------------------------------------------------
573 573  
574 -
332 + // Transition to next track segment, if contact is triggered
333 + state *_LN_0 {
334 + // Hostcode calls for outputs
335 + entry / 'println("[trainNum][ST-ST] Entering *_LN_0")';
336 + entry debug / 'println("[trainNum][ST-ST] Requesting permission for *_LN_1")';
337 + // Entry-Actions with hostcode calls to set previous signal according to depTrack to RED
338 + entry depTrack == 1 / 'railSignal(*_ST_1, FWD, RED)';
339 + entry depTrack == 2 / 'railSignal(*_ST_2, FWD, RED)';
340 + entry depTrack == 3 / 'railSignal(*_ST_3, FWD, RED)';
341 + // Requesting the next track segment
342 + entry / *_LN_1_req[trainNum] = true;
575 575  
576 -
344 + // Region for handling train driving
345 + region Travel:
346 + initial state Entry
347 + // Transition to continuing state, if permitted
348 + --> Continue with 'railContact(*_LN_0,0)' & (*_LN_1_perm == trainNum)
349 + // Transition to slowing down else
350 + --> Slowdown with 'railContact(*_LN_0,0)';
577 577  
578 -
352 + // State for slowing down the train
353 + state Slowdown {
354 + entry debug / 'println("[trainNum][ST-ST] Slowing down on *_LN_0")';
355 + // Entry-Action with hostcode calls for slowing down the train
356 + entry / 'railTrack(*_LN_0,FWD,trainNum,CAUTION)';
357 + }
358 + // Transition to waiting state
359 + --> Waiting with 'railContact(*_LN_0,1)'
360 + // Transition to continuing state, if permitted
361 + --> Continue with *_LN_1_perm == trainNum;
579 579  
580 -
363 + // State for train waiting on permission
364 + state Waiting {
365 + entry debug / 'println("[trainNum][ST-ST] Stopping on *_LN_0")';
366 + // Entry-Action with hostcode call for stopping the train
367 + entry / 'railTrackBrake(*_LN_0)';
368 + }
369 + --> Continue with *_LN_1_perm == trainNum;
581 581  
582 -
583 -~/~/ Transition to next track segment, if contact is readed
584 -
371 + // State to continuing driving on the track
372 + final state Continue {
373 + entry debug / 'println("[trainNum][ST-ST] Continuing on *_LN_0")';
374 + // Entry-Actions with hostcode calls to set tracks and signals for driving
375 + entry / 'railSignal(*_LN_0,FWD,GREEN)';
376 + entry / 'railTrack(*_LN_0,FWD,trainNum,NORMAL)';
377 + entry / 'railTrack(*_LN_1,FWD,trainNum,NORMAL)';
378 + entry / 'railSignal(*_LN_1, FWD, RED)';
379 + };
585 585  
586 -
587 -~/~/ State for handling the train on track *_LN_0
588 -
589 -~/~/ Outputs for debugging
590 -
381 + // Region for handling cleanup functionalities
382 + region Cleanup:
383 + initial state Entry
384 + // Transition to cleanup state
385 + --> cleanup with 'railContact(*_LN_0,0)';
591 591  
592 -
593 -~/~/ Entry-Actions to set the previous signals to RED
594 -
387 + // State for cleaning up the previous track segments
388 + final state cleanup {
389 + entry debug / 'println("[trainNum][ST-ST] Entered *_LN_0 completely")';
390 + // Entry-Action with hostcode call to switching off the previous track
391 + entry / 'railTrackOff(*_ST_4)';
392 + // Entry-Action to release the previous track
393 + entry / *_ST_4_req[trainNum] = false;
394 + };
395 + // Transition to transitional state
396 + }>-> *_LN_0_*_LN_1;
595 595  
596 -
398 + state *_LN_0_*_LN_1
399 + // Transition to next track segment, if contact is triggered
400 + --> *_LN_1 with 'railContact(*_LN_1,0)';
597 597  
402 + // ----------------------------------------------------------------------------------------------------------------
598 598  
599 -~/~/ Requesting the next segment
600 600  
601 -
602 602  
603 -~/~/ Region for handling train driving
604 -
406 + // State for entering a station
407 + state *_LN_5 {
408 + // Variable for checking all needed permissions
409 + int perm_all_next_segments = false;
410 + entry / 'println("[trainNum][ST-ST] Entering *_LN_5")';
411 + entry / 'railSignal(*_LN_4, FWD, RED)';
605 605  
606 -
607 -~/~/ Transition to continuing state, if permitted
608 -
609 -~/~/ Transition to slowing down else
610 -
413 + // Region for handling train driving such as above,
414 + // only with perm_all_next_segments for permitting more than one track
415 + region Travel:
416 + initial state Entry
417 + --> Continue with 'railContact(*_LN_5,0)' & perm_all_next_segments
418 + --> Slowdown with 'railContact(*_LN_5,0)';
611 611  
612 -
613 -~/~/ State for slowing down
614 -
615 -~/~/ Addtitional output for debugging
616 -
617 -~/~/ Entry-Action for slowing down the train
618 -
420 + state Slowdown {
421 + entry debug / 'println("[trainNum][ST-ST] Slowing down on *_LN_5")';
422 + entry / 'railTrack(*_LN_5,FWD,trainNum,CAUTION)';
423 + }
424 + --> Waiting with 'railContact(*_LN_5,1)'
425 + --> Continue with perm_all_next_segments;
619 619  
620 -
621 -~/~/ Transition to waiting state
622 -
623 -~/~/ Transition to continuing state, if permitted
624 -
427 + state Waiting {
428 + entry debug / 'println("[trainNum][ST-ST] Stopping on *_LN_5")';
429 + entry / 'railTrackBrake(*_LN_5)';
430 + }
431 + --> Continue with perm_all_next_segments;
625 625  
626 -
627 -~/~/ Waiting state
628 -
629 -~/~/ Addtitional output for debugging
630 -
631 -~/~/ Entry-Action for stopping the train
632 -
433 + final state Continue {
434 + entry debug / 'println("[trainNum][ST-ST] Continuing on *_LN_5")';
435 + entry i_arrOnTrack == 1 / 'railTrack(*_ST_1,FWD,trainNum,NORMAL)';
436 + entry i_arrOnTrack == 2 / 'railTrack(*_ST_2,FWD,trainNum,NORMAL)';
437 + entry i_arrOnTrack == 3 / 'railTrack(*_ST_3,FWD,trainNum,NORMAL)';
438 + //...
439 + entry / arrTrack = i_arrOnTrack;
440 + };
633 633  
634 -
635 -~/~/ Tranisition to continuing state
636 -
442 + // Region for handling cleanup-functionalities such as above
443 + region Cleanup:
444 + initial state Entry
445 + --> cleanup with 'railContact(*_LN_5,0)';
637 637  
638 -
639 -~/~/ State to continuing driving on the track
640 -
641 -~/~/ Addtitional output for debugging
642 -
643 -~/~/ Entry-Actions to set tracks and signals for driving
644 -
447 + final state cleanup {
448 + entry debug / 'println("[trainNum][ST-ST] Entered *_LN_5 completely")';
449 + entry / 'railTrackOff(*_LN_4)';
450 + entry / *_LN_4_req[trainNum] = false;
451 + };
645 645  
646 -
453 + // Region for handling permissions of all needed tracks
454 + region Permissions:
455 + // State for requesting all needed tracks according to destination track and cleanup-Flag
456 + initial state checking {
457 + entry / *_ST_0_req[trainNum] = true;
458 + entry destTrack == 1 | !cleanup / *_ST_1_req[trainNum] = true;
459 + entry destTrack == 2 | !cleanup / *_ST_2_req[trainNum] = true;
460 + entry destTrack == 3 | !cleanup / *_ST_3_req[trainNum] = true;
461 + }
462 + // Transitions for permitted tracks match wished tracks
463 + --> success with destTrack == 1 & *_ST_0_perm == trainNum & *_ST_1_perm == trainNum / i_arrOnTrack = 1
464 + --> success with destTrack == 2 & *_ST_0_perm == trainNum & *_ST_2_perm == trainNum / i_arrOnTrack = 2
465 + --> success with destTrack == 3 & *_ST_0_perm == trainNum & *_ST_3_perm == trainNum / i_arrOnTrack = 3
466 + // Transitions for permitted tracks don't match wished tracks
467 + --> success with *_ST_0_perm == trainNum & *_ST_1_perm == trainNum / i_arrOnTrack = 1
468 + --> success with *_ST_0_perm == trainNum & *_ST_2_perm == trainNum / i_arrOnTrack = 2
469 + --> success with *_ST_0_perm == trainNum & *_ST_3_perm == trainNum / i_arrOnTrack = 3
470 + // Transition for not all tracks permitted
471 + --> resolving with *_ST_0_perm == trainNum | *_ST_3_perm == trainNum | *_ST_2_perm == trainNum | *_ST_1_perm == trainNum;
647 647  
648 -
473 + // State for waiting an additional tick
474 + state resolving
475 + --> resolving1;
476 +
477 + // State for releasing track requests
478 + state resolving1 {
479 + entry / *_ST_0_req[trainNum] = false;
480 + entry / *_ST_1_req[trainNum] = false;
481 + entry / *_ST_2_req[trainNum] = false;
482 + entry / *_ST_3_req[trainNum] = false;
483 + }
484 + // Transition for trying the requesting again
485 + --> checking;
649 649  
487 + // State for waiting an additional tick
488 + state success
489 + --> success1;
650 650  
491 + // State for releasing not used track requests
492 + final state success1 {
493 + entry !(i_arrOnTrack == 1) / *_ST_1_req[trainNum] = false;
494 + entry !(i_arrOnTrack == 2) / *_ST_2_req[trainNum] = false;
495 + entry !(i_arrOnTrack == 3) / *_ST_3_req[trainNum] = false;
496 + // Settting perm_all_next_segments to true
497 + entry / perm_all_next_segments = true;
498 + };
499 + // Transition to station entry states
500 + }>-> *_LN_5_*_ST;
651 651  
652 -
502 + // State waiting for station entry
503 + state *_LN_5_*_ST
504 + --> Arr_*_ST with i_arrOnTrack == 1 & 'railContact(*_ST_1,0)'
505 +  --> Arr_*_ST with i_arrOnTrack == 2 & 'railContact(*_ST_2,0)'
506 + --> Arr_*_ST with i_arrOnTrack == 3 & 'railContact(*_ST_3,0)';
653 653  
654 -
655 -~/~/ Region for handling cleanup-functionalities
656 -
508 + // State for setting tracks, points and signals according to i_arrOnTrack
509 + // and releasing previous track request
510 + state Arr_*_ST {
511 + entry / 'railSignal(*_LN_5, FWD, RED)';
512 + entry / 'railTrackOff(*_LN_5)';
513 + entry / 'railTrack(*_ST_0,FWD,trainNum,SLOW)';
514 + entry i_arrOnTrack == 1 / 'railTrack(*_ST_1,FWD,trainNum,SLOW)';
515 + entry i_arrOnTrack == 2 / 'railTrack(*_ST_2,FWD,trainNum,SLOW)';
516 + entry i_arrOnTrack == 3 / 'railTrack(*_ST_3,FWD,trainNum,SLOW)';
517 + entry / *_LN_5_req[trainNum] = false;
657 657  
658 -
659 -~/~/ Transition to cleanup state
660 -
519 + initial state SlowEntry
520 + --> Slow with i_arrOnTrack == 1 & 'railContact(*_ST_1,0)'
521 + --> Slow with i_arrOnTrack == 2 & 'railContact(*_ST_2,0)'
522 + --> Slow with i_arrOnTrack == 3 & 'railContact(*_ST_3,0)';
661 661  
662 -
663 -~/~/ Cleanup state
664 -
665 -~/~/ Addtitional output for debugging
666 -
667 -~/~/ Entry-Action to switching off the previous track
668 -
669 -~/~/ Entry-Action to release the previous track
670 -
524 + // State for switching off previous track and releasing the request
525 + state Slow {
526 + entry / 'railTrackOff(*_ST_0)';
527 + entry / *_ST_0_req[trainNum] = false;
528 + }
529 + // Transitions to halt state, when train is at second contact of a track segment
530 + --> Halt with i_arrOnTrack == 1 & 'railContact(*_ST_1,1)'
531 + --> Halt with i_arrOnTrack == 2 & 'railContact(*_ST_2,1)'
532 + --> Halt with i_arrOnTrack == 3 & 'railContact(*_ST_3,1)';
671 671  
672 -
673 -~/~/ Transition to transitional state
674 -
534 +
535 + final state Halt {
536 + // Entry-Actions for braking the train on correct track
537 + entry i_arrOnTrack == 1 / 'railTrackBrake(*_ST_1)';
538 + entry i_arrOnTrack == 2 / 'railTrackBrake(*_ST_2)';
539 + entry i_arrOnTrack == 3 / 'railTrackBrake(*_ST_3)';
540 + // Entry-Actions for waiting for timer on correct track
541 + entry i_arrOnTrack == 1 / 'railArrival(trainNum, *_ST_1)';
542 + entry i_arrOnTrack == 2 / 'railArrival(trainNum, *_ST_2)';
543 + entry i_arrOnTrack == 3 / 'railArrival(trainNum, *_ST_3)';
544 + };
545 + }
546 + >-> done;
675 675  
676 -
677 -~/~/ Transitional state
678 -
679 -~/~/ Transition to next track segment, if contact is readed
680 -
548 + state done
549 + // Transition to final state, if timer is ready
550 + --> reallyDone with 'railDeparture(trainNum)';
681 681  
552 + final state reallyDone;
553 +}
554 +{{/code}}
682 682  
683 -
556 +== Dynamic Controller ==
684 684  
685 -
558 +The dynamic controller handles all 11 Trains. For each train the controller has a region with a referenced dynamic scheduling. Thereby each train can follow an arbitrary schedule. Additionally the controller has a region for stable cleanup function.
686 686  
687 -
560 +{{code linenumbers="true" language="sct"}}
561 +//
562 +// Dynamic controller for 11 trains
563 +//
564 +scchart DynamicController11 {
565 + // Set of request variables for all tracks for 11 trains
566 + bool IC_JCT_0_req[11], IC_LN_0_req[11], IC_LN_1_req[11], IC_LN_2_req[11];
567 + bool IC_LN_3_req[11], IC_LN_4_req[11], IC_LN_5_req[11], IC_ST_0_req[11];
568 + bool IC_ST_1_req[11], IC_ST_2_req[11], IC_ST_3_req[11], IC_ST_4_req[11];
569 + bool IO_LN_0_req[11], IO_LN_1_req[11], IO_LN_2_req[11], KH_LN_0_req[11];
570 + bool KH_LN_1_req[11], KH_LN_2_req[11], KH_LN_3_req[11], KH_LN_4_req[11];
571 + bool KH_LN_5_req[11], KH_LN_6_req[11], KH_LN_7_req[11], KH_LN_8_req[11];
572 + bool KH_ST_0_req[11], KH_ST_1_req[11], KH_ST_2_req[11], KH_ST_3_req[11];
573 + bool KH_ST_4_req[11], KH_ST_5_req[11], KH_ST_6_req[11], KIO_LN_0_req[11];
574 + bool KIO_LN_1_req[11], OC_JCT_0_req[11], OC_LN_0_req[11], OC_LN_1_req[11];
575 + bool OC_LN_2_req[11], OC_LN_3_req[11], OC_LN_4_req[11], OC_LN_5_req[11];
576 + bool OC_ST_0_req[11], OC_ST_1_req[11], OC_ST_2_req[11], OC_ST_3_req[11];
577 + bool OC_ST_4_req[11], OI_LN_0_req[11], OI_LN_1_req[11], OI_LN_2_req[11];
578 + bool req_in_R , req_out_R , req_in_L , req_out_L;
579 +  
580 + // Set of permission variables for all tracks
581 + int IC_JCT_0_perm, IC_LN_0_perm, IC_LN_1_perm, IC_LN_2_perm;
582 + int IC_LN_3_perm, IC_LN_4_perm, IC_LN_5_perm, IC_ST_0_perm;
583 + int IC_ST_1_perm, IC_ST_2_perm, IC_ST_3_perm, IC_ST_4_perm;
584 + int IO_LN_0_perm, IO_LN_1_perm, IO_LN_2_perm, KH_LN_0_perm;
585 + int KH_LN_1_perm, KH_LN_2_perm, KH_LN_3_perm, KH_LN_4_perm;
586 + int KH_LN_5_perm, KH_LN_6_perm, KH_LN_7_perm, KH_LN_8_perm;
587 + int KH_ST_0_perm, KH_ST_1_perm, KH_ST_2_perm, KH_ST_3_perm;
588 + int KH_ST_4_perm, KH_ST_5_perm, KH_ST_6_perm, KIO_LN_0_perm;
589 + int KIO_LN_1_perm, OC_JCT_0_perm, OC_LN_0_perm, OC_LN_1_perm;
590 + int OC_LN_2_perm, OC_LN_3_perm, OC_LN_4_perm, OC_LN_5_perm;
591 + int OC_ST_0_perm, OC_ST_1_perm, OC_ST_2_perm, OC_ST_3_perm;
592 + int OC_ST_4_perm, OI_LN_0_perm, OI_LN_1_perm, OI_LN_2_perm;
593 + bool perm_in_R , perm_out_R , perm_in_L , perm_out_L;
688 688  
689 -
595 + // Flags needed for stable cleanup function
596 + //----------------------------------------------------------------------------------------
597 + // Flags for trains are ready and back at home
598 + bool trainDone[11];
599 + // Flags for trains are on their home circle
600 + bool circle[11];
601 + // Flag for trains 0 to 7 are back at home and trains 8 to 10 are on their home circle
602 +  bool mainDone;
603 + // Flag for all trains are back at home
604 +  bool allDone;
605 + //----------------------------------------------------------------------------------------
690 690  
691 -~/~/ State for entering a station
607 + // Debug flag for additional output
608 +  bool debug;
609 + // Cleanup flag for halting the trains at home station tracks
610 +  bool cleanup;
611 + // Variable, that gives the number of trains to C-Controller for stability check
612 +  int trainCount;
613 + // Constant needed for binding to referenced SCCharts
614 + const bool c_TRUE = true;
692 692  
693 -~/~/ Variable for checking all needed permissions
694 -
695 -~/~/ Output
696 -
697 -~/~/ Setting signal to RED
698 -
699 699  
617 + // State initializing the trains on corresponding tracks
618 + initial state init references initRailway11Trains
619 + >-> run;
700 700  
701 -~/~/ Region for handling train driving
621 +
622 + // State handling the train schedules
623 +  state run {
702 702  
703 -
625 +  // Region handling the cleanup function
626 + region Abort:
627 + initial state notDone
628 +  // Transition when trains 0 to 7 are back at home and trains 8 to 10 are on their home circle
629 + --> mainDone with trainDone[0] & trainDone[1] & trainDone[2]
630 + & trainDone[3] & trainDone[4] & trainDone[5]
631 + & trainDone[6] & trainDone[7]
632 + & circle[8] & circle[9] & circle[10];
633 +
634 + // State for allowing trains 8 to 10 to halt on the home track
635 + state mainDone
636 + --> quitCircle with / mainDone = true;
637 +
638 + // State waiting for trains 8 to 10 halt and setting flag for terminate the controller
639 + state quitCircle
640 + --> done with trainDone[8] & trainDone[9] & trainDone[10] / allDone = true;
641 +
642 + final state done;
643 +
644 + // Regions handling the mutual exclusion on the track segments
645 + region Mutexes:
646 + initial state Mutexes references mutexRailway11Trains
647 + // terminates with a strong abort when all trains are at home
648 + o-> done with allDone;
649 +
650 + final state done;
651 +
652 + region KH_Mutexes:
653 + initial state KH_Mutexes references kh_mutex
654 +  // terminates with a strong abort when all trains are at home
655 + o-> done with allDone;
656 +
657 + final state done;
704 704  
705 -~/~/ Transition to continuing state, if permitted
706 -
707 -~/~/ Transition to slowing down else
708 -
659 + // Regions that contain the dynamic schedules for trains 0 to 7
660 + //--------------------------------------------------------------------------------------
709 709  
662 + // Region with the dynamic schedule for train 0
663 + region Train0:
664 + initial state Train0 {
665 + @alterHostcode
666 + const int trainNum = 0
667 +  // Variable for saving the home track
668 + int homeTrack = 1;
669 + // Variable for saving the home station
670 + int homeStation = 1;
671 +
672 + // State referenced to dynamic scheduling
673 + initial state drive
674 + references DynamicSheduling
675 +  // Binding circleDone to true for halting at home if cleanup is set
676 + bind circleDone to c_TRUE
677 +  // Set a flag and a light for train at home
678 + >-> done with / 'railLight(10,1)'; trainDone[0] = true;
679 +
680 + final state done;
681 + }
682 + >-> done;
683 +
684 + final state done;
710 710  
711 -~/~/ State for slowing down
686 + // ... (other regions for trains 1 to 7 such as before)
712 712  
713 -~/~/ Addtitional output for debugging
714 -
715 -~/~/ Entry-Action for slowing down the train
716 -
688 +  //--------------------------------------------------------------------------------------
717 717  
718 718  
719 -~/~/ Transition to waiting state
720 720  
721 -~/~/ Transition to continuing state, if permitted
722 722  
693 + // Regions that contain the dynamic schedules for trains 8 to 10
694 + // Differences to regions above is that the trains 8 to 10 circle at home station circle
695 + // until trains 0 to 7 are back at home station and track
696 + // For this circleDone binds mainDone flag
697 + //--------------------------------------------------------------------------------------
723 723  
699 + // Region with the dynamic schedule for train 8
700 + region Train8:
701 + initial state Train8 {
702 + @alterHostcode
703 + const int trainNum = 8
704 + // Variable for saving the home track
705 +  int homeTrack = 5;
706 + // Variable for saving the home station
707 + int homeStation = 1;
708 +
709 + // State referenced to dynamic scheduling
710 + initial state drive
711 + references DynamicSheduling
712 +  // Binding circleDone to mainDone for halting at home only if cleanup is set
713 + // and trains 0 to 7 are at home and 8 to 10 on home circle
714 + bind circleDone to mainDone
715 + // Set a flag and a light for train at home 
716 + >-> done with / 'railLight(6,1)'; trainDone[8] = true;
717 +
718 + final state done;
719 + }
720 + >-> done;
721 +
722 + final state done;
724 724  
725 -~/~/ Waiting state
724 + // ... (other regions for trains 9 and 10 such as before)
725 + //--------------------------------------------------------------------------------------
726 726  
727 -~/~/ Addtitional output for debugging
728 -
729 -~/~/ Entry-Action for stopping the train
730 -
731 -
732 -
733 -~/~/ Tranisition to continuing state
734 -
735 -
736 -
737 -~/~/ State to continuing driving on the track
738 -
739 -~/~/ Addtitional output for debugging
740 -
741 -~/~/ Set of entry-Actions for setting tracks, points and signals according to i_arrOnTrack
742 -
743 -
744 -
745 -
746 -
747 -
748 -
749 -~/~/ Setting the arrival track (output)
750 -
751 -
752 -
753 -
754 -
755 -~/~/ Region for handling cleanup-functionalities
756 -
757 -
758 -
759 -~/~/ Transition to cleanup state
760 -
761 -
762 -
763 -~/~/ Cleanup state
764 -
765 -~/~/ Addtitional output for debugging
766 -
767 -~/~/ Entry-Action to switching off the previous tracks
768 -
769 -~/~/ Entry-Action to release the previous tracks
770 -
771 -
772 -
773 -
774 -
775 -~/~/ Region for handling permissions of all needed tracks
776 -
777 -~/~/ State for requesting all needed tracks according to destination track and cleanup-Flag
778 -
779 -
780 -
781 -
782 -
783 -
784 -
785 -
786 -
787 -
788 -
789 -~/~/ Transitions for permitted tracks match wished tracks
790 -
791 -
792 -
793 -
794 -
795 -~/~/ Transitions for permitted tracks don't match wished tracks
796 -
797 -
798 -
799 -
800 -
801 -~/~/ Transition for not all tracks permitted
802 -
803 -
804 -
805 -~/~/ State for waiting an additional tick
806 -
807 -
808 -
809 -
810 -
811 -~/~/ State for releasing track requests
812 -
813 -
814 -
815 -
816 -
817 -
818 -
819 -
820 -
821 -
822 -
823 -~/~/ Transition for trying the requesting again
824 -
825 -
826 -
827 -~/~/ State for waiting an additional tick
828 -
829 -
830 -
831 -
832 -
833 -~/~/ State for releasing not used track requests and
834 -
835 -
836 -
837 -
838 -
839 -
840 -
841 -~/~/ Settting perm_all_next_segments to true
842 -
843 -
844 -
845 -~/~/ Transition to station entry states
846 -
847 -
848 -
849 -~/~/ State waiting for station entry
850 -
851 -
852 -
853 -
854 -
855 -
856 -
857 -
858 -
859 -~/~/ State for setting tracks, points and signals according to i_arrOnTrack
860 -
861 -~/~/ and releasing previous track request
862 -
863 -
864 -
865 -
866 -
867 -
868 -
869 -
870 -
871 -
872 -
873 -
874 -
875 -
876 -
877 -~/~/ State for slowing down, if train completely on track
878 -
879 -
880 -
881 -
882 -
883 -
884 -
885 -
886 -
887 -~/~/ State for switching off previous track and releasing the request
888 -
889 -
890 -
891 -
892 -
893 -
894 -
895 -~/~/ Transitions to halt states, if train at second contact of a track
896 -
897 -
898 -
899 -
900 -
901 -
902 -
903 -
904 -
905 -~/~/ Entry-Actions for braking the train on correct track
906 -
907 -
908 -
909 -
910 -
911 -~/~/ Entry-Actions for waiting for timer on correct track
912 -
913 -
914 -
915 -
916 -
917 -
918 -
919 -
920 -
921 -
922 -
923 -
924 -
925 -
926 -
927 -~/~/ Transition to final state, if timer is ready
928 -)))
727 + }
728 + >-> flash;
729 +
730 + // State for flashing the lights at the end of the controller
731 + state flash
732 + --> done with / 'railFlashLight()';
733 +
734 + final state done;
735 +}
736 +{{/code}}
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -9471639
1 +9471750
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/SS14Railway/pages/9471639/Basic design
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/SS14Railway/pages/9471750/Basic design