SCL aus parametrisierten Templates: Golden-Files, Render-Kontext, Pilot 1Sep1Swi
Schritte 1-3 aus doc/SCL_Templates.md (neu: Konzept, Wertklassen je Zeile, Namensregeln, Tests, Migrationsplan, Vertrag fuer den CSV->SCL-Workflow). - Golden-Files (tests/test_scl_skeleton_golden.py, tests/fixtures/scl/): komplette FB_Main-Ausgabe von mubea und HundM05 byte-genau festgeschrieben, Zeitstempel maskiert; gewollte Aenderung per SKEL_UPDATE_GOLDEN=1 - lib/scl_context.py (neu): alles, was scl_skeleton aus der TRO-JSON ableitet (Reihenfolge, Separator-/Weichen-/Scanner-Bloecke, Staubereiche, Ziellisten, Namen) als pydantic-Kontext SclFile/SclTro; Namen als SclName (Wert + todo-Merker) als Andockstelle fuer die Namensregeln (Schritt 4). scl_skeleton schreibt nur noch Text; Ausgabe byte-identisch (Golden-Files, zusaetzlich dematic/showroom mit und ohne --start alt/neu verglichen) - lib/scl_templates/ (neu, Jinja2): _macros.scl.j2 + Pilot FB_ILS_MTRO_1Sep1Swi.scl.j2 nach der realen Aufrufstelle TRO107 (PriorityManagerDir2, stInSenJam<n>, xInCarouselRun1, xInRelease TRUE, Separatorzeiten 100/50 ms). Ortsgebundene Zeilen als Vorschlag umgesetzt, jede offene Stelle mit TODO(E-Planung) - Bestaetigung durch SPS steht aus - scl_skeleton: --templates [DIR] (opt-in, ohne Schalter Ausgabe unveraendert), --strict (Exit 1 ohne SCL, wenn ein FB-Typ kein Template hat); Kopf und Zusammenfassung nennen Template-/generische Typen; Templatefehler (StrictUndefined) -> Exit 1 ohne SCL - tests/test_scl_templates.py: Rundlauf Template mit Referenzwerten == Referenz-REGION (normalisiert); jede Platzhalterzeile traegt den TODO-Marker - requirements.txt: jinja2 >= 3.1 (bestehende .venv: pip install -r requirements.txt) - Doku: SCL_Templates.md, Python_Scripts.md §5b, Commandlines.md §2.5, CLAUDE.md Befunde: xInCarouselRun1 laesst sich nicht aus der TRO-JSON ableiten (Kanten- art "umlauf" kommt praktisch nicht vor) -> immer als TODO; nTo1Destinations ist in der Referenz 3 bei 2 Abgaengen (zaehlt evtl. Ziele) -> "pruefen". Mit --templates nur die 1Sep1Swi-REGIONs (+ Kopf) anders als generisch; 32 Tests gruen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
97a0db6707
commit
4895ebf5ed
@@ -0,0 +1,64 @@
|
||||
{#-
|
||||
FB_ILS_MTRO_1Sep1Swi - Aufrufstelle in FB_Main
|
||||
|
||||
Referenz: doc/TRO_Katalog/scl_templates/FB_ILS_MTRO_1Sep1Swi.scl
|
||||
(TRO 107, =A01+UH01-KF00 FB_Main). Zeilen und Reihenfolge folgen
|
||||
dieser Aufrufstelle; geprueft per tests/test_scl_templates.py.
|
||||
|
||||
Entscheidungen zu den ortsgebundenen Zeilen (doc/SCL_Templates.md §6):
|
||||
stInSenJam<n> je Ausgang einer, Sensor offen
|
||||
stInSettings.xPrioDir2 TRUE wie Referenz, aber offen (Planungsentscheidung)
|
||||
PriorityManagerDir2 immer, UDT-Name offen
|
||||
xInCarouselRun1 immer, offen - ob der TRO am Kreisel liegt, steht
|
||||
nicht in der TRO-JSON; sonst Zeile loeschen
|
||||
xInRelease TRUE wie Referenz (generisch: "DB_TRO_TEST")
|
||||
Separatorzeiten 100/50 ms wie Referenz, "pruefen"
|
||||
stInOutMachineState Schaltschrank offen (anlagenspezifisch)
|
||||
Alle noch mit den SPS-Kollegen zu bestaetigen.
|
||||
-#}
|
||||
{% import "_macros.scl.j2" as m %}
|
||||
REGION {{ t.region_title }}
|
||||
{{ m.kopf(t) }}
|
||||
|
||||
{% for s in t.separators %}
|
||||
{{ m.separator(t, s) }}
|
||||
{% endfor %}
|
||||
{{ m.jam_sensors(t) }}
|
||||
|
||||
{% for w in t.switches %}
|
||||
{{ m.switch(t, w) }}
|
||||
{% endfor %}
|
||||
|
||||
{{ m.ziele(t) }}
|
||||
|
||||
{% set z = [] %}
|
||||
{% set _ = z.append(('stInPriorityManagerDir2 := "DB_Prozessdaten".stPriorityManager.' ~ t.priority_udt.value ~ '.TroIn', m.note(t.priority_udt))) %}
|
||||
{% set _ = z.append(('stOutPriorityManagerDir2 => "DB_Prozessdaten".stPriorityManager.' ~ t.priority_udt.value ~ '.TroOut', m.note(t.priority_udt))) %}
|
||||
{% set _ = z.append(('nInMainTroNo := "' ~ t.main_tro.value ~ '"', m.note(t.main_tro))) %}
|
||||
{% set _ = z.append(("xInSftyOk := " ~ t.safety.value, m.note(t.safety))) %}
|
||||
{% set _ = z.append(("xInAllRdyToStart := TRUE", "")) %}
|
||||
{% set _ = z.append(("xInCarouselRun1 := " ~ t.carousel_run.value, m.note(t.carousel_run, "nur am Kreisel, sonst Zeile loeschen"))) %}
|
||||
{% set _ = z.append(("xInRelease := TRUE", "")) %}
|
||||
{% set _ = z.append(("stInOutMachineState := " ~ t.machine_state.value, m.note(t.machine_state, "Schaltschrank"))) %}
|
||||
{% set _ = z.append(("stInOutCognexInterface := #stCognexInterfaceDummy", "")) %}
|
||||
{% for j in t.jam_entries %}
|
||||
{% set _ = z.append(("arInOutJamEntr" ~ j.n ~ " := " ~ j.db.value ~ ".arCarrier", m.note(j.db, "Staubereich von " ~ j.neighbour))) %}
|
||||
{% set _ = z.append(("stInOutJamEntr" ~ j.n ~ " := " ~ j.db.value ~ ".stData", m.note(j.db))) %}
|
||||
{% endfor %}
|
||||
{% for j in t.jam_exits %}
|
||||
{% set _ = z.append(("arInOutJamExit" ~ j.n ~ " := " ~ j.db.value ~ ".arCarrier", m.note(j.db, "Staubereich nach " ~ j.neighbour))) %}
|
||||
{% set _ = z.append(("stInOutJamExit" ~ j.n ~ " := " ~ j.db.value ~ ".stData", m.note(j.db))) %}
|
||||
{% endfor %}
|
||||
{% set _ = z.append(('stInOutHMI := "DB_Interface_HMI".stTRO.' ~ t.id, "")) %}
|
||||
{% set _ = z.append(('nOutStateLast => "DB_GLOB_TroState".arTroState["' ~ t.main_tro.value ~ '"]', m.note(t.main_tro))) %}
|
||||
{% for s in t.separators %}
|
||||
{% set _ = z.append(("xOutStopper" ~ s.n ~ ' => "' ~ s.stopper.value ~ '"', m.note(s.stopper))) %}
|
||||
{% endfor %}
|
||||
{% for w in t.switches %}
|
||||
{% set _ = z.append(("xOutSw" ~ w.n ~ 'ExTo3 => "' ~ w.valve.value ~ '"', m.note(w.valve))) %}
|
||||
{% endfor %}
|
||||
#{{ t.id }}.stInSettings.xPrioDir2 := {{ t.prio_dir2.value }};{{ m.todo(t.prio_dir2) }}
|
||||
{{ m.call(t, z) }}
|
||||
|
||||
{{ m.direction(t) }}
|
||||
END_REGION
|
||||
@@ -0,0 +1,103 @@
|
||||
{#-
|
||||
_macros.scl.j2 - gemeinsame Bausteine der FB-Templates (doc/SCL_Templates.md §5.2)
|
||||
|
||||
Jede Zeile ist eine der Klassen aus §6: L (Layout, aus dem Kontext),
|
||||
N (Name, heute Platzhalter + TODO), R (Referenzwert aus der realen Aufrufstelle),
|
||||
E (E-Planung, Platzhalter + TODO), C (Bedingung).
|
||||
|
||||
Makros liefern ihre Zeilen OHNE abschliessenden Zeilenumbruch; der Aufrufer
|
||||
setzt ihn. Globale Variable: TODO (Marker "TODO(E-Planung)").
|
||||
-#}
|
||||
|
||||
{#- TODO-Kommentar hinter einer Zeile, wenn der Name noch offen ist -#}
|
||||
{% macro todo(name, abstand=" ") -%}
|
||||
{% if name.todo %}{{ abstand }}// {{ TODO }}{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
{#- Kommentartext fuer eine Parameterzeile des Aufrufs -#}
|
||||
{% macro note(name, text="") -%}
|
||||
{% if name.todo %}{{ TODO }}{% if text %} - {{ text }}{% endif %}{% else %}{{ text }}{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
{#- Kommentarkopf der REGION: Lage und Nachbarn im Layout (L) -#}
|
||||
{% macro kopf(t) %}
|
||||
{% if t.position %}
|
||||
// Anlagenkoordinate x/y: {{ "%.0f"|format(t.position[0]) }} / {{ "%.0f"|format(t.position[1]) }} mm
|
||||
{% endif %}
|
||||
// Vorgaenger: {{ t.predecessors|join(", ") or "-" }}
|
||||
// Nachfolger: {{ t.successors|join(", ") or "-" }}
|
||||
{% if t.confidence %}
|
||||
// Einstufung: {{ t.confidence }}
|
||||
{% endif %}
|
||||
// Aufbau nach Template {{ t.fb }}.scl.j2 (Referenz: doc/TRO_Katalog/scl_templates)
|
||||
{%- endmacro %}
|
||||
|
||||
{#- stInSeparator<n>: Zeiten R aus der Referenz (TRO107), Nummer N, Sensor E -#}
|
||||
{% macro separator(t, s) %}
|
||||
// Separator {{ s.n }} = Bauteil {{ s.layout }} aus dem Layout
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.nSeparatorNo := "{{ s.no.value }}";{{ todo(s.no) }}
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.tTrailingTime := t#100ms; // {{ TODO }}: pruefen
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.tHandlingTime := t#50ms; // {{ TODO }}: pruefen
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.tJam := "TimeForSepJam";
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.xPluggedJam := TRUE;
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.xPluggedPart := FALSE;
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.Settings.xPluggedScanner := {{ "TRUE" if t.has_scanner else "FALSE" }};
|
||||
#{{ t.id }}.stInSeparator{{ s.n }}.stSenInSep := "DB_Inputs".Sensors["{{ s.sensor.value }}"];{{ todo(s.sensor) }}
|
||||
{%- endmacro %}
|
||||
|
||||
{#- stInSenJam<n>: ein Stausensor je Ausgang (E) -#}
|
||||
{% macro jam_sensors(t) %}
|
||||
{% for j in t.jam_exits %}
|
||||
#{{ t.id }}.stInSenJam{{ j.n }} := "DB_Inputs".Sensors["{{ j.sensor.value }}"];{{ todo(j.sensor) }}
|
||||
{% endfor %}
|
||||
{%- endmacro %}
|
||||
|
||||
{#- stInSwitch<n>: Nummer N; nTo1Destinations L, aber Bedeutung noch zu klaeren -#}
|
||||
{% macro switch(t, w) %}
|
||||
#{{ t.id }}.stInSwitch{{ w.n }}.Settings.nSwitchNo := "{{ w.no.value }}";{{ todo(w.no) }}
|
||||
#{{ t.id }}.stInSwitch{{ w.n }}.Settings.xPluggedExSen3 := FALSE;
|
||||
#{{ t.id }}.stInSwitch{{ w.n }}.Settings.xPluggedExSen4 := FALSE;
|
||||
{% if w.to1_destinations is not none %}
|
||||
#{{ t.id }}.stInSwitch{{ w.n }}.Settings.nTo1Destinations := {{ w.to1_destinations }}; // Abgaenge laut Topologie - {{ TODO }}: pruefen (Info fuer HMI; Referenz TRO107 hat 3 bei 2 Abgaengen)
|
||||
{% else %}
|
||||
#{{ t.id }}.stInSwitch{{ w.n }}.Settings.nTo1Destinations := _; // {{ TODO }}: {{ t.successors|length }} Abgaenge auf {{ t.switches|length }} Weichen - Aufteilung festlegen
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
{#- Zielliste je Weichenabgang (L, nur Kommentar) -#}
|
||||
{% macro ziele(t) %}
|
||||
// Zielliste je Abgang (aus dem TRO-Graphen berechnet) -
|
||||
// Grundlage fuer die Zuordnung Ziel -> Richtung in FC_Direction:
|
||||
{% for e in t.switch_exits %}
|
||||
// ueber {{ e.via }}: {{ e.targets|join(", ") or "-" }}
|
||||
{% endfor %}
|
||||
{%- endmacro %}
|
||||
|
||||
{#-
|
||||
Instanzaufruf aus einer Liste von (Code, Kommentar). Das Komma wird hier
|
||||
gesetzt und steht damit VOR dem Kommentar - sonst waere es Teil des
|
||||
Kommentars und die Parameterliste uebersetzt nicht.
|
||||
-#}
|
||||
{% macro call(t, zeilen) %}
|
||||
{% set einzug = " " * (6 + t.id|length) %}
|
||||
{% for code, kommentar in zeilen %}
|
||||
{{ (" #" ~ t.id ~ "(") if loop.first else einzug }}{{ code }}{{ ");" if loop.last else "," }}{% if kommentar %} // {{ kommentar }}{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{%- endmacro %}
|
||||
|
||||
{#- REGION Direction: je Weiche ein FC_Direction-Aufruf -#}
|
||||
{% macro direction(t) %}
|
||||
REGION Direction
|
||||
{% for w in t.switches %}
|
||||
"FC_Direction"(nInSwitchNo := "{{ w.no.value }}",{{ todo(w.no) }}
|
||||
nOutDirection => {{ w.direction_target }},
|
||||
InOutCarrier := {{ w.jam_db.value }}.arCarrier[1]);{{ todo(w.jam_db) }}
|
||||
{% if not loop.last %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
END_REGION
|
||||
{%- endmacro %}
|
||||
Reference in New Issue
Block a user