:py:mod:`pycasx.acas.acasx` =========================== .. py:module:: pycasx.acas.acasx .. autoapi-nested-parse:: ACAS X implementation for pyCASX. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pycasx.acas.acasx.ACASX Attributes ~~~~~~~~~~ .. autoapisummary:: pycasx.acas.acasx.RHO_INA .. py:data:: RHO_INA .. py:class:: ACASX(model_path = None, backend = 'nnet') Bases: :py:obj:`pycasx.acas.hcas.HCASMixin`, :py:obj:`pycasx.acas.vcas.VCASMixin` The brain behind pyCASX. This class contains all the logic for the ACAS X implementation. Well, almost, some logic is provided by the mixin classes :param model_path: Path to the ACAS model folder. :type model_path: Path | str | None :param backend: The runtime backend to use. Defaults to "nnet". :type backend: Literal["nnet", "onnx", "torch"], optional .. py:method:: advise() Advise the pilot on the current situation. :returns: The HCAS and VCAS advisories. :rtype: tuple[HCASAdvisories, VCASAdvisories] .. py:method:: fetch_data() Fetch the required data from FlightGear. Fetches data of ownship and all intruders from FlightGear and post-processes the data to the required format for the ACAS X. Note: a single get_prop or list_props (without recursion) call via the HTTP API takes roughly 20 ms. Therefore, accessing the properties of a single aircraft in our current setup takes roughly 100 ms. This is a lot of time, especially when we have a lot of intruders. Therefore, not only should we try to eliminate unnecessary calls to intruders far away from the ownship, but we should also try to refactor this function to use concurrency. :raises RuntimeError: If no connection is registered. .. py:method:: evaluate(model_name, inputs) Evaluate a CAS model. :param model_name: Name of the model to evaluate from the model dictionary. :type model_name: str :param inputs: The inputs to the model. :type inputs: npt.NDArray[np.float32] :returns: The outputs of the model. :rtype: npt.NDArray[np.float32] :raises NotImplementedError: Raised if the requested backend is not implemented. .. py:method:: _evaluate_nnet(model_name, inputs) Evaluate a CAS model with the NNet runtime. :param model_name: Name of the model to evaluate from the model dictionary. :type model_name: str :param inputs: The inputs to the model. :type inputs: npt.NDArray[np.float32] :returns: The outputs of the model. :rtype: npt.NDArray[np.float32] .. py:method:: _evaluate_onnx(model_name, inputs) Evaluate a CAS model with the onnx runtime. :param model_name: Name of the model to evaluate from the model dictionary. :type model_name: str :param inputs: The inputs to the model. :type inputs: npt.NDArray[np.float32] :returns: The outputs of the model. :rtype: npt.NDArray[np.float32] :raises KeyError: Raised if the requested model is not found. .. py:method:: _evaluate_torch(model_name, inputs) Evaluate a CAS model with the PyTorch runtime. :param model_name: Name of the model to evaluate from the model dictionary. :type model_name: str :param inputs: The inputs to the model. :type inputs: npt.NDArray[np.float32] :returns: The outputs of the model. :rtype: npt.NDArray[np.float32] :raises KeyError: Raised if the requested model is not found. .. py:method:: register_connection(connection) Register a new connection to a connection provider. The newly registered connection will be used to fetch data for the ACAS X model. If a connection is already registered, it will be overwritten. :param connection: The connection provider. :type connection: PropsConnection .. py:method:: load_models(model_path) Load the CAS models from the provided path. :param model_path: Path to the CAS models. :type model_path: Path | str :returns: The loaded CAS models. :rtype: ModelDict :raises NotImplementedError: Raised if the requested backend is not implemented. :raises FileNotFoundError: Raised if no models are found at the provided path. .. py:method:: fetch_ownship_data() Fetches the data of the ownship. The ownship uses the following properties: - /sim/multiplay/callsign - /position/altitude-ft - /velocities/vertical-speed-fps - /velocities/equivalent-kt - /environment/density-slugft3 - /orientation/true-heading-deg - /position/latitude-deg - /position/longitude-deg :returns: The ownship with the data fetched from FlightGear. :rtype: Aircraft .. py:method:: fetch_intruder_data(intruder) Fetches the data of a single intruder. :param intruder: The intruder to fetch the data for. This refers to the full path of the intruder in the property tree until the aircraft directory. E.g. ``/ai/models/aircraft`` for the zeroth intruder and ``/ai/models/aircraft[1]`` for the first intruder. :type intruder: str :returns: The intruder with the data fetched from FlightGear. :rtype: Aircraft .. py:method:: fetch_aircraft_data(call_sign, altitude_ft, vertical_speed_fps, heading_deg, latitude_deg, longitude_deg, true_airspeed_kt = None, equivalent_airspeed_kt = None, density_slugft3 = None) Fetches the data of a single aircraft. Fetch the required data to fully describe an aircraft from FlightGear. Some properties are optional, depending on the model used. For example, for AI aircraft, FlightGear directly provides the true airspeed, but for the ownship, we have to calculate it ourselves. Thus, one either has to provide the true airspeed or the equivalent airspeed and the density. This method uses threading to improve performance. :param call_sign: The property string of the call sign. :type call_sign: str :param altitude_ft: The property string of the altitude. :type altitude_ft: str :param vertical_speed_fps: The property string of the vertical speed. :type vertical_speed_fps: str :param heading_deg: The property string of the heading. :type heading_deg: str :param latitude_deg: The property string of the latitude. :type latitude_deg: str :param longitude_deg: The property string of the longitude. :type longitude_deg: str :param true_airspeed_kt: The property string of the true airspeed. :type true_airspeed_kt: str | None :param equivalent_airspeed_kt: The property string of the equivalent airspeed. :type equivalent_airspeed_kt: str | None :param density_slugft3: The property string of the density. :type density_slugft3: str | None :returns: The aircraft with the data fetched from FlightGear. :rtype: Aircraft :raises ValueError: Raised if neither the true airspeed nor the equivalent airspeed and density are provided. :raises RuntimeError: Raised if internal logic fails. Please report this as a bug.