This shows you the differences between two versions of the page.
— |
usage:atlatc:examples:tis:digilines [2022-06-28 11:56] (current) 56independent created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Digilines Train Information System ====== | ||
+ | ===== Introduction ===== | ||
+ | Passengers would like to know information about approaching trains. This system gives information using digilines. | ||
+ | This is useful for stations with different, untimetabled services on platforms. The passangers know the time left until the next service. | ||
+ | |||
+ | ===== Explanation ===== | ||
+ | This code waits for a train to roll over the rail, and then calculates various variables: | ||
+ | |||
+ | ^ Variable ^ Calculation ^ Notes ^ | ||
+ | | Time left | Distance/ | ||
+ | | Time to minutes | time/60 | Only used when time left exceeds 59 seconds | | ||
+ | |||
+ | After all calculations are completed, the track then sends a digilines message with the information formatted: | ||
+ | |||
+ | < | ||
+ | Line | ||
+ | In(very approximately) | ||
+ | x seconds | ||
+ | 100 metres away | ||
+ | Of 4 carriages | ||
+ | </ | ||
+ | |||
+ | ===== Code ===== | ||
+ | <code lua> | ||
+ | -- Note: this code assumes a constant speed, which helps avoid complexity. The times will be shorter then the real time. | ||
+ | |||
+ | distance = 0 -- Whatever your distance is | ||
+ | stopping_lines = {} -- Give a list of lines that stop (empty for none) | ||
+ | channel = " | ||
+ | |||
+ | prefix = " | ||
+ | |||
+ | -- DETECTION AND ACTING | ||
+ | if event.type == " | ||
+ | -- CALCULATION | ||
+ | time = distance/ | ||
+ | if time > 59 then | ||
+ | time = time/60 | ||
+ | prefix = " | ||
+ | end | ||
+ | | ||
+ | -- OUTPUT | ||
+ | message = get_line() .. " | ||
+ | digiline_send(channel, | ||
+ | end | ||
+ | </ |