'##############
'Door Script
'##############

'Controls Doors

'(c) 2007-2009 Rüdiger Hülsmann
'(c) 2007-2012 Marcel Kuhnt
'(c) 2011 Markus Rabe
'(c) 09.11.2020 edited by Fourkane Mhoma (TheFMrr) for PDO Irisbus Citelis 12 (AddOn Saint-Servan)
'(c) 21.06.2022 [Citybus S31X] SADOP ltd, edited to fit outside opening doors, based on Kescrole's irisbus interurban scripts

'Script Version: 1.1
'Omsi release: 1.0

'Needs:
'- elec
'- actia
'- bremse
'- ramp
'- sprite cranberry

'NrSpecRandom Seed Area:
'301 ... 318

'Revision History:
'- Marcel Kuhnt   13.06.2009  Batterietrennschalter => elec_busbar_main
'- Marcel Kuhnt   21.06.2009  AI-Unterstützung hinzugefügt
'- Rüdiger Hülsmann 24.10.2009  Ansteuerung des Kinderwagenwunsches modifiziert
'- Rüdiger Hülsmann 19.12.2009  Timer für Ausstiegstür jetzt Timegap-basiert, Bugfix: Tür schließt jetzt nur bei elec_busbar=1
'- RÜdiger Hülsmann 22.09.2010  Door light trigger value set to 0.1
'- RÜdiger Hülsmann 07.11.2010  Door speed based on reservoir pressure, air-operated doors made an option
'- Marcel Kuhnt   08.11.2010  AI procedure closing doors debugged
'- Rüdiger Hülsmann 21.11.2010  Front doors only operable when busbar on
'- Rüdiger Hülsmann 23.12.2010  External front door operation included, option: doors only operable with actual stop brake
'- Rüdiger Hülsmann 31.12.2010  Electric door function debugged
'- Rüdiger Hülsmann 05.01.2011  20h-switch
'- Rüdiger Hülsmann 07.01.2011  Backdoor manual switch sound debugged, 20h switch depending on bus type
'- Rüdiger Hülsmann 19.01.2011  Electric door support
'- Markus Rabe    25.02.2011  D92 Schließverhalten der Hintertür und Einstiegsbeleuchtung ans Vorbild angepasst
'- Markus Rabe    27.02.2011  linker Flügel Vordertür: Abfangeinrichtung eingebaut
'- Marcel Kuhnt   29.06.2011  Integration in Standard-Doorscript
'- Marcel Kuhnt   07.07.2011  Druckluftsimulation inkl. Dämpfer
'- Marcel Kuhnt   09.07.2011  Manuelles Öffnen/Schließen
'- Marcel Kuhnt   10.07.2011  Manuelles Öffnen/Schließen optimiert
'- Marcel Kuhnt   10.07.2011  Mit westdeutscher Türsteuerung versehen und für O305 erweitert
'- Marcel Kuhnt   10.09.2011  Entriegelte Türen => Leuchtende Türlichter
'- Marcel Kuhnt   10.09.2011  Unterschiedliche Dämpfereinstellungen je Türflügel möglich
'- Marcel Kuhnt   09.07.2012  Anpassung an neue Busbar-Logik
'- Marcel Kuhnt   30.10.2012  Mausbewegungsrichtung beim manuellen Bewegen angepasst
'- Marcel Kuhnt   01.11.2012  Türentriegelung jetzt auch für E-Türen
'- Marcel Kuhnt   01.11.2012  E-Türen generieren Leitwert
'- Marcel Kuhnt   02.11.2012  Nach E-Türentriegelungsrücknahme verharren die Türen
'- Marcel Kuhnt   02.11.2012  Dreitürer
'- Marcel Kuhnt   04.11.2012  Türvariation fester Wagennummer zugeordnet
'- Marcel Kuhnt   04.11.2012  Türanforderung mit neuen Variablen
'- Rüdiger Hülsmann 18.11.2012  Zwangs-Haltestellenbremse durch Knickschutz
'- Marcel Kuhnt   16.12.2012  Haltewunsch-Abschaltung durch Vordertür konstantenabhängig
'- Marcel Kuhnt   08.01.2013  Je nach Konstante langsam aufbauender Druck erst nach Türtasterbetätigung nach Deaktivierung der Türentriegelung
'- Marcel Kuhnt   09.01.2013  20h-Schalter funktioniert jetzt auch in Verbindung mit SD-Hstbrems-Sperr-Logik
'- Marcel Kuhnt   09.01.2013  Türleuchten sind jetzt im Lights-Script
'- Marcel Kuhnt   09.01.2013  Außentürtaster nur bei eingelegter Haltestellenbremse wirksam
'- Marcel Kuhnt   09.01.2013  Reversierende Türen bei weggenommener Haltestellenbremse korrigiert
'- Marcel Kuhnt   12.01.2013  Außenelemente korrekt angesteuert (Hst-Schalter + Hst-Bremse)
'- Marcel Kuhnt   13.01.2013  Wagen-Hält-Zeichen erlischt bei Öffnen des rechten vorderen Türflügels mit 20h-Schalter
'- Marcel Kuhnt   14.01.2013  Türaußentaster werden auch von Fahrgästen benutzt
'- Rüdiger Hülsmann 28.10.2013  "needs stopbrake" function debugged
'- Rüdiger Hülsmann 29.10.2013  Keine Freigabe der Haltestellenbremse bei aktiviertem Kneeling
'- Fourkane Mhoma   09.11.2020  [PDO Citelis12] Improvements
'- Acrotere Design  30.11.2021  [Irisbus Citybus Family] added possibility to control the speed of each door half. DEV fixed. Changed into 2 doors script
'- SADOP ltd  21.06.2022  [Citybus S31X] edited to fit outside opening doors, based on Kescrole's irisbus interurban scripts

'--------------------------------------------------------------------------------

'####################
'    Front Doors
'####################

{trigger:bus_doorfront0}
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
  {if}
'   door0 (left)
    (L.L.doorTarget_0)
    (L.L.doorTarget_0) ! (L.L.Actia_BTN_door0_block) ! && ||
    {if}
      (M.L.trg_bus_doorfront0)
    {endif}
'   door 1 (right)
    (M.L.trg_bus_doorfront1)
  {endif}
  1 (S.L.cockpit_tuertaster1)
  (T.L.ev_dash_btn_mono_pushed)
{end}

{trigger:bus_doorfront0_off}
  0 (S.L.cockpit_tuertaster1)
  (T.L.ev_dash_btn_mono_released)
{end}

' > Emergency button ("nothahn")
{trigger:bus_doorfront0_lock}
  (L.L.door_opening_locked) !
  {if}
    1 (S.L.doorfront_emergency)
    (T.L.ev_doorfront_emergency_pushed)
  {endif}
{end}

' > "Tuersperre"
{trigger:bus_doorfront0_block}
  (L.L.Actia_BTN_door0_block) ! (S.L.Actia_BTN_door0_block)
  {if}
    (T.L.ev_dash_btn_pushed)
  {else}
    (L.L.doorTarget_1) (L.L.doorTarget_0) ! && (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > && {if} (M.L.trg_bus_doorfront0) {endif}
    (T.L.ev_dash_btn_released)
  {endif}
{end}

' > Opening from the outside
{trigger:bus_doorfront0_external}
  (L.L.elec_busbar_avail) (C.L.elec_busbar_minV) >
  {if}
    (L.L.doorfront_ext_opening_request_time) ! &&
    {if}
      (L.S.GetTime) (S.L.doorfront_ext_opening_request_time)
    {endif}
  {endif}
{end}

'####################
'     Mid Doors
'####################

{trigger:bus_doorfront1}
    (L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
    {if}
        (L.L.doorTarget_23) ! (L.L.door_SECU_off) ! && ||
        {if}
            (M.L.trg_bus_dooraft23)
        {endif}
    {endif}
    1 (S.L.cockpit_tuertaster2)
    (T.L.ev_dash_btn_mono_pushed)
{end}

{trigger:bus_doorfront1_off}
  0 (S.L.cockpit_tuertaster2)
  (T.L.ev_dash_btn_mono_pushed)
{end}

' > Emergency button ("nothahn")
{trigger:bus_doorfront1_lock}
  (L.L.door_opening_locked) !
  {if}
    1 (S.L.doorback23_emergency)
    (T.L.ev_doorback23_emergency_pushed)
  {endif}
{end}

' > DEV trigger
{trigger:bus_doorfront1_self}
  1 (S.L.PAX_Exit1_Req)
{end}

' > DEV allowed trigger (cockpit)
{trigger:CG_active}
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
  (L.L.bremse_halte) && (L.L.DEV) ! && (S.L.DEV)
  1 (S.L.Actia_BTN_doorall)
  (T.L.ev_Actia_BTN_mono_pushed)
{end}

{trigger:CG_active_off}
  0 (S.L.Actia_BTN_doorall)
  (T.L.ev_Actia_BTN_mono_released)
{end}

{trigger:bus_doorfront_all_close}
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
  {if}
    (L.L.doorfront_emergency) s0 (L.L.doorback23_emergency) s1 || (L.L.doorback45_emergency) s2 ||
    {if}
      l0 {if} 0 (S.L.doorfront_emergency) (T.L.ev_doorfront_unlock) {endif}
      l1 {if} 0 (S.L.doorback23_emergency) (T.L.ev_doorback_23_unlock) {endif}
      l2 {if} 0 (S.L.doorback45_emergency) (T.L.ev_doorback_45_unlock) {endif}
    {else}
      (L.L.doorTarget_0) {if} (M.L.trg_bus_doorfront0) {endif}
      (L.L.doorTarget_1) {if} (M.L.trg_bus_doorfront1) {endif}
      (L.L.doorTarget_23) {if} (M.L.trg_bus_dooraft23) {endif}
      (L.L.doorTarget_45) {if} (M.L.trg_bus_dooraft45) {endif}
    {endif}
    (T.L.ev_doors_compress)
  {endif}
  (T.L.ev_doorall_unlock)
  1 (S.L.Actia_BTN_rearm)
  (T.L.ev_Actia_BTN_misc_pushed)
{end}

{trigger:bus_doorfront_all_close_off}
  0 (S.L.Actia_BTN_rearm)
  (T.L.ev_Actia_BTN_misc_released)
{end}

' > Bremse halte
{trigger:bus_dooraft}
  (M.L.trg_bus_dooraft)
{end}

' > OMSI internal haltewunsch trigger
{trigger:int_haltewunsch}
  1 (S.L.haltewunsch)
{end}

' > DISABLED Command request
{trigger:cp_schalter_kinderwagen}
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
  {if}
    1 (S.L.door_DISABLED_Req)
  {endif}
{end}

{trigger:bus_SECU_off}
  (L.L.door_SECU_off) ! (S.L.door_SECU_off)
  {if}
    (T.L.ev_Actia_BTN_pushed)
  {else}
    (T.L.ev_Actia_BTN_released)
  {endif}
{end}

{trigger:door0_drag}
  (L.S.mouse_y) (L.S.mouse_x) - 5 / (S.L.doorDragAcc_0)
{end}

{trigger:door1_drag}
  (L.S.mouse_y) (L.S.mouse_x) + 5 / (S.L.doorDragAcc_1)
{end}

{trigger:door2_drag}
  (L.S.mouse_y) (L.S.mouse_x) - 5 / (S.L.doorDragAcc_2)
{end}

{trigger:door3_drag}
  (L.S.mouse_y) (L.S.mouse_x) + 5 / (S.L.doorDragAcc_3)
{end}

{trigger:door4_drag}
  (L.S.mouse_y) (L.S.mouse_x) - 5 / (S.L.doorDragAcc_4)
{end}

{trigger:door5_drag}
  (L.S.mouse_y) (L.S.mouse_x) + 5 / (S.L.doorDragAcc_5)
{end}

{macro:Door_Init}
  301 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_acc_var) * (C.L.ffdoor_acc) + (S.L.doorAcc_0)
  302 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_acc_var) * (C.L.fadoor_acc) + (S.L.doorAcc_1)
  303 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_acc_var) * (C.L.mfdoor_acc) + (S.L.doorAcc_2)
  304 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_acc_var) * (C.L.madoor_acc) + (S.L.doorAcc_3)
  305 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_acc_var) * (C.L.bfdoor_acc) + (S.L.doorAcc_4)
  306 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_acc_var) * (C.L.badoor_acc) + (S.L.doorAcc_5)

  307 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_maxspeed_var) * (C.L.ffdoor_maxspeed) + (S.L.doorMaxSpeed_0_norm)
  308 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_maxspeed_var) * (C.L.fadoor_maxspeed) + (S.L.doorMaxSpeed_1_norm)
  309 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_maxspeed_var) * (C.L.mfdoor_maxspeed) + (S.L.doorMaxSpeed_2_norm)
  310 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_maxspeed_var) * (C.L.madoor_maxspeed) + (S.L.doorMaxSpeed_3_norm)
  311 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_maxspeed_var) * (C.L.bfdoor_maxspeed) + (S.L.doorMaxSpeed_4_norm)
  312 (M.V.NrSpecRandom) 2 * 1 - (C.L.door_maxspeed_var) * (C.L.badoor_maxspeed) + (S.L.doorMaxSpeed_5_norm)

'Beim Dämpfer wird der Wert bis auf 40% reduziert statt eine Varianz verwendet:
  313 (M.V.NrSpecRandom) 0.9 * 0.1 + (C.L.door0_damper) * (S.L.doorDamper_0_kennwert)
  314 (M.V.NrSpecRandom) 0.9 * 0.1 + (C.L.door1_damper) * (S.L.doorDamper_1_kennwert)
  315 (M.V.NrSpecRandom) 0.9 * 0.1 + (C.L.door2_damper) * (S.L.doorDamper_2_kennwert)
  316 (M.V.NrSpecRandom) 0.9 * 0.1 + (C.L.door3_damper) * (S.L.doorDamper_3_kennwert)
  317 (M.V.NrSpecRandom) 0.9 * 0.1 + (C.L.door4_damper) * (S.L.doorDamper_4_kennwert)
  318 (M.V.NrSpecRandom) 0.9 * 0.1 + (C.L.door5_damper) * (S.L.doorDamper_5_kennwert)

  (C.L.door0_refl_opn) (S.L.doorRefl_0_opn)
  (C.L.door1_refl_opn) (S.L.doorRefl_1_opn)
  (C.L.door2_refl_opn) (S.L.doorRefl_2_opn)
  (C.L.door3_refl_opn) (S.L.doorRefl_3_opn)
  (C.L.door4_refl_opn) (S.L.doorRefl_4_opn)
  (C.L.door5_refl_opn) (S.L.doorRefl_5_opn)

  (C.L.door0_refl_cls) (S.L.doorRefl_0_cls)
  (C.L.door1_refl_cls) (S.L.doorRefl_1_cls)
  (C.L.door2_refl_cls) (S.L.doorRefl_2_cls)
  (C.L.door3_refl_cls) (S.L.doorRefl_3_cls)
  (C.L.door4_refl_cls) (S.L.doorRefl_4_cls)
  (C.L.door5_refl_cls) (S.L.doorRefl_5_cls)
	
  0 (S.L.door0_warten)
  0 (S.L.door0_umkehr)

  0 (S.L.door0_physblock)
  1 (S.L.door1_physblock)

  0
  (S.L.door_pressure_open_0)
  (S.L.door_pressure_close_0)
  (S.L.door_pressure_open_1)
  (S.L.door_pressure_close_1)
  (S.L.door_pressure_open_2)
  (S.L.door_pressure_close_2)
  (S.L.door_pressure_open_3)
  (S.L.door_pressure_close_3)
  (S.L.door_pressure_open_4)
  (S.L.door_pressure_close_4)
  (S.L.door_pressure_open_5)
  (S.L.door_pressure_close_5)

  (S.L.doorDamper_0) (S.L.doorDamper_1) (S.L.doorDamper_2) (S.L.doorDamper_3) (S.L.doorDamper_4) (S.L.doorDamper_5)
  2 (S.L.Actia_DoorCount)
{end}

{macro:Door_Frame}

  (M.L.Door0_Calc)
  (M.L.Door1_Calc)
  (M.L.Door2_Calc)
  (M.L.Door3_Calc)
  (M.L.Door4_Calc)
  (M.L.Door5_Calc)
  (M.L.DoorAftCalc)
  (M.L.DoorLockAtDeparture_Calc)

  0
  (S.L.doorDragAcc_0)
  (S.L.doorDragAcc_1)
  (S.L.doorDragAcc_2)
  (S.L.doorDragAcc_3)
  (S.L.doorDragAcc_4)
  (S.L.doorDragAcc_5)

' > PAX Entry
  (L.L.door_0) 0.8 > (S.L.PAX_Entry0_Open)
  (L.L.door_1) 0.8 > (S.L.PAX_Entry1_Open)
  (L.L.door_2) 0.8 > (S.L.PAX_Exit0_Open) (S.L.PAX_Exit1_Open)
  (L.L.door_3) 0.8 > (S.L.PAX_Exit1_Open)
  (L.L.door_4) 0.8 > (S.L.PAX_Exit2_Open) (S.L.PAX_Exit3_Open)
  (L.L.door_5) 0.8 > (S.L.PAX_Exit3_Open)


' > Swinging back doors
  (L.L.door_2) (F.L.door2_xposition) (S.L.door2_positionx)
  (L.L.door_2) (F.L.door2_yposition) (S.L.door2_positiony)
  (L.L.door_4) (F.L.door3_xposition) (S.L.door3_positionx)
  (L.L.door_4) (F.L.door3_yposition) (S.L.door3_positiony)

' > Door lights
  (L.L.door_0) (L.L.door_1) || (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > && (S.L.door_light_1)
  (L.L.door_2) (L.L.door_3) || (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > && (S.L.door_light_2)
  (L.L.door_4) (L.L.door_5) || (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > && (S.L.door_light_3)

' Setzen der Haltestellenbremse erst bei Stillstand des Busses:
  (L.L.bremse_halte_sw)
  (L.L.bremse_halte) ! (L.L.Velocity) (C.L.Door_Bremse_Halte_MaxKMH) < && &&
  {if}
    (L.L.elec_busbar_main) (C.L.elec_busbar_minV) >
    {if}
      (T.L.ev_haltebremse_an)
      1 (S.L.bremse_halte)
    {endif}
  {endif}

' Anhand dieser Bedingungen kann nun die Automatiktür geöffnet werden:
  (M.L.DEV_Calc)

' Haltewunsch + Haltewunschlampe:
  (L.L.haltewunsch)
  (L.L.door_2) 0.2 < (L.L.door_3) 0.2 < &&
  (L.L.door_4) 0.2 < (L.L.door_5) 0.2 < && && &&
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > &&
  {if}
    1 (S.L.haltewunschlampe)
  {else}
    0 (S.L.haltewunschlampe) (S.L.haltewunsch)
  {endif}

  (L.L.door_DISABLED_Req)
  (L.L.ramp_target) ! &&
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > &&
  {if}
    1 (S.L.haltewunschlampe_DISABLED)
  {else}
    0 (S.L.door_DISABLED_Req) (S.L.haltewunschlampe_DISABLED)
  {endif}

' Bing: (what?)
  (L.L.haltewunsch) (L.L.prev_haltewunsch) ! && (L.L.elec_busbar_main) (C.L.elec_busbar_minV) > &&
  {if}
    (T.L.ev_stop)
  {endif}

  (L.L.haltewunsch) (S.L.prev_haltewunsch)

' Beleuchtung der Einstiege

' Ausgelagert in Lights-Script




'###############################################################################################
' Druckluftverhalten:

  (C.L.door_druckluft)
  {if}
    (L.L.doorMaxSpeed_0_norm) (L.L.bremse_p_Tank01) 100000 - 750000 / * (S.L.doorMaxSpeed_0)
    (L.L.doorMaxSpeed_1_norm) (L.L.bremse_p_Tank01) 100000 - 850000 / * (S.L.doorMaxSpeed_1)
    (L.L.doorMaxSpeed_2_norm) (L.L.bremse_p_Tank02) 100000 - 800000 / * (S.L.doorMaxSpeed_2)
    (L.L.doorMaxSpeed_3_norm) (L.L.bremse_p_Tank02) 100000 - 900000 / * (S.L.doorMaxSpeed_3)
    (L.L.doorMaxSpeed_4_norm) (L.L.bremse_p_Tank02) 100000 - 800000 / * (S.L.doorMaxSpeed_4)
    (L.L.doorMaxSpeed_5_norm) (L.L.bremse_p_Tank02) 100000 - 900000 / * (S.L.doorMaxSpeed_5)
  {endif}

'-------------------------------------------------------------------

'###############################################################################################
' Gegenseitiges Blockieren der Türflügel:

' Die jeweilige Tür wird dadurch blockiert, dass ihr Öffnungsgrad kleiner ist als der des anderen Flügels ist, der selbst aber schon fast zu und nicht blockiert sein muss:

  (C.L.door_blocking)
  {if}

    (L.L.door0_physblock)
    {if}
      (L.L.door_0) (L.L.door_1) (C.L.door_blocking_diff) + < (L.L.door_1) (C.L.door_blocking_area) < && (L.L.door1_physblock) ! && (S.L.door0_physblock)
    {else}
      (L.L.door_0) (L.L.door_1) < (L.L.door_1) (C.L.door_blocking_area) < && (L.L.door1_physblock) ! && (S.L.door0_physblock)
    {endif}

    (L.L.door1_physblock)
    {if}
      (L.L.door_1) (L.L.door_0) (C.L.door_blocking_diff) + < (L.L.door_0) (C.L.door_blocking_area) < && (L.L.door0_physblock) ! && (S.L.door1_physblock)
    {else}
      (L.L.door_1) (L.L.door_0) < (L.L.door_0) (C.L.door_blocking_area) < && (L.L.door0_physblock) ! && (S.L.door1_physblock)
    {endif}
  {else}
    0 (S.L.door0_physblock) (S.L.door1_physblock)
  {endif}


'###############################################################################################
'###############################################################################################
' AI-Ablauf:

(L.L.AI_Scheduled_AtStation) s0
1 =
{if}
'Wenn Türen geöffnet werden sollen:
  (L.L.Velocity) (C.L.Door_Bremse_Halte_MaxKMH) <
  {if}
'Nur, wenn v < maxkmh, sonst warten
'Taster jeweils nur betätigen, falls noch nicht an
    (L.L.bremse_halte_sw) !
    {if}
      (M.L.trg_bus_dooraft)
    {endif}

    (L.L.door_AI_timer) 0.3 >
    {if}
      (L.L.doorTarget_0) ! {if} (M.L.trg_bus_doorfront0) {endif}
      (L.L.doorTarget_1) ! {if} (M.L.trg_bus_doorfront1) {endif}
      (L.L.haltewunsch) (L.L.PAX_Exit0_Req) (L.L.PAX_Exit1_Req) || && (L.L.doorTarget_23) ! {if} (M.L.trg_bus_dooraft23) {endif}
      (L.L.haltewunsch) (L.L.PAX_Exit2_Req) (L.L.PAX_Exit3_Req) || && (L.L.doorTarget_45) ! {if} (M.L.trg_bus_dooraft23) {endif}
    {endif}

  {else}
    0 (S.L.door_AI_timer)
  {endif}
  (L.L.door_AI_timer) (L.S.Timegap) + (S.L.door_AI_timer)
{else}
l0 -1 =
{if}
'Wenn Türen geschlossen werden sollen:
'Taster jeweils nur betätigen, falls noch nicht aus:

  (L.L.doorTarget_0)  {if} (M.L.trg_bus_doorfront0) {endif}
  (L.L.doorTarget_1)  {if} (M.L.trg_bus_doorfront1) {endif}
  (L.L.doorTarget_23) {if} (M.L.trg_bus_dooraft23) {endif}
  (L.L.doorTarget_45) {if} (M.L.trg_bus_dooraft23) {endif}

'Haltestellenbremse erst wegnehmen, wenn alle Türen zu. Dann auch erst den Bus AI-mäßig freigeben:
  (L.L.door_0) 0.1 <
  (L.L.door_1) 0.1 < &&
  (L.L.door_2) 0.1 < &&
  (L.L.door_3) 0.1 < &&
  (L.L.door_4) 0.1 < &&
  (L.L.door_5) 0.1 < &&
  {if}
    (L.L.bremse_halte_sw) (L.L.door_AI_timer) 0.5 > &&
    {if}
      (M.L.trg_bus_dooraft)
    {endif}
    (L.L.bremse_halte_sw) !
    {if}
      0 (S.L.AI_Scheduled_AtStation)
    {endif}
  {else}
'Sollte eine der Türen auf sein und die Haltestellenbremse aus, dann sofort diese einlegen
    (L.L.bremse_halte_sw) !
    {if}
      (M.L.trg_bus_dooraft)
    {endif}
    (L.L.doorTarget_0) !
    (L.L.doorTarget_1) ! &&
    (L.L.doorTarget_23) ! &&
    (L.L.doorTarget_45) ! &&
    {if}
      0 (S.L.door_AI_timer)
    {endif}
  {endif}

  (L.L.door_AI_timer) (L.S.Timegap) + (S.L.door_AI_timer)
{endif}
{endif}


{end}

'###############################################################################################
' Door Calc Türenpaar 1
'###############################################################################################


{macro:Door0_Calc}
	(L.L.doorTarget_0) (L.L.door0_pos_z) 1 < &&
	{if}
		(L.L.door0_pos_z) (C.L.door0_pos_z_speed) 5 / (L.S.Timegap) * + 1 min (S.L.door0_pos_z)
	{else}
		(C.L.electric_doors)
		{if}

			(C.L.ffdoor_acc) (S.L.doorAcc_0)

			(L.L.doorTarget_0) ! (L.L.doorSpeed_0) s0 abs 0.05 > (L.L.door_0) 0 > || && 
			{if}
				l0 /-/ (L.L.doorMaxSpeed_0) <
				{if}
					(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * - (S.L.doorSpeed_0)
				{else}
					(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * + (S.L.doorSpeed_0)
				{endif}
				(L.L.door_0) (L.L.doorSpeed_0) (L.S.Timegap) * + (S.L.door_0)
			{else}
				(L.L.doorSpeed_0) abs 0.05 > (L.L.door_0) 1 < || (L.L.doorTarget_0) &&
				{if}
					l0 (L.L.doorMaxSpeed_0) <
					{if}
						(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * + (S.L.doorSpeed_0) 
					{else}
						(L.L.doorSpeed_0) (L.L.doorAcc_0) (L.S.Timegap) * - (S.L.doorSpeed_0) 
					{endif}
					(L.L.door_0) (L.L.doorSpeed_0) (L.S.Timegap) * + (S.L.door_0)
				{else}
					0 (S.L.doorSpeed_0)
				{endif}
			{endif}
		{endif}
	{endif}


	(L.L.door_0) 1 >
	{if}
		(T.L.ev_doorhitopen_0)
		1 (S.L.door_0)
		(L.L.doorSpeed_0) /-/ (L.L.doorRefl_0_opn) * (S.L.doorSpeed_0)
	{else}
		(L.L.door_0) 0 <
		{if}
			(T.L.ev_doorhitclose_0)
			0 (S.L.door_0)
			(L.L.doorSpeed_0) /-/ (L.L.doorRefl_0_cls) * (S.L.doorSpeed_0)
		{endif}
	{endif}

' Open front door from outside
	(L.L.doorfront_ext_opening_request_time) s0
	{if}
		(L.S.GetTime) l0 - 1.5 >=
		{if}
			(L.L.doorTarget_1) ! (L.L.doorTarget_0) &&
			{if}
				(M.L.trg_bus_doorfront0)
			{else}
			(L.L.doorTarget_1) (L.L.doorTarget_0) ! &&
			{if}
				(M.L.trg_bus_doorfront1)
			{else}
				(M.L.trg_bus_doorfront0)
				(M.L.trg_bus_doorfront1)
			{endif}
			{endif}
			0 (S.L.doorfront_ext_opening_request_time)
		{endif}
	{endif}
	
	(L.L.doorTarget_0) !
	(L.L.door0_pos_z) 0 > &&
	(L.L.door_0) 0.05 < &&
	{if}
	(L.L.door0_pos_z) (C.L.door0_pos_z_speed_up) 5 / (L.S.Timegap) * - 0 max (S.L.door0_pos_z)
	{endif}
{end}

{macro:Door1_Calc}
	(L.L.doorTarget_1) (L.L.door1_pos_z) 1 < &&
	{if}
		(L.L.door1_pos_z) (C.L.door1_pos_z_speed) 5 / (L.S.Timegap) * + 1 min (S.L.door1_pos_z)
	{else}
		(C.L.electric_doors)
		{if}

			(C.L.fadoor_acc) (S.L.doorAcc_1)

			(L.L.doorTarget_1) ! (L.L.doorSpeed_1) s0 abs 0.05 > (L.L.door_1) 0 > || &&
			{if}
				l0 /-/ (L.L.doorMaxSpeed_1) <
				{if}
					(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * - (S.L.doorSpeed_1)
				{else}
					(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * + (S.L.doorSpeed_1)
				{endif}
				(L.L.door_1) (L.L.doorSpeed_1) (L.S.Timegap) * + (S.L.door_1)
			{else}
				(L.L.doorSpeed_1) abs 0.05 > (L.L.door_1) 1 < || (L.L.doorTarget_1) &&
				{if}
					l0 (L.L.doorMaxSpeed_1) <
					{if}
						(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * + (S.L.doorSpeed_1) 
					{else}
						(L.L.doorSpeed_1) (L.L.doorAcc_1) (L.S.Timegap) * - (S.L.doorSpeed_1) 
					{endif}
					(L.L.door_1) (L.L.doorSpeed_1) (L.S.Timegap) * + (S.L.door_1)
				{else}
					0 (S.L.doorSpeed_1)
				{endif}
			{endif}
		{endif}
	{endif}
	
	(L.L.door_1) (F.L.door_inc_dblFrontD) (S.L.door_0_inc_dblFront_scd)

	(L.L.door_1) 1 >
	{if}
		(T.L.ev_doorhitopen_1)
		1 (S.L.door_1)
		(L.L.doorSpeed_1) /-/ (L.L.doorRefl_1_opn) * (S.L.doorSpeed_1)
	{else}
		(L.L.door_1) 0 <
		{if}
			(T.L.ev_doorhitclose_1)
			0 (S.L.door_1)
			(L.L.doorSpeed_1) /-/ (L.L.doorRefl_1_cls) * (S.L.doorSpeed_1)
		{endif}
	{endif}

	(L.L.doorTarget_1) !
	(L.L.door1_pos_z) 0 > &&
	(L.L.door_1) 0.05 < &&
	{if}
	(L.L.door1_pos_z) (C.L.door1_pos_z_speed_up) 5 / (L.S.Timegap) * - 0 max (S.L.door1_pos_z)
	{endif}
{end}

'###############################################################################################
' Hintertürautomatiken
'###############################################################################################

{macro:DEV_Calc}

  (L.L.DEV)
  {if}

'   > Doors 2-3
    (L.L.PAX_Exit0_Req) (L.L.PAX_Exit1_Req) ||
    {if}
      (L.L.doorTarget_23) !
      {if}
        (M.L.trg_bus_dooraft23)
      {endif}
      0 (S.L.doorMidLastOpen)
    {else}
      (L.L.doorTarget_23)
      (L.L.doorMidLastOpen) (C.L.doorMidOpenTime) > &&
      {if}
        (M.L.trg_bus_dooraft23)
      {endif}
    {endif}

'   > Doors 4-5
    (L.L.PAX_Exit2_Req) (L.L.PAX_Exit3_Req) ||
    {if}
      (L.L.doorTarget_45) !
      {if}
        (M.L.trg_bus_dooraft45)
      {endif}
      0 (S.L.doorAftLastOpen)
    {else}
      (L.L.doorTarget_45)
      (L.L.doorAftLastOpen) (C.L.doorAftOpenTime) > &&
      {if}
        (M.L.trg_bus_dooraft45)
      {endif}
    {endif}

    (L.L.door_2) 1 = (L.L.door_2) 1 = ||
    {if}
      (L.L.doorMidLastOpen) (L.S.Timegap) + {else} 0
    {endif}
    (S.L.DoorMidLastOpen)

    (L.L.door_4) 1 = (L.L.door_5) 1 = ||
    {if}
      (L.L.doorAftLastOpen) (L.S.Timegap) + {else} 0
    {endif}
    (S.L.DoorAftLastOpen)

  {else}
    0 (S.L.doorMidLastOpen) (S.L.doorAftLastOpen)
  {endif}

{end}

'###############################################################################################
' BREMSE HALTE CALC
'###############################################################################################

{macro:DoorAftCalc}

  (L.L.bremse_halte_sw) !
  (L.L.DEBUG_Kneel) ! &&
  (L.L.ramp_target) ! &&
  (L.L.door_2) ! &&
  (L.L.door_3) ! &&
  (L.L.door_4) ! &&
  (L.L.door_5) ! &&
  (L.L.elec_busbar_main) (C.L.elec_busbar_minV) <= s0 ||
  (L.L.bremse_halte) &&
  l0 ! (L.L.throttle) 0.1 > && &&
  {if}
    0 (S.L.DEV) (S.L.bremse_halte)
    (T.L.ev_haltebremse_aus)
  {endif}

{end}

'###############################################################################################
' Door Calc Türenpaar 2
'###############################################################################################

{macro:Door2_Calc}
	(L.L.doorTarget_23) (L.L.door2_pos_z) 1 < &&
	{if}
		(L.L.door2_pos_z) (C.L.door2_pos_z_speed) 5 / (L.S.Timegap) * + 1 min (S.L.door2_pos_z)
	{else}
		(C.L.electric_doors)
		{if}

			(C.L.mfdoor_acc) (S.L.doorAcc_2)

			(L.L.doorTarget_23) ! (L.L.doorSpeed_2) s0 abs 0.05 > (L.L.door_2) 0 > || && 
			{if}
				l0 /-/ (L.L.doorMaxSpeed_2) <
				{if}
					(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * - (S.L.doorSpeed_2)
				{else}
					(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * + (S.L.doorSpeed_2)
				{endif}
				(L.L.door_2) (L.L.doorSpeed_2) (L.S.Timegap) * + (S.L.door_2)
			{else}
				(L.L.doorSpeed_2) abs 0.05 > (L.L.door_2) 1 < || (L.L.doorTarget_23) &&
				{if}
					l0 (L.L.doorMaxSpeed_2) <
					{if}
						(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * + (S.L.doorSpeed_2) 
					{else}
						(L.L.doorSpeed_2) (L.L.doorAcc_2) (L.S.Timegap) * - (S.L.doorSpeed_2) 
					{endif}
					(L.L.door_2) (L.L.doorSpeed_2) (L.S.Timegap) * + (S.L.door_2)
				{else}
					0 (S.L.doorSpeed_2)
				{endif}
			{endif}
		{endif}
	{endif}
	
	(L.L.door_2) (F.L.door_inc_dblRearG) (S.L.door_1_inc_dblRear)

	(L.L.door_2) 1 >
	{if}
		(T.L.ev_doorhitopen_2)
		1 (S.L.door_2)
		(L.L.doorSpeed_2) /-/ (L.L.doorRefl_2_opn) * (S.L.doorSpeed_2)
	{else}
		(L.L.door_2) 0 <
		{if}
			(T.L.ev_doorhitclose_2)
			0 (S.L.door_2)
			(L.L.doorSpeed_2) /-/ (L.L.doorRefl_2_cls) * (S.L.doorSpeed_2)
		{endif}
	{endif}

	(L.L.doorTarget_23) !
	(L.L.door2_pos_z) 0 > &&
	(L.L.door_2) 0.05 < &&
	{if}
	(L.L.door2_pos_z) (C.L.door2_pos_z_speed_up) 5 / (L.S.Timegap) * - 0 max (S.L.door2_pos_z)
	{endif}
{end}

{macro:Door3_Calc}
	(L.L.doorTarget_23) (L.L.door3_pos_z) 1 < &&
	{if}
		(L.L.door3_pos_z) (C.L.door3_pos_z_speed) 5 / (L.S.Timegap) * + 1 min (S.L.door3_pos_z)
	{else}
		(C.L.electric_doors)
		{if}

			(C.L.madoor_acc) (S.L.doorAcc_3)

			(L.L.doorTarget_23) ! (L.L.doorSpeed_3) s0 abs 0.05 > (L.L.door_3) 0 > || && 
			{if}
				l0 /-/ (L.L.doorMaxSpeed_3) <
				{if}
					(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * - (S.L.doorSpeed_3)
				{else}
					(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * + (S.L.doorSpeed_3)
				{endif}
				(L.L.door_3) (L.L.doorSpeed_3) (L.S.Timegap) * + (S.L.door_3)
			{else}
				(L.L.doorSpeed_3) abs 0.05 > (L.L.door_3) 1 < || (L.L.doorTarget_23) &&
				{if}
					l0 (L.L.doorMaxSpeed_3) <
					{if}
						(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * + (S.L.doorSpeed_3) 
					{else}
						(L.L.doorSpeed_3) (L.L.doorAcc_3) (L.S.Timegap) * - (S.L.doorSpeed_3) 
					{endif}
					(L.L.door_3) (L.L.doorSpeed_3) (L.S.Timegap) * + (S.L.door_3)
				{else}
					0 (S.L.doorSpeed_3)
				{endif}
			{endif}
		{endif}
	{endif}
	
	(L.L.door_3) (F.L.door_inc_dblRearD) (S.L.door_1_inc_dblRear_scd)

	(L.L.door_3) 1 >
	{if}
		(T.L.ev_doorhitopen_3)
		1 (S.L.door_3)
		(L.L.doorSpeed_3) /-/ (L.L.doorRefl_3_opn) * (S.L.doorSpeed_3)
	{else}
		(L.L.door_3) 0 <
		{if}
			(T.L.ev_doorhitclose_3)
			0 (S.L.door_3)
			(L.L.doorSpeed_3) /-/ (L.L.doorRefl_3_cls) * (S.L.doorSpeed_3)
		{endif}
	{endif}

	(L.L.doorTarget_23) !
	(L.L.door3_pos_z) 0 > &&
	(L.L.door_3) 0.05 < &&
	{if}
	(L.L.door3_pos_z) (C.L.door3_pos_z_speed_up) 5 / (L.S.Timegap) * - 0 max (S.L.door3_pos_z)
	{endif}
{end}

'###############################################################################################
' Door Calc Türenpaar 3
'###############################################################################################

{macro:Door4_Calc}
	(L.L.doorTarget_45) (L.L.door4_pos_z) 1 < &&
	{if}
		(L.L.door4_pos_z) (C.L.door4_pos_z_speed) 5 / (L.S.Timegap) * + 1 min (S.L.door4_pos_z)
	{else}
		(C.L.electric_doors)
		{if}

			(C.L.madoor_acc) (S.L.doorAcc_4)

			(L.L.doorTarget_45) ! (L.L.doorSpeed_4) s0 abs 0.05 > (L.L.door_4) 0 > || && 
			{if}
				l0 /-/ (L.L.doorMaxSpeed_4) <
				{if}
					(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * - (S.L.doorSpeed_4)
				{else}
					(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * + (S.L.doorSpeed_4)
				{endif}
				(L.L.door_4) (L.L.doorSpeed_4) (L.S.Timegap) * + (S.L.door_4)
			{else}
				(L.L.doorSpeed_4) abs 0.05 > (L.L.door_4) 1 < || (L.L.doorTarget_45) &&
				{if}
					l0 (L.L.doorMaxSpeed_4) <
					{if}
						(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * + (S.L.doorSpeed_4) 
					{else}
						(L.L.doorSpeed_4) (L.L.doorAcc_4) (L.S.Timegap) * - (S.L.doorSpeed_4) 
					{endif}
					(L.L.door_4) (L.L.doorSpeed_4) (L.S.Timegap) * + (S.L.door_4)
				{else}
					0 (S.L.doorSpeed_4)
				{endif}
			{endif}
		{endif}
	{endif}
	
	(L.L.door_4) (F.L.door_inc_dblAftD) (S.L.door_1_inc_dblAft_scd)

	(L.L.door_4) 1 >
	{if}
		(T.L.ev_doorhitopen_4)
		1 (S.L.door_4)
		(L.L.doorSpeed_4) /-/ (L.L.doorRefl_4_opn) * (S.L.doorSpeed_4)
	{else}
		(L.L.door_4) 0 <
		{if}
			(T.L.ev_doorhitclose_4)
			0 (S.L.door_4)
			(L.L.doorSpeed_4) /-/ (L.L.doorRefl_4_cls) * (S.L.doorSpeed_4)
		{endif}
	{endif}

	(L.L.doorTarget_45) !
	(L.L.door4_pos_z) 0 > &&
	(L.L.door_4) 0.05 < &&
	{if}
	(L.L.door4_pos_z) (C.L.door4_pos_z_speed_up) 5 / (L.S.Timegap) * - 0 max (S.L.door4_pos_z)
	{endif}
{end}

{macro:Door5_Calc}
	(L.L.doorTarget_45) (L.L.door5_pos_z) 1 < &&
	{if}
		(L.L.door5_pos_z) (C.L.door5_pos_z_speed) 5 / (L.S.Timegap) * + 1 min (S.L.door5_pos_z)
	{else}
		(C.L.electric_doors)
		{if}

			(C.L.madoor_acc) (S.L.doorAcc_5)

			(L.L.doorTarget_45) ! (L.L.doorSpeed_5) s0 abs 0.05 > (L.L.door_5) 0 > || && 
			{if}
				l0 /-/ (L.L.doorMaxSpeed_5) <
				{if}
					(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * - (S.L.doorSpeed_5)
				{else}
					(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * + (S.L.doorSpeed_5)
				{endif}
				(L.L.door_5) (L.L.doorSpeed_5) (L.S.Timegap) * + (S.L.door_5)
			{else}
				(L.L.doorSpeed_5) abs 0.05 > (L.L.door_5) 1 < || (L.L.doorTarget_45) &&
				{if}
					l0 (L.L.doorMaxSpeed_5) <
					{if}
						(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * + (S.L.doorSpeed_5) 
					{else}
						(L.L.doorSpeed_5) (L.L.doorAcc_5) (L.S.Timegap) * - (S.L.doorSpeed_5) 
					{endif}
					(L.L.door_5) (L.L.doorSpeed_5) (L.S.Timegap) * + (S.L.door_5)
				{else}
					0 (S.L.doorSpeed_5)
				{endif}
			{endif}
		{endif}
	{endif}
	
	(L.L.door_5) (F.L.door_inc_dblAftG) (S.L.door_1_inc_dblAft_scd)

	(L.L.door_5) 1 >
	{if}
		(T.L.ev_doorhitopen_5)
		1 (S.L.door_5)
		(L.L.doorSpeed_5) /-/ (L.L.doorRefl_5_opn) * (S.L.doorSpeed_5)
	{else}
		(L.L.door_5) 0 <
		{if}
			(T.L.ev_doorhitclose_5)
			0 (S.L.door_5)
			(L.L.doorSpeed_5) /-/ (L.L.doorRefl_5_cls) * (S.L.doorSpeed_5)
		{endif}
	{endif}

	(L.L.doorTarget_45) !
	(L.L.door5_pos_z) 0 > &&
	(L.L.door_5) 0.05 < &&
	{if}
	(L.L.door5_pos_z) (C.L.door5_pos_z_speed_up) 5 / (L.S.Timegap) * - 0 max (S.L.door5_pos_z)
	{endif}
{end}

'###############################################################################################

{macro:trg_bus_doorfront0}

  (L.L.doorfront_emergency) !
  {if}
    (L.L.doorTarget_0) ! (S.L.doorTarget_0)
    {if}
      (T.L.ev_doortriggeropen_0)
    {else}
      (T.L.ev_doortriggerclose_0)
    {endif}
    (C.L.door_druckluft)
    {if}
      (L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
    {endif}
  {endif}

{end}

{macro:trg_bus_doorfront1}

  (L.L.doorfront_emergency) !
  {if}
    (L.L.doorTarget_1) ! (S.L.doorTarget_1) (L.L.door_0) 0.1 > &&
    {if}
      (T.L.ev_doortriggeropen_1)
    {else}
      (T.L.ev_doortriggerclose_1)
    {endif}
    (C.L.door_druckluft)
    {if}
      (L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
    {endif}
  {endif}

{end}

{macro:trg_bus_dooraft23}

  (L.L.doorback23_emergency) !
  {if}
    (L.L.doorTarget_23) ! (S.L.doorTarget_23)
    {if}
      (T.L.ev_doortriggeropen_2)
    {else}
      (T.L.ev_doortriggerclose_2)
    {endif}

    (C.L.door_druckluft)
    {if}
      (L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
    {endif}
  {endif}

{end}

{macro:trg_bus_dooraft45}

  (L.L.doorback45_emergency) !
  {if}
    (L.L.doorTarget_45) ! (S.L.doorTarget_45)
    {if}
      (T.L.ev_doortriggeropen_3)
    {else}
      (T.L.ev_doortriggerclose_3)
    {endif}

    (C.L.door_druckluft)
    {if}
      (L.L.bremse_p_Tank04) 100000 - 0.96 * 100000 + (S.L.bremse_p_Tank04)
    {endif}
  {endif}

{end}

{macro:trg_bus_dooraft}
  (L.L.bremse_halte_sw) ! (S.L.bremse_halte_sw)
  {if}
    (T.L.ev_haltebremse_sw_an)
  {else}
    (T.L.ev_haltebremse_sw_aus)
  {endif}
{end}

{macro:DoorLockAtDeparture_Calc}
  (L.L.Velocity) 3 >
  {if}
    (L.L.door_opening_locked) 0 =
    {if}
      (T.L.ev_door_lock)
      1 (S.L.door_opening_locked)
    {endif}
  {endif}


  (L.L.Velocity) 3 <
  {if}
    (L.L.door_opening_locked) 1 =
    {if}
      (T.L.ev_door_unlock)
      0 (S.L.door_opening_locked)
    {endif}
  {endif}
{end}

{macro:traegheit}

'Simuliert träges Verhalten (exponentiell)

'Ladekonventionen:
' Sollwert    l0
' Istwert     l1
' Konstante Anlauf  l2 (Einheiten/s)
' Konstante Ablauf  l3 (Einheiten/s)

'Anlauf oder Auslauf?
  l0 l1 >
  {if}
    l2 (L.S.Timegap) * 1 min -1 max s4
  {else}
    l3 (L.S.Timegap) * 1 min -1 max s4
  {endif}


'Sollwert:
  l0
'Istwert:
  l1
'Beschleunigung:
  - l4 *
'Addition zum Istwert:
  l1 + s1
{end}