Procedury ATC: katalog procedures/ + dynamiczne wczytywanie (globalne + per-lotnisko) + przykładowa EPWA
This commit is contained in:
1 parent
ed073df1bc
commit
735e3335ff
3 files changed
+130
-5
No files matched your search
@@ -75,6 +75,11 @@ DEFAULT_CONFIG = {
|
|||||||
# planu do natywnego FMS X-Plane. Wskaz plik tekstowy; kazda linia to jeden
|
# planu do natywnego FMS X-Plane. Wskaz plik tekstowy; kazda linia to jeden
|
||||||
# punkt: "NAZWA [WYSOKOSC_stop]" (wysokosc opcjonalna), '#' = komentarz.
|
# punkt: "NAZWA [WYSOKOSC_stop]" (wysokosc opcjonalna), '#' = komentarz.
|
||||||
"flightplan_file": "",
|
"flightplan_file": "",
|
||||||
|
# --- Procedury ATC ---
|
||||||
|
# Katalog z plikami procedur. Puste = <katalog_wtyczki>/procedures.
|
||||||
|
# _global.txt = zawsze dolaczane; <ICAO>.txt = per-lotnisko.
|
||||||
|
"procedures_dir": "",
|
||||||
|
"use_procedures": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dataref -> (nazwa kontekstu, mnoznik, jednostka)
|
# Dataref -> (nazwa kontekstu, mnoznik, jednostka)
|
||||||
@@ -287,6 +292,69 @@ class XSayATC:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _procedures_dir(self):
|
||||||
|
"""Zwraca sciezke katalogu procedur."""
|
||||||
|
if self.config.get("procedures_dir"):
|
||||||
|
return self.config["procedures_dir"]
|
||||||
|
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "procedures")
|
||||||
|
|
||||||
|
def _nearest_airport_icao(self):
|
||||||
|
"""Zwraca ICAO najblizszego lotniska (z natywnej bazy navaidow)."""
|
||||||
|
lat = self._get_dataref("sim/flightmodel/position/latitude", is_float=True)
|
||||||
|
lon = self._get_dataref("sim/flightmodel/position/longitude", is_float=True)
|
||||||
|
if lat is None or lon is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
import math
|
||||||
|
best_id = None
|
||||||
|
best_dist = None
|
||||||
|
nav = xp.getFirstNavAid()
|
||||||
|
while nav is not None and nav != xp.NAV_NOT_FOUND:
|
||||||
|
info = xp.getNavAidInfo(nav)
|
||||||
|
if info is not None and getattr(info, "type", None) == xp.Nav_Airport:
|
||||||
|
dlat = info.latitude - lat
|
||||||
|
dlon = info.longitude - lon
|
||||||
|
dist = dlat * dlat + dlon * dlon
|
||||||
|
if best_dist is None or dist < best_dist:
|
||||||
|
best_dist = dist
|
||||||
|
best_id = getattr(info, "navAidID", None)
|
||||||
|
nav = xp.getNextNavAid(nav)
|
||||||
|
return best_id
|
||||||
|
except Exception as e:
|
||||||
|
xp.log(f"[XSayATC] Blad szukania lotniska: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _read_procedure_file(self, path):
|
||||||
|
"""Czyta plik procedury, zwraca tekst (bez linii komentarza '#')."""
|
||||||
|
try:
|
||||||
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
|
lines = [ln.rstrip() for ln in f if ln.strip() and not ln.lstrip().startswith("#")]
|
||||||
|
return "\n".join(lines)
|
||||||
|
except Exception:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def _collect_procedures(self):
|
||||||
|
"""Zbiera tekst procedur: _global.txt + <ICAO>.txt najblizszego lotniska."""
|
||||||
|
if not self.config.get("use_procedures", True):
|
||||||
|
return ""
|
||||||
|
d = self._procedures_dir()
|
||||||
|
if not os.path.isdir(d):
|
||||||
|
return ""
|
||||||
|
parts = []
|
||||||
|
g = os.path.join(d, "_global.txt")
|
||||||
|
if os.path.exists(g):
|
||||||
|
t = self._read_procedure_file(g)
|
||||||
|
if t:
|
||||||
|
parts.append(t)
|
||||||
|
icao = self._nearest_airport_icao()
|
||||||
|
if icao:
|
||||||
|
p = os.path.join(d, icao.upper() + ".txt")
|
||||||
|
if os.path.exists(p):
|
||||||
|
t = self._read_procedure_file(p)
|
||||||
|
if t:
|
||||||
|
parts.append(f"[Procedures for {icao.upper()}]\n" + t)
|
||||||
|
return "\n\n".join(parts)
|
||||||
|
|
||||||
def _read_float_array(self, ref, count):
|
def _read_float_array(self, ref, count):
|
||||||
"""Czyta tablice float z datarefu. Zwraca liste lub []."""
|
"""Czyta tablice float z datarefu. Zwraca liste lub []."""
|
||||||
if ref is None:
|
if ref is None:
|
||||||
@@ -443,8 +511,9 @@ class XSayATC:
|
|||||||
xp.log(f"[XSayATC] Nie mozna pobrac modelu: {e}")
|
xp.log(f"[XSayATC] Nie mozna pobrac modelu: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _build_messages(self, user_text, flight_ctx_text):
|
def _build_messages(self, user_text, flight_ctx_text, procedures_text):
|
||||||
"""Buduje liste messages. flight_ctx_text musi byc przekazany (bez odczytu datarefow)."""
|
"""Buduje liste messages. flight_ctx_text i procedures_text musza byc
|
||||||
|
przekazane (bez odczytu datarefow / plikow na watku roboczym)."""
|
||||||
msgs = []
|
msgs = []
|
||||||
sp = self.config.get("system_prompt", "")
|
sp = self.config.get("system_prompt", "")
|
||||||
if self.config.get("no_think", True) and sp and "/no_think" not in sp:
|
if self.config.get("no_think", True) and sp and "/no_think" not in sp:
|
||||||
@@ -454,6 +523,9 @@ class XSayATC:
|
|||||||
if self.config.get("include_flight_context", True) and flight_ctx_text:
|
if self.config.get("include_flight_context", True) and flight_ctx_text:
|
||||||
msgs.append({"role": "system", "content": "Pilot's current flight context:\n" + flight_ctx_text})
|
msgs.append({"role": "system", "content": "Pilot's current flight context:\n" + flight_ctx_text})
|
||||||
|
|
||||||
|
if procedures_text:
|
||||||
|
msgs.append({"role": "system", "content": "Local ATC procedures:\n" + procedures_text})
|
||||||
|
|
||||||
for m in self.messages[-12:]:
|
for m in self.messages[-12:]:
|
||||||
msgs.append({"role": m["role"], "content": m["text"]})
|
msgs.append({"role": m["role"], "content": m["text"]})
|
||||||
|
|
||||||
@@ -472,7 +544,7 @@ class XSayATC:
|
|||||||
}
|
}
|
||||||
return requests.post(url, json=payload, stream=True, timeout=(10, 120))
|
return requests.post(url, json=payload, stream=True, timeout=(10, 120))
|
||||||
|
|
||||||
def _run_stream(self, user_text, flight_ctx_text):
|
def _run_stream(self, user_text, flight_ctx_text, procedures_text):
|
||||||
"""Watek roboczy: TYLKO siec i aktualizacja self.messages. Bez xp.getData*."""
|
"""Watek roboczy: TYLKO siec i aktualizacja self.messages. Bez xp.getData*."""
|
||||||
self.streaming = True
|
self.streaming = True
|
||||||
self.status = "ATC mysli..."
|
self.status = "ATC mysli..."
|
||||||
@@ -482,7 +554,7 @@ class XSayATC:
|
|||||||
self.messages.append({"role": "assistant", "text": ""})
|
self.messages.append({"role": "assistant", "text": ""})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
messages = self._build_messages(user_text, flight_ctx_text)
|
messages = self._build_messages(user_text, flight_ctx_text, procedures_text)
|
||||||
resp = self._request(messages)
|
resp = self._request(messages)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
@@ -540,9 +612,17 @@ class XSayATC:
|
|||||||
xp.log(f"[XSayATC] Blad zbierania kontekstu: {e}")
|
xp.log(f"[XSayATC] Blad zbierania kontekstu: {e}")
|
||||||
flight_ctx_text = None
|
flight_ctx_text = None
|
||||||
|
|
||||||
|
# Zbierz procedury ATC NA GLOWNYM WATKU (czytanie plikow/navaidow)
|
||||||
|
procedures_text = ""
|
||||||
|
try:
|
||||||
|
procedures_text = self._collect_procedures()
|
||||||
|
except Exception as e:
|
||||||
|
xp.log(f"[XSayATC] Blad zbierania procedur: {e}")
|
||||||
|
procedures_text = ""
|
||||||
|
|
||||||
self._stop_event.clear()
|
self._stop_event.clear()
|
||||||
self._worker = threading.Thread(
|
self._worker = threading.Thread(
|
||||||
target=self._run_stream, args=(text, flight_ctx_text), daemon=True)
|
target=self._run_stream, args=(text, flight_ctx_text, procedures_text), daemon=True)
|
||||||
self._worker.start()
|
self._worker.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@@ -779,6 +859,13 @@ class XSayATC:
|
|||||||
_, self.config["flightplan_file"] = imgui.input_text(
|
_, self.config["flightplan_file"] = imgui.input_text(
|
||||||
"Plik planu lotu", self.config["flightplan_file"], 512)
|
"Plik planu lotu", self.config["flightplan_file"], 512)
|
||||||
|
|
||||||
|
imgui.separator()
|
||||||
|
imgui.text("Procedury ATC:")
|
||||||
|
_, self.config["use_procedures"] = imgui.checkbox(
|
||||||
|
"Wlacz procedury", self.config["use_procedures"])
|
||||||
|
_, self.config["procedures_dir"] = imgui.input_text(
|
||||||
|
"Katalog procedur", self.config["procedures_dir"], 512)
|
||||||
|
|
||||||
imgui.separator()
|
imgui.separator()
|
||||||
imgui.text("System prompt (instrukcje ATC):")
|
imgui.text("System prompt (instrukcje ATC):")
|
||||||
_, self.config["system_prompt"] = imgui.input_text_multiline(
|
_, self.config["system_prompt"] = imgui.input_text_multiline(
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Procedury ATC dla Lotniska Chopina w Warszawie (EPWA)
|
||||||
|
# ICAO: EPWA — Warsaw Chopin Airport
|
||||||
|
# Pas startowy główny: 11/29 (oraz 15/33)
|
||||||
|
|
||||||
|
## Informacje ogolne
|
||||||
|
- Lotnisko: Warsaw Chopin (EPWA), elevacja 362 ft AMSL.
|
||||||
|
- Pasy: 11/29 (2800 m) i 15/33 (3690 m). Dominujacy pas: 33 do ladowania, 11 do startow przy wietrze wschodnim.
|
||||||
|
- Ruch mieszany: pasazerski, cargo i general aviation.
|
||||||
|
|
||||||
|
## Ground (121.900 MHz)
|
||||||
|
- Kołowanie na pas 11 przez TWY A, B i C.
|
||||||
|
- Punkt oczekiwania przed pasem 33: holding point przy TWY D.
|
||||||
|
- Standardowe trasy kołowania podawaj wedlug najkrotszej bezpiecznej drogi.
|
||||||
|
- Przypominaj o wstrzymaniu na punktach hold short przed aktywnym pasem.
|
||||||
|
|
||||||
|
## Tower (118.300 MHz)
|
||||||
|
- Aktywny pas startow/ladowan zwykle 11 lub 33, zaleznie od wiatru.
|
||||||
|
- Zezwalaj na start dopiero po "cleared for takeoff runway 11".
|
||||||
|
- Ladowanie: "cleared to land runway 33, wind ...".
|
||||||
|
- Go-arounds kieruj na wznoszenie w osi pasa i standardowa procedure.
|
||||||
|
|
||||||
|
## Approach / Departure (128.800 MHz)
|
||||||
|
- Departures: po starcie wznoszenie wstepne do 3000 ft, nastepnie wektorowanie wg SID.
|
||||||
|
- Arrivals: schodzenie wg STAR, przeniesienie na ILS dla pasa 33 lub 11.
|
||||||
|
- Rozdzielanie ruchu przy pomocy wektorow i wysokosci.
|
||||||
|
|
||||||
|
## Uwagi
|
||||||
|
- Jezeli pilot nie zna aktywnego pasa, podaj go w pierwszej odpowiedzi.
|
||||||
|
- W warunkach nocnych przypominaj o swiatlach.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Globalne zasady ATC (stosowane zawsze, niezależnie od lotniska)
|
||||||
|
# Komentarze zaczynaja sie od '#' i nie sa wysylane do modelu.
|
||||||
|
|
||||||
|
- Uzywaj standardowej frazeologii lotniczej w jezyku angielskim.
|
||||||
|
- Odpowiadaj krotko i konkretnie, jednym poleceniem na raz.
|
||||||
|
- Wysokosci podawaj w stopach, predkosc w wezlach, dystans w milach morskich.
|
||||||
|
- Przy wydawaniu zezwolen na start i ladowanie uzywaj pelnych znakow wywolawczych.
|
||||||
|
- Nie wymyslaj czestotliwosci ani tras, ktorych nie ma w kontekscie lotu.
|
||||||
|
- Gdy pilot zgłasza awarie lub sytuacje awaryjna, nadaj priorytet i pomoz.
|
||||||
Reference in new issue
Block a user