User Tools

Site Tools


usage:atlatc:examples:tis:digilines

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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/speed | Assumes a constant speed, which is often not the case when decelerating for a station |
 +| 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:
 +
 +<code>
 +Line 
 +In(very approximately)
 +x seconds
 +100 metres away
 +Of 4 carriages
 +</code>
 +
 +===== 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 = "1" -- Final channel for the message (defaults to 1)
 +
 +prefix = "seconds"
 +
 +-- DETECTION AND ACTING
 +if event.type == "train" then    
 +    -- CALCULATION
 +    time = distance/atc_speed -- Use our delicate formula to get time, in seconds. Of course, on approach, we will be slowing down.
 +    if time > 59 then
 +        time = time/60
 +        prefix = "minutes"  
 +    end
 +    
 +    -- OUTPUT
 +    message = get_line() .. "\n" .. "In (very approximately)\n" .. time .. " " .. prefix .. ",\n" .. distance .. " metres away" .. "\nOf " .. train_length() .. " carriages"
 +    digiline_send(channel, message) 
 +end
 +</code>
usage/atlatc/examples/tis/digilines.txt · Last modified: 2022-06-28 11:56 by 56independent